From 441aa3044f43e5572f58c354f01e6bc070acd5c7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 10 Dec 2009 20:28:30 +0100 Subject: [PATCH] Use spaces for indentation, not tabs. --- ChangeLog | 11 + NEWS | 4 + README | 48 + build-aux/link-warning.h | 12 +- lib/accept4.c | 64 +- lib/acl_entries.c | 20 +- lib/acosl.c | 66 +- lib/alloca.c | 154 +- lib/arcfour.c | 6 +- lib/arcfour.h | 2 +- lib/arctwo.c | 100 +- lib/arctwo.h | 6 +- lib/areadlink-with-size.c | 40 +- lib/areadlink.c | 84 +- lib/argmatch.c | 82 +- lib/argmatch.h | 32 +- lib/argp-fmtstream.c | 438 +- lib/argp-fmtstream.h | 46 +- lib/argp-help.c | 1238 ++-- lib/argp-namefrob.h | 2 +- lib/argp-parse.c | 480 +- lib/argp-version-etc.c | 2 +- lib/argp-xinl.c | 2 +- lib/argp.h | 138 +- lib/argz.c | 210 +- lib/argz.in.h | 50 +- lib/arpa_inet.in.h | 4 +- lib/array-mergesort.h | 300 +- lib/asinl.c | 68 +- lib/at-func.c | 16 +- lib/atanl.c | 10 +- lib/backupfile.c | 72 +- lib/backupfile.h | 2 +- lib/base64.c | 336 +- lib/base64.h | 14 +- lib/btowc.c | 2 +- lib/byteswap.in.h | 22 +- lib/c-stack.c | 30 +- lib/c-strcasecmp.c | 2 +- lib/c-strcasestr.c | 18 +- lib/c-strncasecmp.c | 2 +- lib/c-strtod.c | 12 +- lib/calloc.c | 10 +- lib/canon-host.c | 6 +- lib/canonicalize-lgpl.c | 292 +- lib/canonicalize.c | 282 +- lib/ceil.c | 32 +- lib/chdir-long.c | 88 +- lib/chdir-long.h | 2 +- lib/chdir-safer.c | 20 +- lib/classpath.c | 6 +- lib/classpath.h | 8 +- lib/clean-temp.c | 208 +- lib/clean-temp.h | 16 +- lib/close-hook.c | 2 +- lib/close-stream.c | 2 +- lib/closein.c | 12 +- lib/closeout.c | 6 +- lib/concat-filename.c | 22 +- lib/concat-filename.h | 4 +- lib/connect.c | 4 +- lib/copy-acl.c | 320 +- lib/copy-file.c | 10 +- lib/cosl.c | 34 +- lib/csharpcomp.c | 536 +- lib/csharpcomp.h | 16 +- lib/csharpexec.c | 118 +- lib/csharpexec.h | 14 +- lib/cycle-check.c | 10 +- lib/cycle-check.h | 22 +- lib/des.c | 252 +- lib/des.h | 20 +- lib/diacrit.c | 6 +- lib/diffseq.h | 444 +- lib/dirchownmod.c | 118 +- lib/dirent.in.h | 4 +- lib/dirname.h | 6 +- lib/dprintf.c | 10 +- lib/dup3.c | 168 +- lib/duplocale.c | 68 +- lib/error.c | 118 +- lib/error.h | 6 +- lib/euidaccess.c | 32 +- lib/exclude.c | 212 +- lib/exclude.h | 2 +- lib/execute.c | 134 +- lib/execute.h | 10 +- lib/expl.c | 24 +- lib/fatal-signal.c | 48 +- lib/fdopendir.c | 22 +- lib/file-has-acl.c | 534 +- lib/file-set.c | 12 +- lib/file-set.h | 4 +- lib/fileblocks.c | 12 +- lib/filemode.c | 60 +- lib/filenamecat.h | 4 +- lib/filevercmp.c | 40 +- lib/findprog.c | 58 +- lib/flock.c | 42 +- lib/floor.c | 32 +- lib/fnmatch.c | 202 +- lib/fnmatch.in.h | 30 +- lib/fnmatch_loop.c | 1876 +++--- lib/fopen-safer.c | 36 +- lib/fopen.c | 58 +- lib/fprintf.c | 10 +- lib/fprintftime.h | 2 +- lib/fpucw.h | 12 +- lib/fpurge.c | 6 +- lib/freadahead.c | 18 +- lib/freading.c | 6 +- lib/freadseek.c | 42 +- lib/frexp.c | 118 +- lib/fseeko.c | 34 +- lib/fseterr.c | 4 +- lib/fstatat.c | 10 +- lib/fstrcmp.c | 144 +- lib/fstrcmp.h | 2 +- lib/fsusage.c | 34 +- lib/fsusage.h | 14 +- lib/fsync.c | 18 +- lib/ftello.c | 4 +- lib/ftruncate.c | 12 +- lib/fts-cycle.c | 56 +- lib/fts.c | 2460 ++++---- lib/fts_.h | 238 +- lib/full-write.c | 10 +- lib/fwriteerror.c | 88 +- lib/fwriting.c | 2 +- lib/gc-gnulib.c | 278 +- lib/gc-libgcrypt.c | 28 +- lib/gc-pbkdf2-sha1.c | 50 +- lib/gc.h | 32 +- lib/gcd.c | 38 +- lib/gen-uni-tables.c | 4616 +++++++-------- lib/getaddrinfo.c | 164 +- lib/getcwd.c | 254 +- lib/getdate.y | 1142 ++-- lib/getdelim.c | 74 +- lib/getdomainname.c | 2 +- lib/getdtablesize.c | 36 +- lib/gethostname.c | 2 +- lib/getloadavg.c | 250 +- lib/getndelim2.c | 148 +- lib/getnline.c | 2 +- lib/getnline.h | 4 +- lib/getopt.c | 1220 ++-- lib/getopt.in.h | 24 +- lib/getopt1.c | 136 +- lib/getopt_int.h | 32 +- lib/getpass.c | 44 +- lib/getsockopt.c | 2 +- lib/getsubopt.c | 14 +- lib/gettext.h | 28 +- lib/getugroups.c | 62 +- lib/getusershell.c | 22 +- lib/git-merge-changelog.c | 1510 ++--- lib/gl_anyavltree_list1.h | 8 +- lib/gl_anyavltree_list2.h | 636 +- lib/gl_anyhash_list2.h | 24 +- lib/gl_anylinked_list2.h | 578 +- lib/gl_anyrbtree_list1.h | 2 +- lib/gl_anyrbtree_list2.h | 926 +-- lib/gl_anytree_list2.h | 900 +-- lib/gl_anytree_oset.h | 176 +- lib/gl_anytreehash_list1.h | 236 +- lib/gl_anytreehash_list2.h | 254 +- lib/gl_array_list.c | 218 +- lib/gl_array_oset.c | 170 +- lib/gl_avltree_list.c | 4 +- lib/gl_avltree_oset.c | 512 +- lib/gl_avltreehash_list.c | 4 +- lib/gl_carray_list.c | 500 +- lib/gl_linkedhash_list.c | 14 +- lib/gl_list.c | 84 +- lib/gl_list.h | 236 +- lib/gl_oset.c | 12 +- lib/gl_oset.h | 32 +- lib/gl_rbtree_list.c | 4 +- lib/gl_rbtree_oset.c | 844 +-- lib/gl_rbtreehash_list.c | 4 +- lib/gl_sublist.c | 98 +- lib/gl_sublist.h | 2 +- lib/glob-libc.h | 76 +- lib/glob.c | 1700 +++--- lib/glob.in.h | 2 +- lib/glthread/cond.c | 300 +- lib/glthread/lock.c | 434 +- lib/glthread/thread.c | 32 +- lib/glthread/threadlib.c | 18 +- lib/hard-locale.c | 42 +- lib/hash.c | 490 +- lib/hash.h | 14 +- lib/hmac-md5.c | 2 +- lib/hmac-sha1.c | 2 +- lib/hmac.h | 4 +- lib/human.c | 320 +- lib/iconv.c | 522 +- lib/iconv.in.h | 4 +- lib/iconv_open.c | 84 +- lib/iconveh.h | 6 +- lib/idcache.c | 20 +- lib/idpriv-drop.c | 12 +- lib/idpriv-droptemp.c | 24 +- lib/imaxdiv.c | 38 +- lib/inet_ntop.c | 86 +- lib/inet_pton.c | 160 +- lib/intprops.h | 12 +- lib/inttostr.c | 4 +- lib/isapipe.c | 32 +- lib/isnan.c | 6 +- lib/javacomp.c | 2284 ++++---- lib/javacomp.h | 18 +- lib/javaexec.c | 412 +- lib/javaexec.h | 18 +- lib/javaversion.c | 8 +- lib/ldexpl.c | 32 +- lib/linebuffer.c | 30 +- lib/linebuffer.h | 6 +- lib/link.c | 72 +- lib/localcharset.c | 474 +- lib/localename.c | 782 +-- lib/logl.c | 24 +- lib/long-options.c | 44 +- lib/long-options.h | 12 +- lib/malloca.c | 64 +- lib/malloca.h | 8 +- lib/math.in.h | 24 +- lib/mbchar.c | 8 +- lib/mbchar.h | 106 +- lib/mbfile.h | 142 +- lib/mbiter.h | 102 +- lib/mbmemcasecmp.c | 62 +- lib/mbmemcasecoll.c | 62 +- lib/mbmemcasecoll.h | 4 +- lib/mbrtowc.c | 472 +- lib/mbscasecmp.c | 48 +- lib/mbscasestr.c | 542 +- lib/mbschr.c | 18 +- lib/mbscspn.c | 32 +- lib/mbslen.c | 2 +- lib/mbsncasecmp.c | 48 +- lib/mbsnlen.c | 2 +- lib/mbsnrtowcs.c | 170 +- lib/mbspbrk.c | 34 +- lib/mbspcasecmp.c | 42 +- lib/mbsrchr.c | 14 +- lib/mbsrtowcs.c | 166 +- lib/mbssep.c | 34 +- lib/mbsspn.c | 66 +- lib/mbsstr.c | 492 +- lib/mbstok_r.c | 38 +- lib/mbswidth.c | 178 +- lib/mbswidth.h | 2 +- lib/mbuiter.h | 100 +- lib/md2.c | 70 +- lib/md2.h | 4 +- lib/md4.c | 112 +- lib/md4.h | 4 +- lib/md5.c | 136 +- lib/md5.h | 10 +- lib/memcasecmp.c | 4 +- lib/memchr.c | 24 +- lib/memchr2.c | 28 +- lib/memcmp.c | 72 +- lib/memcmp2.c | 4 +- lib/memcoll.c | 46 +- lib/memmem.c | 6 +- lib/memmove.c | 2 +- lib/memrchr.c | 30 +- lib/memxfrm.c | 80 +- lib/mkancesdirs.c | 112 +- lib/mkancesdirs.h | 2 +- lib/mkdir-p.c | 212 +- lib/mkdir-p.h | 20 +- lib/mktime.c | 372 +- lib/modechange.c | 324 +- lib/modechange.h | 2 +- lib/mountlist.c | 472 +- lib/mountlist.h | 12 +- lib/mpsort.c | 98 +- lib/nanosleep.c | 32 +- lib/netdb.in.h | 80 +- lib/nproc.c | 284 +- lib/obstack.c | 78 +- lib/obstack.h | 420 +- lib/obstack_printf.c | 6 +- lib/open-safer.c | 2 +- lib/open.c | 30 +- lib/openat-die.c | 4 +- lib/openat-priv.h | 12 +- lib/openat-proc.c | 38 +- lib/openat-safer.c | 2 +- lib/openat.h | 2 +- lib/pagealign_alloc.c | 8 +- lib/pathmax.h | 2 +- lib/physmem.c | 86 +- lib/pipe-filter-aux.h | 2 +- lib/pipe-filter-gi.c | 340 +- lib/pipe-filter-ii.c | 396 +- lib/pipe-filter.h | 34 +- lib/pipe.c | 240 +- lib/pipe.h | 24 +- lib/pipe2.c | 30 +- lib/poll.c | 230 +- lib/poll.in.h | 18 +- lib/popen-safer.c | 6 +- lib/popen.c | 12 +- lib/posixtm.c | 52 +- lib/posixver.c | 2 +- lib/pread.c | 2 +- lib/printf-args.c | 208 +- lib/printf-args.h | 52 +- lib/printf-frexp.c | 146 +- lib/printf-parse.c | 938 +-- lib/printf-parse.h | 18 +- lib/priv-set.c | 44 +- lib/progname.c | 14 +- lib/progname.h | 4 +- lib/progreloc.c | 190 +- lib/propername.c | 288 +- lib/propername.h | 2 +- lib/pthread.in.h | 4 +- lib/putenv.c | 22 +- lib/quotearg.c | 710 +-- lib/quotearg.h | 30 +- lib/random_r.c | 84 +- lib/read-file.c | 50 +- lib/readline.c | 2 +- lib/readtokens.c | 80 +- lib/readtokens.h | 6 +- lib/readtokens0.c | 28 +- lib/readutmp.c | 16 +- lib/readutmp.h | 8 +- lib/realloc.c | 2 +- lib/recvfrom.c | 2 +- lib/relocatable.c | 272 +- lib/relocatable.h | 6 +- lib/relocwrapper.c | 58 +- lib/rijndael-alg-fst.c | 284 +- lib/rijndael-alg-fst.h | 8 +- lib/rijndael-api-fst.c | 352 +- lib/rijndael-api-fst.h | 42 +- lib/rmdir.c | 22 +- lib/round.c | 44 +- lib/rpmatch.c | 28 +- lib/safe-read.c | 8 +- lib/same.c | 46 +- lib/savedir.c | 42 +- lib/savewd.c | 198 +- lib/savewd.h | 22 +- lib/scandir.c | 80 +- lib/se-context.in.h | 8 +- lib/se-selinux.in.h | 16 +- lib/search.in.h | 8 +- lib/select.c | 214 +- lib/sendto.c | 2 +- lib/set-mode-acl.c | 364 +- lib/setenv.c | 196 +- lib/sh-quote.c | 30 +- lib/sha1.c | 130 +- lib/sha1.h | 4 +- lib/sha256.c | 192 +- lib/sha256.h | 4 +- lib/sha512.c | 230 +- lib/sha512.h | 4 +- lib/sig2str.c | 60 +- lib/sigaction.c | 2 +- lib/sigpipe-die.c | 20 +- lib/sigprocmask.c | 156 +- lib/sincosl.c | 788 +-- lib/sinl.c | 44 +- lib/snprintf.c | 10 +- lib/sockets.c | 32 +- lib/spawn.c | 6 +- lib/spawn.in.h | 86 +- lib/spawn_faction_addclose.c | 2 +- lib/spawn_faction_adddup2.c | 2 +- lib/spawn_faction_addopen.c | 4 +- lib/spawn_faction_init.c | 2 +- lib/spawn_int.h | 8 +- lib/spawnattr_getdefault.c | 2 +- lib/spawnattr_getschedparam.c | 2 +- lib/spawnattr_getschedpolicy.c | 2 +- lib/spawnattr_getsigmask.c | 2 +- lib/spawnattr_setdefault.c | 2 +- lib/spawnattr_setflags.c | 14 +- lib/spawnattr_setschedparam.c | 2 +- lib/spawnattr_setsigmask.c | 2 +- lib/spawni.c | 196 +- lib/spawnp.c | 6 +- lib/stat.c | 8 +- lib/stdint.in.h | 8 +- lib/stdio-impl.h | 42 +- lib/stdio-write.c | 40 +- lib/stdio.in.h | 22 +- lib/stdlib.in.h | 24 +- lib/stpncpy.c | 44 +- lib/str-kmp.h | 122 +- lib/str-two-way.h | 360 +- lib/strcasecmp.c | 2 +- lib/strcasestr.c | 18 +- lib/strerror.c | 8 +- lib/strftime.c | 1736 +++--- lib/strftime.h | 2 +- lib/striconv.c | 310 +- lib/striconv.h | 4 +- lib/striconveh.c | 1330 ++--- lib/striconveh.h | 26 +- lib/striconveha.c | 204 +- lib/striconveha.h | 18 +- lib/string.in.h | 32 +- lib/strncasecmp.c | 2 +- lib/strpbrk.c | 4 +- lib/strptime.c | 1614 +++--- lib/strsignal.c | 34 +- lib/strstr.c | 12 +- lib/strtod.c | 226 +- lib/strtoimax.c | 2 +- lib/strtok_r.c | 12 +- lib/strtol.c | 88 +- lib/strtoll.c | 2 +- lib/strtoul.c | 2 +- lib/strverscmp.c | 4 +- lib/symlink.c | 4 +- lib/symlinkat.c | 2 +- lib/sys_file.in.h | 2 +- lib/sys_socket.in.h | 40 +- lib/sys_stat.in.h | 16 +- lib/sys_times.in.h | 16 +- lib/tanl.c | 62 +- lib/tempname.c | 138 +- lib/tempname.h | 10 +- lib/time.in.h | 6 +- lib/times.c | 2 +- lib/timespec.h | 8 +- lib/tmpdir.c | 24 +- lib/tmpfile-safer.c | 44 +- lib/tmpfile.c | 80 +- lib/trigl.c | 350 +- lib/trim.c | 110 +- lib/trunc.c | 32 +- lib/tsearch.c | 462 +- lib/uname.c | 206 +- lib/unicase.h | 304 +- lib/unicase/cased.c | 4 +- lib/unicase/ignorable.c | 12 +- lib/unicase/invariant.h | 30 +- lib/unicase/locale-language.c | 4 +- lib/unicase/simple-mapping.h | 20 +- lib/unicase/u-casecmp.h | 10 +- lib/unicase/u-casecoll.h | 12 +- lib/unicase/u-casefold.h | 8 +- lib/unicase/u-casemap.h | 628 +- lib/unicase/u-casexfrm.h | 38 +- lib/unicase/u-ct-casefold.h | 88 +- lib/unicase/u-ct-totitle.h | 738 +-- lib/unicase/u-is-cased.h | 38 +- lib/unicase/u-is-invariant.h | 18 +- lib/unicase/u-prefix-context.h | 32 +- lib/unicase/u-suffix-context.h | 48 +- lib/unicase/u-totitle.h | 8 +- lib/unicase/u16-ct-tolower.c | 16 +- lib/unicase/u16-ct-toupper.c | 16 +- lib/unicase/u16-is-casefolded.c | 2 +- lib/unicase/u16-is-lowercase.c | 2 +- lib/unicase/u16-is-titlecase.c | 2 +- lib/unicase/u16-is-uppercase.c | 2 +- lib/unicase/u16-tolower.c | 14 +- lib/unicase/u16-toupper.c | 14 +- lib/unicase/u32-ct-tolower.c | 16 +- lib/unicase/u32-ct-toupper.c | 16 +- lib/unicase/u32-is-casefolded.c | 2 +- lib/unicase/u32-is-lowercase.c | 2 +- lib/unicase/u32-is-titlecase.c | 2 +- lib/unicase/u32-is-uppercase.c | 2 +- lib/unicase/u32-tolower.c | 14 +- lib/unicase/u32-toupper.c | 14 +- lib/unicase/u8-casefold.c | 44 +- lib/unicase/u8-ct-tolower.c | 16 +- lib/unicase/u8-ct-toupper.c | 16 +- lib/unicase/u8-is-casefolded.c | 2 +- lib/unicase/u8-is-lowercase.c | 2 +- lib/unicase/u8-is-titlecase.c | 2 +- lib/unicase/u8-is-uppercase.c | 2 +- lib/unicase/u8-tolower.c | 58 +- lib/unicase/u8-totitle.c | 44 +- lib/unicase/u8-toupper.c | 58 +- lib/unicase/ulc-casecmp.c | 18 +- lib/unicase/ulc-casexfrm.c | 18 +- lib/unicase/unicasemap.h | 42 +- lib/unicodeio.c | 52 +- lib/unicodeio.h | 14 +- lib/uniconv.h | 72 +- lib/uniconv/u-conv-from-enc.h | 42 +- lib/uniconv/u-conv-to-enc.h | 90 +- lib/uniconv/u-strconv-from-enc.h | 6 +- lib/uniconv/u-strconv-to-enc.h | 16 +- lib/uniconv/u16-conv-to-enc.c | 104 +- lib/uniconv/u8-conv-from-enc.c | 84 +- lib/uniconv/u8-conv-to-enc.c | 58 +- lib/uniconv/u8-strconv-to-enc.c | 40 +- lib/unictype.h | 6 +- lib/unictype/3level.h | 152 +- lib/unictype/3levelbit.h | 152 +- lib/unictype/bidi_byname.c | 214 +- lib/unictype/bidi_of.c | 32 +- lib/unictype/bitmap.h | 20 +- lib/unictype/blocks.c | 6 +- lib/unictype/categ_and.c | 2 +- lib/unictype/categ_and_not.c | 2 +- lib/unictype/categ_byname.c | 130 +- lib/unictype/categ_name.c | 70 +- lib/unictype/categ_of.c | 30 +- lib/unictype/categ_or.c | 2 +- lib/unictype/combining.c | 22 +- lib/unictype/decdigit.c | 26 +- lib/unictype/digit.c | 26 +- lib/unictype/identsyntaxmap.h | 22 +- lib/unictype/mirror.c | 24 +- lib/unictype/numeric.c | 32 +- lib/unictype/pr_bidi_embedding_or_override.c | 2 +- lib/unictype/pr_byname.c | 10 +- lib/unictype/pr_private_use.c | 4 +- lib/unictype/scripts.c | 22 +- lib/unilbrk.h | 32 +- lib/unilbrk/lbrktables.c | 4 +- lib/unilbrk/lbrktables.h | 18 +- lib/unilbrk/u16-possible-linebreaks.c | 214 +- lib/unilbrk/u16-width-linebreaks.c | 82 +- lib/unilbrk/u32-possible-linebreaks.c | 214 +- lib/unilbrk/u32-width-linebreaks.c | 82 +- lib/unilbrk/u8-possible-linebreaks.c | 288 +- lib/unilbrk/u8-width-linebreaks.c | 150 +- lib/unilbrk/ulc-common.c | 2 +- lib/unilbrk/ulc-possible-linebreaks.c | 194 +- lib/unilbrk/ulc-width-linebreaks.c | 230 +- lib/uniname/uniname.c | 642 +-- lib/uninorm.h | 28 +- lib/uninorm/canonical-decomposition.c | 102 +- lib/uninorm/composition.c | 82 +- lib/uninorm/decompose-internal.h | 4 +- lib/uninorm/decomposition-table.h | 18 +- lib/uninorm/decomposition.c | 94 +- lib/uninorm/u-normalize-internal.h | 564 +- lib/uninorm/u-normcmp.h | 10 +- lib/uninorm/u-normcoll.h | 12 +- lib/uninorm/u-normxfrm.h | 38 +- lib/uninorm/uninorm-filter.c | 392 +- lib/unistd.in.h | 46 +- lib/unistdio.h | 116 +- lib/unistdio/u-vsnprintf.h | 14 +- lib/unistdio/ulc-fprintf.c | 10 +- lib/unistdio/ulc-vfprintf.c | 10 +- lib/unistr.h | 22 +- lib/unistr/u-cmp2.h | 4 +- lib/unistr/u-cpy-alloc.h | 2 +- lib/unistr/u-move.h | 4 +- lib/unistr/u-set.h | 18 +- lib/unistr/u-startswith.h | 4 +- lib/unistr/u-strcoll.h | 68 +- lib/unistr/u-strcspn.h | 28 +- lib/unistr/u-strdup.h | 2 +- lib/unistr/u-strpbrk.h | 14 +- lib/unistr/u-strspn.h | 28 +- lib/unistr/u-strstr.h | 22 +- lib/unistr/u-strtok.h | 8 +- lib/unistr/u16-check.c | 24 +- lib/unistr/u16-chr.c | 32 +- lib/unistr/u16-cmp.c | 28 +- lib/unistr/u16-mblen.c | 20 +- lib/unistr/u16-mbsnlen.c | 2 +- lib/unistr/u16-mbtouc-aux.c | 22 +- lib/unistr/u16-mbtouc-unsafe-aux.c | 22 +- lib/unistr/u16-mbtouc-unsafe.c | 22 +- lib/unistr/u16-mbtouc.c | 22 +- lib/unistr/u16-mbtoucr.c | 26 +- lib/unistr/u16-next.c | 2 +- lib/unistr/u16-prev.c | 26 +- lib/unistr/u16-strchr.c | 42 +- lib/unistr/u16-strcmp.c | 22 +- lib/unistr/u16-strmblen.c | 2 +- lib/unistr/u16-strmbtouc.c | 8 +- lib/unistr/u16-strncmp.c | 28 +- lib/unistr/u16-strrchr.c | 40 +- lib/unistr/u16-to-u32.c | 80 +- lib/unistr/u16-to-u8.c | 98 +- lib/unistr/u16-uctomb-aux.c | 34 +- lib/unistr/u16-uctomb.c | 42 +- lib/unistr/u32-check.c | 6 +- lib/unistr/u32-chr.c | 2 +- lib/unistr/u32-cmp.c | 8 +- lib/unistr/u32-mblen.c | 2 +- lib/unistr/u32-next.c | 2 +- lib/unistr/u32-prev.c | 8 +- lib/unistr/u32-strchr.c | 4 +- lib/unistr/u32-strcmp.c | 2 +- lib/unistr/u32-strcspn.c | 6 +- lib/unistr/u32-strncmp.c | 8 +- lib/unistr/u32-strpbrk.c | 6 +- lib/unistr/u32-strrchr.c | 4 +- lib/unistr/u32-strspn.c | 6 +- lib/unistr/u32-to-u16.c | 88 +- lib/unistr/u32-to-u8.c | 88 +- lib/unistr/u32-uctomb.c | 10 +- lib/unistr/u8-check.c | 124 +- lib/unistr/u8-chr.c | 80 +- lib/unistr/u8-mblen.c | 96 +- lib/unistr/u8-mbsnlen.c | 2 +- lib/unistr/u8-mbtouc-aux.c | 222 +- lib/unistr/u8-mbtouc-unsafe-aux.c | 222 +- lib/unistr/u8-mbtouc-unsafe.c | 222 +- lib/unistr/u8-mbtouc.c | 222 +- lib/unistr/u8-mbtoucr.c | 474 +- lib/unistr/u8-next.c | 2 +- lib/unistr/u8-prev.c | 90 +- lib/unistr/u8-set.c | 10 +- lib/unistr/u8-strchr.c | 102 +- lib/unistr/u8-strmblen.c | 72 +- lib/unistr/u8-strmbtouc.c | 132 +- lib/unistr/u8-strrchr.c | 102 +- lib/unistr/u8-to-u16.c | 98 +- lib/unistr/u8-to-u32.c | 80 +- lib/unistr/u8-uctomb-aux.c | 4 +- lib/unistr/u8-uctomb.c | 56 +- lib/uniwbrk/u-wordbreaks.h | 164 +- lib/uniwbrk/u8-wordbreaks.c | 66 +- lib/uniwbrk/ulc-wordbreaks.c | 166 +- lib/uniwbrk/wbrktable.c | 20 +- lib/uniwbrk/wordbreak-property.c | 18 +- lib/uniwidth/u16-width.c | 4 +- lib/uniwidth/u32-width.c | 4 +- lib/uniwidth/u8-width.c | 4 +- lib/uniwidth/width.c | 52 +- lib/unlink.c | 74 +- lib/unlinkat.c | 42 +- lib/unlinkdir.c | 4 +- lib/unsetenv.c | 18 +- lib/userspec.h | 2 +- lib/utime.c | 10 +- lib/utimecmp.c | 360 +- lib/vasnprintf.c | 8024 +++++++++++++------------- lib/vdprintf.c | 10 +- lib/verify.h | 4 +- lib/verror.c | 4 +- lib/version-etc.c | 88 +- lib/version-etc.h | 20 +- lib/vfprintf.c | 10 +- lib/vsnprintf.c | 10 +- lib/w32spawn.h | 124 +- lib/wait-process.c | 188 +- lib/wait-process.h | 6 +- lib/wcrtomb.c | 10 +- lib/wcsnrtombs.c | 92 +- lib/wcsrtombs.c | 92 +- lib/wctype.in.h | 10 +- lib/wcwidth.c | 2 +- lib/write.c | 16 +- lib/xalloc.h | 46 +- lib/xconcat-filename.c | 2 +- lib/xgetdomainname.c | 14 +- lib/xgethostname.c | 28 +- lib/xmalloca.h | 2 +- lib/xmemcoll.c | 6 +- lib/xnanosleep.c | 56 +- lib/xprintf.h | 4 +- lib/xstriconv.c | 2 +- lib/xstriconv.h | 4 +- lib/xstriconveh.c | 26 +- lib/xstriconveh.h | 24 +- lib/xstrtod.c | 6 +- lib/xstrtod.h | 4 +- lib/xstrtol-error.c | 10 +- lib/xstrtol.c | 182 +- lib/xstrtol.h | 6 +- lib/xtime.h | 8 +- lib/xvasprintf.c | 22 +- m4/absolute-header.m4 | 8 +- m4/acl.m4 | 134 +- m4/afs.m4 | 4 +- m4/argp.m4 | 4 +- m4/argz.m4 | 48 +- m4/assert.m4 | 2 +- m4/c-stack.m4 | 32 +- m4/c-strtod.m4 | 22 +- m4/calloc.m4 | 12 +- m4/chown.m4 | 32 +- m4/d-ino.m4 | 36 +- m4/d-type.m4 | 6 +- m4/dirfd.m4 | 38 +- m4/dos.m4 | 22 +- m4/double-slash-root.m4 | 40 +- m4/dup2.m4 | 24 +- m4/extensions.m4 | 4 +- m4/fcntl_h.m4 | 90 +- m4/fdopendir.m4 | 6 +- m4/fflush.m4 | 68 +- m4/flexmember.m4 | 18 +- m4/fpending.m4 | 86 +- m4/fpurge.m4 | 30 +- m4/free.m4 | 12 +- m4/fseeko.m4 | 2 +- m4/fsusage.m4 | 14 +- m4/ftello.m4 | 2 +- m4/ftruncate.m4 | 8 +- m4/gc-random.m4 | 20 +- m4/getaddrinfo.m4 | 2 +- m4/getcwd-abort-bug.m4 | 14 +- m4/getcwd-path-max.m4 | 102 +- m4/getcwd.m4 | 32 +- m4/gethrxtime.m4 | 12 +- m4/getline.m4 | 8 +- m4/getloadavg.m4 | 44 +- m4/getopt.m4 | 14 +- m4/gettimeofday.m4 | 50 +- m4/glibc2.m4 | 8 +- m4/glibc21.m4 | 8 +- m4/glob.m4 | 4 +- m4/gnulib-common.m4 | 10 +- m4/host-os.m4 | 94 +- m4/iconv_open.m4 | 20 +- m4/include_next.m4 | 78 +- m4/inttypes.m4 | 48 +- m4/isapipe.m4 | 86 +- m4/isinf.m4 | 2 +- m4/jm-winsz1.m4 | 16 +- m4/jm-winsz2.m4 | 2 +- m4/ld-version-script.m4 | 2 +- m4/lib-ignore.m4 | 8 +- m4/lib-ld.m4 | 6 +- m4/link-follow.m4 | 54 +- m4/longlong.m4 | 64 +- m4/ls-mntd-fs.m4 | 30 +- m4/lseek.m4 | 20 +- m4/math_h.m4 | 8 +- m4/mbstate_t.m4 | 16 +- m4/memchr.m4 | 8 +- m4/memcmp.m4 | 8 +- m4/memmem.m4 | 28 +- m4/mkstemp.m4 | 38 +- m4/mktime.m4 | 58 +- m4/mountlist.m4 | 2 +- m4/nanosleep.m4 | 88 +- m4/openat.m4 | 8 +- m4/openmp.m4 | 48 +- m4/physmem.m4 | 14 +- m4/po.m4 | 8 +- m4/posix-shell.m4 | 18 +- m4/posix_spawn.m4 | 16 +- m4/pthread.m4 | 4 +- m4/pty.m4 | 2 +- m4/putenv.m4 | 10 +- m4/readline.m4 | 2 +- m4/regex.m4 | 260 +- m4/rmdir-errno.m4 | 22 +- m4/rmdir.m4 | 8 +- m4/selinux-context-h.m4 | 4 +- m4/selinux-selinux-h.m4 | 6 +- m4/socklen.m4 | 26 +- m4/st_dm_mode.m4 | 2 +- m4/stat-time.m4 | 52 +- m4/stdbool.m4 | 138 +- m4/stdint.m4 | 12 +- m4/stdio_h.m4 | 4 +- m4/strcasestr.m4 | 28 +- m4/string_h.m4 | 54 +- m4/strndup.m4 | 2 +- m4/strsignal.m4 | 22 +- m4/strstr.m4 | 14 +- m4/strtod.m4 | 6 +- m4/sys_select_h.m4 | 2 +- m4/sys_time_h.m4 | 12 +- m4/time_h.m4 | 18 +- m4/timegm.m4 | 2 +- m4/tzset.m4 | 10 +- m4/ungetc.m4 | 30 +- m4/unlink-busy.m4 | 10 +- m4/uptime.m4 | 2 +- m4/utimbuf.m4 | 18 +- m4/utime.m4 | 24 +- m4/utimes-null.m4 | 10 +- m4/utimes.m4 | 16 +- m4/vararrays.m4 | 4 +- m4/version-etc.m4 | 10 +- m4/warnings.m4 | 2 +- tests/test-arcfour.c | 8 +- tests/test-arctwo.c | 12 +- tests/test-argmatch.c | 16 +- tests/test-argp.c | 10 +- tests/test-array-mergesort.c | 38 +- tests/test-array_list.c | 16 +- tests/test-array_oset.c | 32 +- tests/test-avltree_list.c | 16 +- tests/test-avltree_oset.c | 16 +- tests/test-avltreehash_list.c | 16 +- tests/test-base64.c | 20 +- tests/test-binary-io.c | 16 +- tests/test-bitrotate.c | 22 +- tests/test-btowc.c | 40 +- tests/test-byteswap.c | 16 +- tests/test-c-ctype.c | 636 +- tests/test-c-stack.c | 26 +- tests/test-c-strcasecmp.c | 18 +- tests/test-c-strcasestr.c | 64 +- tests/test-c-strncasecmp.c | 18 +- tests/test-c-strstr.c | 64 +- tests/test-canonicalize-lgpl.c | 32 +- tests/test-canonicalize.c | 20 +- tests/test-carray_list.c | 16 +- tests/test-ceilf1.c | 16 +- tests/test-ceilf2.c | 70 +- tests/test-ceill.c | 16 +- tests/test-copy-acl.c | 16 +- tests/test-copy-file.c | 16 +- tests/test-des.c | 210 +- tests/test-dirname.c | 228 +- tests/test-dprintf-posix.c | 16 +- tests/test-dup3.c | 22 +- tests/test-duplocale.c | 20 +- tests/test-environ.c | 4 +- tests/test-exclude.c | 46 +- tests/test-fbufmode.c | 18 +- tests/test-fchdir.c | 50 +- tests/test-fcntl-h.c | 4 +- tests/test-fdopendir.c | 16 +- tests/test-fflush.c | 8 +- tests/test-fflush2.c | 112 +- tests/test-file-has-acl.c | 20 +- tests/test-filenamecat.c | 8 +- tests/test-filevercmp.c | 34 +- tests/test-flock.c | 24 +- tests/test-floorf1.c | 16 +- tests/test-floorf2.c | 70 +- tests/test-floorl.c | 16 +- tests/test-fnmatch.c | 22 +- tests/test-fopen.h | 16 +- tests/test-fpending.c | 16 +- tests/test-fprintf-posix.c | 16 +- tests/test-fprintf-posix2.c | 10 +- tests/test-fpurge.c | 70 +- tests/test-freadable.c | 16 +- tests/test-freadahead.c | 62 +- tests/test-freadptr.c | 64 +- tests/test-freadptr2.c | 26 +- tests/test-freadseek.c | 16 +- tests/test-freopen.c | 16 +- tests/test-frexp.c | 16 +- tests/test-frexpl.c | 16 +- tests/test-fseek.c | 16 +- tests/test-fstrcmp.c | 22 +- tests/test-ftell.c | 16 +- tests/test-ftello.c | 16 +- tests/test-func.c | 22 +- tests/test-fwritable.c | 16 +- tests/test-fwriting.c | 16 +- tests/test-gc-arcfour.c | 8 +- tests/test-gc-arctwo.c | 8 +- tests/test-gc-des.c | 46 +- tests/test-gc-hmac-md5.c | 22 +- tests/test-gc-hmac-sha1.c | 22 +- tests/test-gc-md2.c | 76 +- tests/test-gc-md4.c | 74 +- tests/test-gc-md5.c | 76 +- tests/test-gc-pbkdf2-sha1.c | 22 +- tests/test-gc-rijndael.c | 90 +- tests/test-gc-sha1.c | 74 +- tests/test-getaddrinfo.c | 68 +- tests/test-getcwd.c | 2 +- tests/test-getdate.c | 60 +- tests/test-getdelim.c | 16 +- tests/test-getdtablesize.c | 16 +- tests/test-getline.c | 16 +- tests/test-getndelim2.c | 20 +- tests/test-getopt.c | 16 +- tests/test-getopt.h | 174 +- tests/test-getopt_long.h | 190 +- tests/test-glob.c | 22 +- tests/test-hash.c | 168 +- tests/test-hmac-md5.c | 66 +- tests/test-hmac-sha1.c | 66 +- tests/test-i-ring.c | 16 +- tests/test-iconv-utf.c | 48 +- tests/test-iconv.c | 42 +- tests/test-iconvme.c | 18 +- tests/test-idpriv-drop.c | 42 +- tests/test-idpriv-droptemp.c | 52 +- tests/test-inet_ntop.c | 16 +- tests/test-inet_pton.c | 16 +- tests/test-isblank.c | 16 +- tests/test-isfinite.c | 16 +- tests/test-isinf.c | 16 +- tests/test-isnan.c | 16 +- tests/test-isnand.h | 16 +- tests/test-isnanf.h | 16 +- tests/test-isnanl.h | 16 +- tests/test-ldexpl.c | 22 +- tests/test-linked_list.c | 16 +- tests/test-linkedhash_list.c | 16 +- tests/test-localename.c | 28 +- tests/test-lock.c | 56 +- tests/test-lseek.c | 20 +- tests/test-lstat.c | 10 +- tests/test-lstat.h | 4 +- tests/test-mbmemcasecmp.c | 34 +- tests/test-mbmemcasecmp.h | 82 +- tests/test-mbmemcasecoll.c | 34 +- tests/test-mbrtowc.c | 458 +- tests/test-mbscasecmp.c | 16 +- tests/test-mbscasestr1.c | 64 +- tests/test-mbscasestr2.c | 64 +- tests/test-mbscasestr3.c | 16 +- tests/test-mbscasestr4.c | 16 +- tests/test-mbschr.c | 16 +- tests/test-mbscspn.c | 16 +- tests/test-mbsinit.c | 18 +- tests/test-mbsncasecmp.c | 16 +- tests/test-mbsnrtowcs.c | 432 +- tests/test-mbspbrk.c | 16 +- tests/test-mbspcasecmp.c | 16 +- tests/test-mbsrchr.c | 16 +- tests/test-mbsrtowcs.c | 432 +- tests/test-mbsspn.c | 16 +- tests/test-mbsstr1.c | 64 +- tests/test-mbsstr2.c | 64 +- tests/test-mbsstr3.c | 16 +- tests/test-md2.c | 8 +- tests/test-md4.c | 8 +- tests/test-md5.c | 8 +- tests/test-memchr.c | 66 +- tests/test-memchr2.c | 40 +- tests/test-memcmp.c | 28 +- tests/test-memmem.c | 72 +- tests/test-memrchr.c | 32 +- tests/test-mkdir.c | 10 +- tests/test-obstack-printf.c | 16 +- tests/test-openat-safer.c | 92 +- tests/test-pipe-filter-gi1.c | 30 +- tests/test-pipe-filter-gi2-child.c | 8 +- tests/test-pipe-filter-gi2-main.c | 24 +- tests/test-pipe-filter-ii1.c | 34 +- tests/test-pipe-filter-ii2-child.c | 8 +- tests/test-pipe-filter-ii2-main.c | 34 +- tests/test-pipe.c | 4 +- tests/test-pipe2.c | 86 +- tests/test-poll.c | 4 +- tests/test-popen.h | 44 +- tests/test-posix_spawn1.c | 4 +- tests/test-posix_spawn2.c | 4 +- tests/test-posixtm.c | 16 +- tests/test-pread.c | 12 +- tests/test-printf-frexp.c | 16 +- tests/test-printf-frexpl.c | 16 +- tests/test-printf-posix.c | 16 +- tests/test-printf-posix2.c | 10 +- tests/test-priv-set.c | 16 +- tests/test-quotearg.c | 54 +- tests/test-random_r.c | 18 +- tests/test-rawmemchr.c | 18 +- tests/test-rbtree_list.c | 16 +- tests/test-rbtree_oset.c | 16 +- tests/test-rbtreehash_list.c | 16 +- tests/test-read-file.c | 70 +- tests/test-readlink.c | 10 +- tests/test-readlink.h | 8 +- tests/test-remove.c | 10 +- tests/test-renameat.c | 10 +- tests/test-rijndael.c | 16 +- tests/test-rmdir.c | 10 +- tests/test-rmdir.h | 4 +- tests/test-round1.c | 16 +- tests/test-round2.c | 24 +- tests/test-roundf1.c | 16 +- tests/test-roundl.c | 16 +- tests/test-safe-alloc.c | 16 +- tests/test-sameacls.c | 468 +- tests/test-select-fd.c | 66 +- tests/test-select-stdin.c | 46 +- tests/test-select.c | 2 +- tests/test-set-mode-acl.c | 16 +- tests/test-sha1.c | 6 +- tests/test-sigaction.c | 24 +- tests/test-signbit.c | 16 +- tests/test-sigpipe.c | 26 +- tests/test-snprintf-posix.c | 16 +- tests/test-snprintf-posix.h | 1626 +++--- tests/test-snprintf.c | 44 +- tests/test-sprintf-posix.c | 16 +- tests/test-sprintf-posix.h | 1604 ++--- tests/test-strcasestr.c | 64 +- tests/test-strerror.c | 16 +- tests/test-striconv.c | 24 +- tests/test-striconveh.c | 1448 ++--- tests/test-striconveha.c | 678 +-- tests/test-strsignal.c | 16 +- tests/test-strstr.c | 66 +- tests/test-strtod.c | 160 +- tests/test-strverscmp.c | 16 +- tests/test-symlink.c | 10 +- tests/test-symlinkat.c | 12 +- tests/test-times.c | 2 +- tests/test-tls.c | 28 +- tests/test-trunc1.c | 16 +- tests/test-trunc2.c | 78 +- tests/test-truncf1.c | 16 +- tests/test-truncf2.c | 78 +- tests/test-truncl.c | 16 +- tests/test-tsearch.c | 158 +- tests/test-uname.c | 18 +- tests/test-unlink.c | 10 +- tests/test-unlinkat.c | 12 +- tests/test-vasnprintf-posix.c | 1656 +++--- tests/test-vasnprintf-posix2.c | 28 +- tests/test-vasnprintf.c | 24 +- tests/test-vasprintf-posix.c | 1652 +++--- tests/test-vasprintf.c | 16 +- tests/test-vdprintf-posix.c | 16 +- tests/test-vfprintf-posix.c | 16 +- tests/test-vprintf-posix.c | 16 +- tests/test-vsnprintf-posix.c | 16 +- tests/test-vsnprintf.c | 44 +- tests/test-vsprintf-posix.c | 16 +- tests/test-wcrtomb.c | 132 +- tests/test-wcsnrtombs.c | 304 +- tests/test-wcsrtombs.c | 304 +- tests/test-wctype.c | 16 +- tests/test-wcwidth.c | 26 +- tests/test-xfprintf-posix.c | 16 +- tests/test-xmemdup0.c | 18 +- tests/test-xprintf-posix.c | 16 +- tests/test-xstrtol.c | 12 +- tests/test-xvasprintf.c | 16 +- tests/unicase/test-casecmp.h | 2 +- tests/unicase/test-locale-language.c | 16 +- tests/unicase/test-mapping-part1.h | 20 +- tests/unicase/test-mapping-part2.h | 2 +- tests/unicase/test-predicate-part1.h | 20 +- tests/unicase/test-predicate-part2.h | 4 +- tests/unicase/test-u16-casecmp.c | 64 +- tests/unicase/test-u16-casecoll.c | 16 +- tests/unicase/test-u16-casefold.c | 56 +- tests/unicase/test-u16-is-cased.c | 16 +- tests/unicase/test-u16-is-casefolded.c | 16 +- tests/unicase/test-u16-is-lowercase.c | 16 +- tests/unicase/test-u16-is-titlecase.c | 16 +- tests/unicase/test-u16-is-uppercase.c | 16 +- tests/unicase/test-u16-tolower.c | 56 +- tests/unicase/test-u16-totitle.c | 56 +- tests/unicase/test-u16-toupper.c | 56 +- tests/unicase/test-u32-casecmp.c | 64 +- tests/unicase/test-u32-casecoll.c | 16 +- tests/unicase/test-u32-casefold.c | 56 +- tests/unicase/test-u32-is-cased.c | 16 +- tests/unicase/test-u32-is-casefolded.c | 16 +- tests/unicase/test-u32-is-lowercase.c | 16 +- tests/unicase/test-u32-is-titlecase.c | 16 +- tests/unicase/test-u32-is-uppercase.c | 16 +- tests/unicase/test-u32-tolower.c | 56 +- tests/unicase/test-u32-totitle.c | 56 +- tests/unicase/test-u32-toupper.c | 56 +- tests/unicase/test-u8-casecmp.c | 82 +- tests/unicase/test-u8-casecoll.c | 16 +- tests/unicase/test-u8-casefold.c | 68 +- tests/unicase/test-u8-is-cased.c | 16 +- tests/unicase/test-u8-is-casefolded.c | 16 +- tests/unicase/test-u8-is-lowercase.c | 16 +- tests/unicase/test-u8-is-titlecase.c | 16 +- tests/unicase/test-u8-is-uppercase.c | 16 +- tests/unicase/test-u8-tolower.c | 68 +- tests/unicase/test-u8-totitle.c | 68 +- tests/unicase/test-u8-toupper.c | 68 +- tests/unicase/test-ulc-casecmp.c | 94 +- tests/unicase/test-ulc-casecoll.c | 16 +- tests/uniconv/test-u16-conv-from-enc.c | 254 +- tests/uniconv/test-u16-conv-to-enc.c | 206 +- tests/uniconv/test-u16-strconv-from-enc.c | 52 +- tests/uniconv/test-u16-strconv-to-enc.c | 80 +- tests/uniconv/test-u32-conv-from-enc.c | 254 +- tests/uniconv/test-u32-conv-to-enc.c | 172 +- tests/uniconv/test-u32-strconv-from-enc.c | 52 +- tests/uniconv/test-u32-strconv-to-enc.c | 80 +- tests/uniconv/test-u8-conv-from-enc.c | 226 +- tests/uniconv/test-u8-conv-to-enc.c | 212 +- tests/uniconv/test-u8-strconv-from-enc.c | 16 +- tests/uniconv/test-u8-strconv-to-enc.c | 62 +- tests/unictype/test-bidi_byname.c | 16 +- tests/unictype/test-bidi_name.c | 16 +- tests/unictype/test-bidi_of.c | 16 +- tests/unictype/test-bidi_test.c | 16 +- tests/unictype/test-block_list.c | 24 +- tests/unictype/test-block_of.c | 36 +- tests/unictype/test-block_test.c | 16 +- tests/unictype/test-categ_and.c | 16 +- tests/unictype/test-categ_and_not.c | 16 +- tests/unictype/test-categ_byname.c | 16 +- tests/unictype/test-categ_name.c | 16 +- tests/unictype/test-categ_none.c | 16 +- tests/unictype/test-categ_of.c | 16 +- tests/unictype/test-categ_or.c | 16 +- tests/unictype/test-categ_test_withtable.c | 16 +- tests/unictype/test-combining.c | 16 +- tests/unictype/test-decdigit.c | 18 +- tests/unictype/test-digit.c | 18 +- tests/unictype/test-mirror.c | 16 +- tests/unictype/test-numeric.c | 26 +- tests/unictype/test-pr_byname.c | 16 +- tests/unictype/test-pr_test.c | 16 +- tests/unictype/test-predicate-part1.h | 20 +- tests/unictype/test-predicate-part2.h | 4 +- tests/unictype/test-scripts.c | 28 +- tests/unictype/test-sy_c_ident.c | 16 +- tests/unictype/test-sy_java_ident.c | 16 +- tests/unilbrk/test-u16-possible-linebreaks.c | 66 +- tests/unilbrk/test-u16-width-linebreaks.c | 46 +- tests/unilbrk/test-u32-possible-linebreaks.c | 66 +- tests/unilbrk/test-u32-width-linebreaks.c | 46 +- tests/unilbrk/test-u8-possible-linebreaks.c | 56 +- tests/unilbrk/test-u8-width-linebreaks.c | 36 +- tests/unilbrk/test-ulc-possible-linebreaks.c | 24 +- tests/unilbrk/test-ulc-width-linebreaks.c | 22 +- tests/uniname/test-uninames.c | 152 +- tests/uninorm/test-canonical-decomposition.c | 16 +- tests/uninorm/test-compat-decomposition.c | 16 +- tests/uninorm/test-composition.c | 16 +- tests/uninorm/test-decomposing-form.c | 16 +- tests/uninorm/test-decomposition.c | 16 +- tests/uninorm/test-u16-nfc.c | 164 +- tests/uninorm/test-u16-nfd.c | 158 +- tests/uninorm/test-u16-nfkc.c | 176 +- tests/uninorm/test-u16-nfkd.c | 160 +- tests/uninorm/test-u16-normcmp.c | 16 +- tests/uninorm/test-u16-normcmp.h | 2 +- tests/uninorm/test-u16-normcoll.c | 16 +- tests/uninorm/test-u32-nfc-big.c | 20 +- tests/uninorm/test-u32-nfc.c | 164 +- tests/uninorm/test-u32-nfd-big.c | 20 +- tests/uninorm/test-u32-nfd.c | 158 +- tests/uninorm/test-u32-nfkc-big.c | 20 +- tests/uninorm/test-u32-nfkc.c | 176 +- tests/uninorm/test-u32-nfkd-big.c | 20 +- tests/uninorm/test-u32-nfkd.c | 160 +- tests/uninorm/test-u32-normalize-big.c | 272 +- tests/uninorm/test-u32-normalize-big.h | 12 +- tests/uninorm/test-u32-normcmp.c | 16 +- tests/uninorm/test-u32-normcmp.h | 2 +- tests/uninorm/test-u32-normcoll.c | 16 +- tests/uninorm/test-u8-nfc.c | 222 +- tests/uninorm/test-u8-nfd.c | 214 +- tests/uninorm/test-u8-nfkc.c | 242 +- tests/uninorm/test-u8-nfkd.c | 218 +- tests/uninorm/test-u8-normcmp.c | 16 +- tests/uninorm/test-u8-normcmp.h | 2 +- tests/uninorm/test-u8-normcoll.c | 16 +- tests/uninorm/test-uninorm-filter-nfc.c | 38 +- tests/unistdio/test-u16-asnprintf1.c | 16 +- tests/unistdio/test-u16-asnprintf1.h | 10 +- tests/unistdio/test-u16-printf1.h | 390 +- tests/unistdio/test-u16-vasnprintf1.c | 16 +- tests/unistdio/test-u16-vasnprintf2.c | 44 +- tests/unistdio/test-u16-vasnprintf3.c | 44 +- tests/unistdio/test-u16-vasprintf1.c | 16 +- tests/unistdio/test-u16-vsnprintf1.c | 16 +- tests/unistdio/test-u16-vsprintf1.c | 16 +- tests/unistdio/test-u32-asnprintf1.c | 16 +- tests/unistdio/test-u32-asnprintf1.h | 10 +- tests/unistdio/test-u32-printf1.h | 390 +- tests/unistdio/test-u32-vasnprintf1.c | 16 +- tests/unistdio/test-u32-vasnprintf2.c | 44 +- tests/unistdio/test-u32-vasnprintf3.c | 44 +- tests/unistdio/test-u32-vasprintf1.c | 16 +- tests/unistdio/test-u32-vsnprintf1.c | 16 +- tests/unistdio/test-u32-vsprintf1.c | 16 +- tests/unistdio/test-u8-asnprintf1.c | 16 +- tests/unistdio/test-u8-asnprintf1.h | 4 +- tests/unistdio/test-u8-printf1.h | 112 +- tests/unistdio/test-u8-vasnprintf1.c | 16 +- tests/unistdio/test-u8-vasnprintf2.c | 24 +- tests/unistdio/test-u8-vasnprintf3.c | 24 +- tests/unistdio/test-u8-vasprintf1.c | 16 +- tests/unistdio/test-u8-vsnprintf1.c | 16 +- tests/unistdio/test-u8-vsprintf1.c | 16 +- tests/unistdio/test-ulc-asnprintf1.c | 16 +- tests/unistdio/test-ulc-asnprintf1.h | 4 +- tests/unistdio/test-ulc-printf1.h | 80 +- tests/unistdio/test-ulc-vasnprintf1.c | 16 +- tests/unistdio/test-ulc-vasnprintf2.c | 80 +- tests/unistdio/test-ulc-vasnprintf3.c | 56 +- tests/unistdio/test-ulc-vasprintf1.c | 16 +- tests/unistdio/test-ulc-vsnprintf1.c | 16 +- tests/unistdio/test-ulc-vsprintf1.c | 16 +- tests/uniwbrk/test-u16-wordbreaks.c | 70 +- tests/uniwbrk/test-u32-wordbreaks.c | 70 +- tests/uniwbrk/test-u8-wordbreaks.c | 56 +- tests/uniwbrk/test-ulc-wordbreaks.c | 28 +- tests/uniwidth/test-u16-strwidth.c | 20 +- tests/uniwidth/test-u16-width.c | 16 +- tests/uniwidth/test-u32-strwidth.c | 20 +- tests/uniwidth/test-u32-width.c | 16 +- tests/uniwidth/test-u8-strwidth.c | 16 +- tests/uniwidth/test-u8-width.c | 16 +- tests/uniwidth/test-uc_width.c | 16 +- tests/uniwidth/test-uc_width2.c | 42 +- tests/zerosize-ptr.h | 8 +- 1202 files changed, 57621 insertions(+), 57558 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89af21a15..db9205ae2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2009-12-10 Bruno Haible + Use spaces for indentation, not tabs. + * lib/**/*.[hcy] except lib/reg*.[hc]: Untabify. + * m4/*.m4: Untabify. + * build-aux/*.h: Untabify. + * tests/**/*.[hc]: Untabify. + * README: New section "Indent with spaces, not TABs", based on + coreutils/HACKING and comments by Pádraig Brady and Paolo Bonzini. + * NEWS: Mention the change. + +2009-12-10 Bruno Haible + pty test: Fix link error. * modules/pty-tests (Makefile.am): Add the default LDADD value to test_pty_LDADD. diff --git a/NEWS b/NEWS index cfa017c34..21fd1f722 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ User visible incompatible changes Date Modules Changes +2009-12-10 * Most source code files have been converted to + indentation by spaces (rather than tabs). Patches + of gnulib source code needs to be updated. + 2009-12-09 link-warning The Makefile rules that use $(LINK_WARNING_H) now must contain an explicit dependency on $(LINK_WARNING_H). diff --git a/README b/README index 4b699a7a2..eb6c62030 100644 --- a/README +++ b/README @@ -49,6 +49,10 @@ git resources: http://www.kernel.org/pub/software/scm/git/docs/tutorial.html FAQ: http://git.or.cz/gitwiki/GitFaq +When you use "git annotate" or "git blame" with gnulib, it's recommended that +you use the "-w" option, in order to ignore massive whitespace changes that +happened in 2009. + CVS checkouts are also supported: $ cvs -d :pserver:anonymous@pserver.git.sv.gnu.org:/gnulib.git co -d gnulib HEAD @@ -110,6 +114,50 @@ available under LGPL via a "License: LGPL" information in the projects' modules/ file. +Indent with spaces, not TABs +---------------------------- +We use space-only indentation in nearly all files. This includes all +*.h, *.c, *.y files, except for the regex module. Makefile and ChangeLog +files are excluded, since TAB characters are part of their format. + +In order to tell your editor to produce space-only indentation, you +can use these instructions. + + * For Emacs: Add these lines to your Emacs initialization file + ($HOME/.emacs or similar): + + ;; In gnulib, indent with spaces everywhere (not TABs). + ;; Exceptions: Makefile and ChangeLog modes. + (add-hook 'find-file-hook '(lambda () + (if (and buffer-file-name + (string-match "/gnulib\\>" (buffer-file-name)) + (not (string-equal mode-name "Change Log")) + (not (string-equal mode-name "Makefile"))) + (setq indent-tabs-mode nil)))) + + * For vi (vim): Add these lines to your $HOME/.vimrc file: + + " Don't use tabs for indentation. Spaces are nicer to work with. + set expandtab + + For Makefile and ChangeLog files, compensate this by adding this to + your $HOME/.vim/after/indent/make.vim and + $HOME/.vim/after/indent/changelog.vim files: + + " Use tabs for indentation, regardless of the global setting. + set noexpandtab + + * For Eclipse: In the "Window|Preferences" dialog (or "Eclipse|Preferences" + dialog on MacOS), + 1. Under "General|Editors|Text Editors", select the "Insert spaces for tabs" + checkbox. + 2. Under "C/C++|Code Style", select a code style profile that has the + "Indentation|Tab policy" combobox set to "Spaces only", such as the + "GNU [built-in]" policy. + +If you use the GNU indent program, pass it the option '--no-tabs'. + + How to add a new module ----------------------- * Add the header files and source files to lib/. diff --git a/build-aux/link-warning.h b/build-aux/link-warning.h index 9ff7c175a..d7f117c76 100644 --- a/build-aux/link-warning.h +++ b/build-aux/link-warning.h @@ -32,12 +32,12 @@ # define GL_LINK_WARNING2(file, line, message) \ GL_LINK_WARNING3 (file ":" #line ": warning: " message) # define GL_LINK_WARNING3(message) \ - ({ static const char warning[sizeof (message)] \ - __attribute__ ((__unused__, \ - __section__ (".gnu.warning"), \ - __aligned__ (1))) \ - = message "\n"; \ - (void)0; \ + ({ static const char warning[sizeof (message)] \ + __attribute__ ((__unused__, \ + __section__ (".gnu.warning"), \ + __aligned__ (1))) \ + = message "\n"; \ + (void)0; \ }) # else # define GL_LINK_WARNING(message) ((void) 0) diff --git a/lib/accept4.c b/lib/accept4.c index fbcb609b8..14b13bdc3 100644 --- a/lib/accept4.c +++ b/lib/accept4.c @@ -42,13 +42,13 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) static int have_accept4_really; /* 0 = unknown, 1 = yes, -1 = no */ if (have_accept4_really >= 0) { - int result = accept4 (sockfd, addr, addrlen, flags); - if (!(result < 0 && errno == ENOSYS)) - { - have_accept4_really = 1; - return result; - } - have_accept4_really = -1; + int result = accept4 (sockfd, addr, addrlen, flags); + if (!(result < 0 && errno == ENOSYS)) + { + have_accept4_really = 1; + return result; + } + have_accept4_really = -1; } } #endif @@ -74,29 +74,29 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) HANDLE new_handle; int nfd; - if (!DuplicateHandle (curr_process, /* SourceProcessHandle */ - old_handle, /* SourceHandle */ - curr_process, /* TargetProcessHandle */ - (PHANDLE) &new_handle, /* TargetHandle */ - (DWORD) 0, /* DesiredAccess */ - FALSE, /* InheritHandle */ - DUPLICATE_SAME_ACCESS)) /* Options */ - { - close (fd); - errno = EBADF; /* arbitrary */ - return -1; - } + if (!DuplicateHandle (curr_process, /* SourceProcessHandle */ + old_handle, /* SourceHandle */ + curr_process, /* TargetProcessHandle */ + (PHANDLE) &new_handle, /* TargetHandle */ + (DWORD) 0, /* DesiredAccess */ + FALSE, /* InheritHandle */ + DUPLICATE_SAME_ACCESS)) /* Options */ + { + close (fd); + errno = EBADF; /* arbitrary */ + return -1; + } /* Closing fd before allocating the new fd ensures that the new fd will - have the minimum possible value. */ + have the minimum possible value. */ close (fd); nfd = _open_osfhandle ((long) new_handle, - O_NOINHERIT | (flags & (O_TEXT | O_BINARY))); + O_NOINHERIT | (flags & (O_TEXT | O_BINARY))); if (nfd < 0) - { - CloseHandle (new_handle); - return -1; - } + { + CloseHandle (new_handle); + return -1; + } return nfd; } # else @@ -106,13 +106,13 @@ accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) int fcntl_flags; if ((fcntl_flags = fcntl (fd, F_GETFD, 0)) < 0 - || fcntl (fd, F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) - { - int saved_errno = errno; - close (fd); - errno = saved_errno; - return -1; - } + || fcntl (fd, F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) + { + int saved_errno = errno; + close (fd); + errno = saved_errno; + return -1; + } } # endif #endif diff --git a/lib/acl_entries.c b/lib/acl_entries.c index 12e85e565..fea83c3e3 100644 --- a/lib/acl_entries.c +++ b/lib/acl_entries.c @@ -37,26 +37,26 @@ acl_entries (acl_t acl) #if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD, MacOS X */ # if HAVE_ACL_TYPE_EXTENDED /* MacOS X */ /* acl_get_entry returns 0 when it successfully fetches an entry, - and -1/EINVAL at the end. */ + and -1/EINVAL at the end. */ acl_entry_t ace; int got_one; for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace); - got_one >= 0; - got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) - count++; + got_one >= 0; + got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) + count++; # else /* Linux, FreeBSD */ /* acl_get_entry returns 1 when it successfully fetches an entry, - and 0 at the end. */ + and 0 at the end. */ acl_entry_t ace; int got_one; for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace); - got_one > 0; - got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) - count++; + got_one > 0; + got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace)) + count++; if (got_one < 0) - return -1; + return -1; # endif #else /* IRIX, Tru64 */ # if HAVE_ACL_TO_SHORT_TEXT /* IRIX */ @@ -65,7 +65,7 @@ acl_entries (acl_t acl) # endif # if HAVE_ACL_FREE_TEXT /* Tru64 */ /* Don't use acl_get_entry: it takes only one argument and does not - work. */ + work. */ count = acl->acl_num; # endif #endif diff --git a/lib/acosl.c b/lib/acosl.c index 122fb9ccb..109104ac7 100644 --- a/lib/acosl.c +++ b/lib/acosl.c @@ -21,17 +21,17 @@ /* asin(x) * Method : - * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... - * we approximate asin(x) on [0,0.5] by - * asin(x) = x + x*x^2*R(x^2) + * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... + * we approximate asin(x) on [0,0.5] by + * asin(x) = x + x*x^2*R(x^2) * Between .5 and .625 the approximation is * asin(0.5625 + x) = asin(0.5625) + x rS(x) / sS(x) - * For x in [0.625,1] - * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) + * For x in [0.625,1] + * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) * * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. * */ @@ -44,7 +44,7 @@ static const long double pio2_lo = 4.3359050650618905123985220130216759843812E-35L, pio4_hi = 7.8539816339744830961566084581987569936977E-1L, - /* coefficient for R(x^2) */ + /* coefficient for R(x^2) */ /* asin(x) = x + x^3 pS(x^2) / qS(x^2) 0 <= x <= 0.5 @@ -113,19 +113,19 @@ acosl (long double x) return t; } - if (x >= 1.0L) /* |x|>= 1 */ + if (x >= 1.0L) /* |x|>= 1 */ { if (x == 1.0L) - return 0.0L; /* return zero */ + return 0.0L; /* return zero */ - return (x - x) / (x - x); /* asin(|x|>1) is NaN */ + return (x - x) / (x - x); /* asin(|x|>1) is NaN */ } else if (x < 0.5L) /* |x| < 0.5 */ { if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2**-57 */ - /* acos(0)=+-pi/2 with inexact */ - return x * pio2_hi + x * pio2_lo; + /* acos(0)=+-pi/2 with inexact */ + return x * pio2_hi + x * pio2_lo; t = x * x; p = (((((((((pS9 * t @@ -157,28 +157,28 @@ acosl (long double x) { t = x - 0.5625; p = ((((((((((rS10 * t - + rS9) * t - + rS8) * t - + rS7) * t - + rS6) * t - + rS5) * t - + rS4) * t - + rS3) * t - + rS2) * t - + rS1) * t - + rS0) * t; + + rS9) * t + + rS8) * t + + rS7) * t + + rS6) * t + + rS5) * t + + rS4) * t + + rS3) * t + + rS2) * t + + rS1) * t + + rS0) * t; q = ((((((((( t - + sS9) * t - + sS8) * t - + sS7) * t - + sS6) * t - + sS5) * t - + sS4) * t - + sS3) * t - + sS2) * t - + sS1) * t - + sS0; + + sS9) * t + + sS8) * t + + sS7) * t + + sS6) * t + + sS5) * t + + sS4) * t + + sS3) * t + + sS2) * t + + sS1) * t + + sS0; return (pio2_hi - asinr5625) - (p / q - pio2_lo); } diff --git a/lib/alloca.c b/lib/alloca.c index 3a1f4e273..b652765fd 100644 --- a/lib/alloca.c +++ b/lib/alloca.c @@ -81,37 +81,37 @@ long i00afunc (); STACK_DIRECTION = 0 => direction of growth unknown */ # ifndef STACK_DIRECTION -# define STACK_DIRECTION 0 /* Direction unknown. */ +# define STACK_DIRECTION 0 /* Direction unknown. */ # endif # if STACK_DIRECTION != 0 -# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ +# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ # else /* STACK_DIRECTION == 0; need run-time code. */ -static int stack_dir; /* 1 or -1 once known. */ -# define STACK_DIR stack_dir +static int stack_dir; /* 1 or -1 once known. */ +# define STACK_DIR stack_dir static void find_stack_direction (void) { - static char *addr = NULL; /* Address of first `dummy', once known. */ - auto char dummy; /* To get stack address. */ + static char *addr = NULL; /* Address of first `dummy', once known. */ + auto char dummy; /* To get stack address. */ if (addr == NULL) - { /* Initial entry. */ + { /* Initial entry. */ addr = ADDRESS_FUNCTION (dummy); - find_stack_direction (); /* Recurse once. */ + find_stack_direction (); /* Recurse once. */ } else { /* Second entry. */ if (ADDRESS_FUNCTION (dummy) > addr) - stack_dir = 1; /* Stack grew upward. */ + stack_dir = 1; /* Stack grew upward. */ else - stack_dir = -1; /* Stack grew downward. */ + stack_dir = -1; /* Stack grew downward. */ } } @@ -124,21 +124,21 @@ find_stack_direction (void) It is very important that sizeof(header) agree with malloc alignment chunk size. The following default should work okay. */ -# ifndef ALIGN_SIZE -# define ALIGN_SIZE sizeof(double) +# ifndef ALIGN_SIZE +# define ALIGN_SIZE sizeof(double) # endif typedef union hdr { - char align[ALIGN_SIZE]; /* To force sizeof(header). */ + char align[ALIGN_SIZE]; /* To force sizeof(header). */ struct { - union hdr *next; /* For chaining headers. */ - char *deep; /* For stack depth measure. */ + union hdr *next; /* For chaining headers. */ + char *deep; /* For stack depth measure. */ } h; } header; -static header *last_alloca_header = NULL; /* -> last alloca header. */ +static header *last_alloca_header = NULL; /* -> last alloca header. */ /* Return a pointer to at least SIZE bytes of storage, which will be automatically reclaimed upon exit from @@ -150,11 +150,11 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */ void * alloca (size_t size) { - auto char probe; /* Probes stack depth: */ + auto char probe; /* Probes stack depth: */ register char *depth = ADDRESS_FUNCTION (probe); # if STACK_DIRECTION == 0 - if (STACK_DIR == 0) /* Unknown growth direction. */ + if (STACK_DIR == 0) /* Unknown growth direction. */ find_stack_direction (); # endif @@ -162,7 +162,7 @@ alloca (size_t size) was allocated from deeper in the stack than currently. */ { - register header *hp; /* Traverses linked list. */ + register header *hp; /* Traverses linked list. */ # ifdef emacs BLOCK_INPUT; @@ -170,18 +170,18 @@ alloca (size_t size) for (hp = last_alloca_header; hp != NULL;) if ((STACK_DIR > 0 && hp->h.deep > depth) - || (STACK_DIR < 0 && hp->h.deep < depth)) - { - register header *np = hp->h.next; + || (STACK_DIR < 0 && hp->h.deep < depth)) + { + register header *np = hp->h.next; - free (hp); /* Collect garbage. */ + free (hp); /* Collect garbage. */ - hp = np; /* -> next header. */ - } + hp = np; /* -> next header. */ + } else - break; /* Rest are not deeper. */ + break; /* Rest are not deeper. */ - last_alloca_header = hp; /* -> last valid storage. */ + last_alloca_header = hp; /* -> last valid storage. */ # ifdef emacs UNBLOCK_INPUT; @@ -189,7 +189,7 @@ alloca (size_t size) } if (size == 0) - return NULL; /* No allocation required. */ + return NULL; /* No allocation required. */ /* Allocate combined header + user data storage. */ @@ -229,10 +229,10 @@ alloca (size_t size) /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ struct stack_control_header { - long shgrow:32; /* Number of times stack has grown. */ - long shaseg:32; /* Size of increments to stack. */ - long shhwm:32; /* High water mark of stack. */ - long shsize:32; /* Current size of stack (all segments). */ + long shgrow:32; /* Number of times stack has grown. */ + long shaseg:32; /* Size of increments to stack. */ + long shhwm:32; /* High water mark of stack. */ + long shsize:32; /* Current size of stack (all segments). */ }; /* The stack segment linkage control information occurs at @@ -244,21 +244,21 @@ struct stack_control_header struct stack_segment_linkage { - long ss[0200]; /* 0200 overflow words. */ - long sssize:32; /* Number of words in this segment. */ - long ssbase:32; /* Offset to stack base. */ + long ss[0200]; /* 0200 overflow words. */ + long sssize:32; /* Number of words in this segment. */ + long ssbase:32; /* Offset to stack base. */ long:32; - long sspseg:32; /* Offset to linkage control of previous - segment of stack. */ + long sspseg:32; /* Offset to linkage control of previous + segment of stack. */ long:32; - long sstcpt:32; /* Pointer to task common address block. */ - long sscsnm; /* Private control structure number for - microtasking. */ - long ssusr1; /* Reserved for user. */ - long ssusr2; /* Reserved for user. */ - long sstpid; /* Process ID for pid based multi-tasking. */ - long ssgvup; /* Pointer to multitasking thread giveup. */ - long sscray[7]; /* Reserved for Cray Research. */ + long sstcpt:32; /* Pointer to task common address block. */ + long sscsnm; /* Private control structure number for + microtasking. */ + long ssusr1; /* Reserved for user. */ + long ssusr2; /* Reserved for user. */ + long sstpid; /* Process ID for pid based multi-tasking. */ + long ssgvup; /* Pointer to multitasking thread giveup. */ + long sscray[7]; /* Reserved for Cray Research. */ long ssa0; long ssa1; long ssa2; @@ -282,27 +282,27 @@ struct stack_segment_linkage returned by the STKSTAT library routine. */ struct stk_stat { - long now; /* Current total stack size. */ - long maxc; /* Amount of contiguous space which would - be required to satisfy the maximum - stack demand to date. */ - long high_water; /* Stack high-water mark. */ - long overflows; /* Number of stack overflow ($STKOFEN) calls. */ - long hits; /* Number of internal buffer hits. */ - long extends; /* Number of block extensions. */ - long stko_mallocs; /* Block allocations by $STKOFEN. */ - long underflows; /* Number of stack underflow calls ($STKRETN). */ - long stko_free; /* Number of deallocations by $STKRETN. */ - long stkm_free; /* Number of deallocations by $STKMRET. */ - long segments; /* Current number of stack segments. */ - long maxs; /* Maximum number of stack segments so far. */ - long pad_size; /* Stack pad size. */ - long current_address; /* Current stack segment address. */ - long current_size; /* Current stack segment size. This - number is actually corrupted by STKSTAT to - include the fifteen word trailer area. */ - long initial_address; /* Address of initial segment. */ - long initial_size; /* Size of initial segment. */ + long now; /* Current total stack size. */ + long maxc; /* Amount of contiguous space which would + be required to satisfy the maximum + stack demand to date. */ + long high_water; /* Stack high-water mark. */ + long overflows; /* Number of stack overflow ($STKOFEN) calls. */ + long hits; /* Number of internal buffer hits. */ + long extends; /* Number of block extensions. */ + long stko_mallocs; /* Block allocations by $STKOFEN. */ + long underflows; /* Number of stack underflow calls ($STKRETN). */ + long stko_free; /* Number of deallocations by $STKRETN. */ + long stkm_free; /* Number of deallocations by $STKMRET. */ + long segments; /* Current number of stack segments. */ + long maxs; /* Maximum number of stack segments so far. */ + long pad_size; /* Stack pad size. */ + long current_address; /* Current stack segment address. */ + long current_size; /* Current stack segment size. This + number is actually corrupted by STKSTAT to + include the fifteen word trailer area. */ + long initial_address; /* Address of initial segment. */ + long initial_size; /* Size of initial segment. */ }; /* The following structure describes the data structure which trails @@ -311,13 +311,13 @@ struct stk_stat struct stk_trailer { - long this_address; /* Address of this block. */ - long this_size; /* Size of this block (does not include - this trailer). */ + long this_address; /* Address of this block. */ + long this_size; /* Size of this block (does not include + this trailer). */ long unknown2; long unknown3; - long link; /* Address of trailer block of previous - segment. */ + long link; /* Address of trailer block of previous + segment. */ long unknown5; long unknown6; long unknown7; @@ -355,8 +355,8 @@ i00afunc (long *address) /* Set up the iteration. */ trailer = (struct stk_trailer *) (status.current_address - + status.current_size - - 15); + + status.current_size + - 15); /* There must be at least one stack segment. Therefore it is a fatal error if "trailer" is null. */ @@ -371,10 +371,10 @@ i00afunc (long *address) block = (long *) trailer->this_address; size = trailer->this_size; if (block == 0 || size == 0) - abort (); + abort (); trailer = (struct stk_trailer *) trailer->link; if ((block <= address) && (address < (block + size))) - break; + break; } /* Set the result to the offset in this segment and add the sizes @@ -390,7 +390,7 @@ i00afunc (long *address) do { if (trailer->this_size <= 0) - abort (); + abort (); result += trailer->this_size; trailer = (struct stk_trailer *) trailer->link; } @@ -453,7 +453,7 @@ i00afunc (long address) fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); # endif if (pseg == 0) - break; + break; stkl = stkl - pseg; ssptr = (struct stack_segment_linkage *) stkl; size = ssptr->sssize; diff --git a/lib/arcfour.c b/lib/arcfour.c index 95f8204f4..acd5f8a42 100644 --- a/lib/arcfour.c +++ b/lib/arcfour.c @@ -33,7 +33,7 @@ void arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf, - size_t length) + size_t length) { uint8_t i = context->idx_i; uint8_t j = context->idx_j; @@ -49,7 +49,7 @@ arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf, sbox[i] = sbox[j]; sbox[j] = t; *outbuf++ = (*inbuf++ - ^ sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]); + ^ sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]); } context->idx_i = i; @@ -73,6 +73,6 @@ arcfour_setkey (arcfour_context * context, const char *key, size_t keylen) sbox[i] = sbox[j]; sbox[j] = t; if (++k == keylen) - k = 0; + k = 0; } } diff --git a/lib/arcfour.h b/lib/arcfour.h index 0a9d75c0f..eaceb64e2 100644 --- a/lib/arcfour.h +++ b/lib/arcfour.h @@ -40,7 +40,7 @@ typedef struct before this function is called. */ extern void arcfour_stream (arcfour_context * context, - const char *inbuf, char *outbuf, size_t length); + const char *inbuf, char *outbuf, size_t length); /* Initialize CONTEXT using encryption KEY of KEYLEN bytes. KEY should be 40 bits (5 bytes) or longer. The KEY cannot be zero diff --git a/lib/arctwo.c b/lib/arctwo.c index baf3c615e..6c0f4e4c1 100644 --- a/lib/arctwo.c +++ b/lib/arctwo.c @@ -77,10 +77,10 @@ to_uchar (char ch) void arctwo_encrypt (arctwo_context *context, const char *inbuf, - char *outbuf, size_t length) + char *outbuf, size_t length) { for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE, - inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE) + inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE) { size_t i, j; uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0; @@ -95,29 +95,29 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf, word3 = (word3 << 8) | to_uchar (inbuf[6]); for (i = 0; i < 16; i++) - { - j = i * 4; - /* For some reason I cannot combine those steps. */ - word0 += (word1 & ~word3) + (word2 & word3) + context->S[j]; - word0 = rotl16 (word0, 1); - - word1 += (word2 & ~word0) + (word3 & word0) + context->S[j + 1]; - word1 = rotl16 (word1, 2); - - word2 += (word3 & ~word1) + (word0 & word1) + context->S[j + 2]; - word2 = rotl16 (word2, 3); - - word3 += (word0 & ~word2) + (word1 & word2) + context->S[j + 3]; - word3 = rotl16 (word3, 5); - - if (i == 4 || i == 10) - { - word0 += context->S[word3 & 63]; - word1 += context->S[word0 & 63]; - word2 += context->S[word1 & 63]; - word3 += context->S[word2 & 63]; - } - } + { + j = i * 4; + /* For some reason I cannot combine those steps. */ + word0 += (word1 & ~word3) + (word2 & word3) + context->S[j]; + word0 = rotl16 (word0, 1); + + word1 += (word2 & ~word0) + (word3 & word0) + context->S[j + 1]; + word1 = rotl16 (word1, 2); + + word2 += (word3 & ~word1) + (word0 & word1) + context->S[j + 2]; + word2 = rotl16 (word2, 3); + + word3 += (word0 & ~word2) + (word1 & word2) + context->S[j + 3]; + word3 = rotl16 (word3, 5); + + if (i == 4 || i == 10) + { + word0 += context->S[word3 & 63]; + word1 += context->S[word0 & 63]; + word2 += context->S[word1 & 63]; + word3 += context->S[word2 & 63]; + } + } outbuf[0] = word0 & 255; outbuf[1] = word0 >> 8; @@ -132,10 +132,10 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf, void arctwo_decrypt (arctwo_context *context, const char *inbuf, - char *outbuf, size_t length) + char *outbuf, size_t length) { for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE, - inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE) + inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE) { size_t i, j; uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0; @@ -150,29 +150,29 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf, word3 = (word3 << 8) | to_uchar (inbuf[6]); for (i = 16; i > 0; i--) - { - j = (i - 1) * 4; + { + j = (i - 1) * 4; - word3 = rotr16 (word3, 5); - word3 -= (word0 & ~word2) + (word1 & word2) + context->S[j + 3]; + word3 = rotr16 (word3, 5); + word3 -= (word0 & ~word2) + (word1 & word2) + context->S[j + 3]; - word2 = rotr16 (word2, 3); - word2 -= (word3 & ~word1) + (word0 & word1) + context->S[j + 2]; + word2 = rotr16 (word2, 3); + word2 -= (word3 & ~word1) + (word0 & word1) + context->S[j + 2]; - word1 = rotr16 (word1, 2); - word1 -= (word2 & ~word0) + (word3 & word0) + context->S[j + 1]; + word1 = rotr16 (word1, 2); + word1 -= (word2 & ~word0) + (word3 & word0) + context->S[j + 1]; - word0 = rotr16 (word0, 1); - word0 -= (word1 & ~word3) + (word2 & word3) + context->S[j]; + word0 = rotr16 (word0, 1); + word0 -= (word1 & ~word3) + (word2 & word3) + context->S[j]; - if (i == 6 || i == 12) - { - word3 = word3 - context->S[word2 & 63]; - word2 = word2 - context->S[word1 & 63]; - word1 = word1 - context->S[word0 & 63]; - word0 = word0 - context->S[word3 & 63]; - } - } + if (i == 6 || i == 12) + { + word3 = word3 - context->S[word2 & 63]; + word2 = word2 - context->S[word1 & 63]; + word1 = word1 - context->S[word0 & 63]; + word0 = word0 - context->S[word3 & 63]; + } + } outbuf[0] = word0 & 255; outbuf[1] = word0 >> 8; @@ -187,7 +187,7 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf, void arctwo_setkey_ekb (arctwo_context *context, - size_t keylen, const char *key, size_t effective_keylen) + size_t keylen, const char *key, size_t effective_keylen) { size_t i; uint8_t *S, x; @@ -216,10 +216,10 @@ arctwo_setkey_ekb (arctwo_context *context, S[i] = x; while (i--) - { - x = arctwo_sbox[x ^ S[i + len]]; - S[i] = x; - } + { + x = arctwo_sbox[x ^ S[i + len]]; + S[i] = x; + } } /* Make the expanded key, endian independent. */ diff --git a/lib/arctwo.h b/lib/arctwo.h index 89c581e20..87cf3fbc4 100644 --- a/lib/arctwo.h +++ b/lib/arctwo.h @@ -39,7 +39,7 @@ typedef struct EFFECTIVE_KEYLEN of 0, but see RFC 2268 for more information. */ void arctwo_setkey_ekb (arctwo_context *context, - size_t keylen, const char *key, size_t effective_keylen); + size_t keylen, const char *key, size_t effective_keylen); #define arctwo_setkey(context,keylen,key) \ arctwo_setkey_ekb (context, keylen, key, 8 * (keylen)) @@ -50,7 +50,7 @@ arctwo_setkey_ekb (arctwo_context *context, arctwo_setkey_ekb. */ extern void arctwo_encrypt (arctwo_context *context, const char *inbuf, - char *outbuf, size_t length); + char *outbuf, size_t length); /* Decrypt INBUF of size LENGTH into OUTBUF. LENGTH must be a multiple of ARCTWO_BLOCK_SIZE. CONTEXT hold the decryption key, @@ -58,6 +58,6 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf, arctwo_setkey_ekb. */ extern void arctwo_decrypt (arctwo_context *context, const char *inbuf, - char *outbuf, size_t length); + char *outbuf, size_t length); #endif /* ARCTWO_H */ diff --git a/lib/areadlink-with-size.c b/lib/areadlink-with-size.c index 625ddb795..d39c56bcd 100644 --- a/lib/areadlink-with-size.c +++ b/lib/areadlink-with-size.c @@ -57,8 +57,8 @@ areadlink_with_size (char const *file, size_t size) size_t symlink_max = SYMLINK_MAX; size_t INITIAL_LIMIT_BOUND = 8 * 1024; size_t initial_limit = (symlink_max < INITIAL_LIMIT_BOUND - ? symlink_max + 1 - : INITIAL_LIMIT_BOUND); + ? symlink_max + 1 + : INITIAL_LIMIT_BOUND); /* The initial buffer size for the link value. */ size_t buf_size = size < initial_limit ? size + 1 : initial_limit; @@ -70,35 +70,35 @@ areadlink_with_size (char const *file, size_t size) char *buffer = malloc (buf_size); if (buffer == NULL) - return NULL; + return NULL; r = readlink (file, buffer, buf_size); link_length = r; /* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1 - with errno == ERANGE if the buffer is too small. */ + with errno == ERANGE if the buffer is too small. */ if (r < 0 && errno != ERANGE) - { - int saved_errno = errno; - free (buffer); - errno = saved_errno; - return NULL; - } + { + int saved_errno = errno; + free (buffer); + errno = saved_errno; + return NULL; + } if (link_length < buf_size) - { - buffer[link_length] = 0; - return buffer; - } + { + buffer[link_length] = 0; + return buffer; + } free (buffer); if (buf_size <= MAXSIZE / 2) - buf_size *= 2; + buf_size *= 2; else if (buf_size < MAXSIZE) - buf_size = MAXSIZE; + buf_size = MAXSIZE; else - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } } } diff --git a/lib/areadlink.c b/lib/areadlink.c index f6871c572..b506eb8bc 100644 --- a/lib/areadlink.c +++ b/lib/areadlink.c @@ -64,56 +64,56 @@ areadlink (char const *filename) ssize_t link_length = readlink (filename, buffer, buf_size); /* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1 - with errno == ERANGE if the buffer is too small. */ + with errno == ERANGE if the buffer is too small. */ if (link_length < 0 && errno != ERANGE) - { - if (buffer != initial_buf) - { - int saved_errno = errno; - free (buffer); - errno = saved_errno; - } - return NULL; - } + { + if (buffer != initial_buf) + { + int saved_errno = errno; + free (buffer); + errno = saved_errno; + } + return NULL; + } if ((size_t) link_length < buf_size) - { - buffer[link_length++] = '\0'; - - /* Return it in a chunk of memory as small as possible. */ - if (buffer == initial_buf) - { - buffer = (char *) malloc (link_length); - if (buffer == NULL) - /* errno is ENOMEM. */ - return NULL; - memcpy (buffer, initial_buf, link_length); - } - else - { - /* Shrink buffer before returning it. */ - if ((size_t) link_length < buf_size) - { - char *smaller_buffer = (char *) realloc (buffer, link_length); - - if (smaller_buffer != NULL) - buffer = smaller_buffer; - } - } - return buffer; - } + { + buffer[link_length++] = '\0'; + + /* Return it in a chunk of memory as small as possible. */ + if (buffer == initial_buf) + { + buffer = (char *) malloc (link_length); + if (buffer == NULL) + /* errno is ENOMEM. */ + return NULL; + memcpy (buffer, initial_buf, link_length); + } + else + { + /* Shrink buffer before returning it. */ + if ((size_t) link_length < buf_size) + { + char *smaller_buffer = (char *) realloc (buffer, link_length); + + if (smaller_buffer != NULL) + buffer = smaller_buffer; + } + } + return buffer; + } if (buffer != initial_buf) - free (buffer); + free (buffer); buf_size *= 2; if (SSIZE_MAX < buf_size || (SIZE_MAX / 2 < SSIZE_MAX && buf_size == 0)) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } buffer = (char *) malloc (buf_size); if (buffer == NULL) - /* errno is ENOMEM. */ - return NULL; + /* errno is ENOMEM. */ + return NULL; } } diff --git a/lib/argmatch.c b/lib/argmatch.c index 925449bfd..e255abb5a 100644 --- a/lib/argmatch.c +++ b/lib/argmatch.c @@ -81,12 +81,12 @@ argmatch_exit_fn argmatch_die = __argmatch_die; ptrdiff_t argmatch (const char *arg, const char *const *arglist, - const char *vallist, size_t valsize) + 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). */ + 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); @@ -94,26 +94,26 @@ argmatch (const char *arg, const char *const *arglist, 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 (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; @@ -130,11 +130,11 @@ 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")); + ? _("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)); + quote_n (1, context)); } /* List the valid arguments for argmatch. @@ -143,7 +143,7 @@ argmatch_invalid (const char *context, const char *value, ptrdiff_t problem) VALSIZE is the size of the elements of VALLIST */ void argmatch_valid (const char *const *arglist, - const char *vallist, size_t valsize) + const char *vallist, size_t valsize) { size_t i; const char *last_val = NULL; @@ -153,14 +153,14 @@ argmatch_valid (const char *const *arglist, fprintf (stderr, _("Valid arguments are:")); for (i = 0; arglist[i]; i++) if ((i == 0) - || memcmp (last_val, vallist + valsize * i, valsize)) + || memcmp (last_val, vallist + valsize * i, valsize)) { - fprintf (stderr, "\n - `%s'", arglist[i]); - last_val = vallist + valsize * i; + fprintf (stderr, "\n - `%s'", arglist[i]); + last_val = vallist + valsize * i; } else { - fprintf (stderr, ", `%s'", arglist[i]); + fprintf (stderr, ", `%s'", arglist[i]); } putc ('\n', stderr); } @@ -173,9 +173,9 @@ argmatch_valid (const char *const *arglist, 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) + 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) @@ -194,8 +194,8 @@ __xargmatch_internal (const char *context, 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) + const char *const *arglist, + const char *vallist, size_t valsize) { size_t i; @@ -263,14 +263,14 @@ main (int argc, const char *const *argv) if ((cp = getenv ("VERSION_CONTROL"))) backup_type = XARGMATCH ("$VERSION_CONTROL", cp, - backup_args, backup_vals); + backup_args, backup_vals); if (argc == 2) backup_type = XARGMATCH (program_name, argv[1], - backup_args, backup_vals); + backup_args, backup_vals); printf ("The version control is `%s'\n", - ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals)); + ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals)); return 0; } diff --git a/lib/argmatch.h b/lib/argmatch.h index cc403145a..4972abe95 100644 --- a/lib/argmatch.h +++ b/lib/argmatch.h @@ -40,7 +40,7 @@ to the same values in VALLIST). */ ptrdiff_t argmatch (char const *arg, char const *const *arglist, - char const *vallist, size_t valsize); + char const *vallist, size_t valsize); # define ARGMATCH(Arg, Arglist, Vallist) \ argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist)) @@ -54,7 +54,7 @@ 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); + ptrdiff_t problem); /* Left for compatibility with the old name invalid_arg */ @@ -66,7 +66,7 @@ void argmatch_invalid (char const *context, char const *value, /* Report on stderr the list of possible arguments. */ void argmatch_valid (char const *const *arglist, - char const *vallist, size_t valsize); + char const *vallist, size_t valsize); # define ARGMATCH_VALID(Arglist, Vallist) \ argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist)) @@ -77,26 +77,26 @@ void argmatch_valid (char const *const *arglist, failure, and exits 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); + 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)]) +# 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); + char const *const *arglist, + char const *vallist, size_t valsize); -# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \ - argmatch_to_argument (Value, Arglist, \ - (char const *) (Vallist), sizeof *(Vallist)) +# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \ + argmatch_to_argument (Value, Arglist, \ + (char const *) (Vallist), sizeof *(Vallist)) #endif /* ARGMATCH_H_ */ diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c index 7e6d9c698..6cdbf6ba7 100644 --- a/lib/argp-fmtstream.c +++ b/lib/argp-fmtstream.c @@ -55,7 +55,7 @@ Returns NULL if there was an error. */ argp_fmtstream_t __argp_make_fmtstream (FILE *stream, - size_t lmargin, size_t rmargin, ssize_t wmargin) + size_t lmargin, size_t rmargin, ssize_t wmargin) { argp_fmtstream_t fs; @@ -72,15 +72,15 @@ __argp_make_fmtstream (FILE *stream, fs->buf = (char *) malloc (INIT_BUF_SIZE); if (! fs->buf) - { - free (fs); - fs = 0; - } + { + free (fs); + fs = 0; + } else - { - fs->p = fs->buf; - fs->end = fs->buf + INIT_BUF_SIZE; - } + { + fs->p = fs->buf; + fs->end = fs->buf + INIT_BUF_SIZE; + } } return fs; @@ -130,214 +130,214 @@ __argp_fmtstream_update (argp_fmtstream_t fs) size_t r; if (fs->point_col == 0 && fs->lmargin != 0) - { - /* We are starting a new line. Print spaces to the left margin. */ - const size_t pad = fs->lmargin; - if (fs->p + pad < fs->end) - { - /* We can fit in them in the buffer by moving the - buffer text up and filling in the beginning. */ - memmove (buf + pad, buf, fs->p - buf); - fs->p += pad; /* Compensate for bigger buffer. */ - memset (buf, ' ', pad); /* Fill in the spaces. */ - buf += pad; /* Don't bother searching them. */ - } - else - { - /* No buffer space for spaces. Must flush. */ - size_t i; - for (i = 0; i < pad; i++) - { + { + /* We are starting a new line. Print spaces to the left margin. */ + const size_t pad = fs->lmargin; + if (fs->p + pad < fs->end) + { + /* We can fit in them in the buffer by moving the + buffer text up and filling in the beginning. */ + memmove (buf + pad, buf, fs->p - buf); + fs->p += pad; /* Compensate for bigger buffer. */ + memset (buf, ' ', pad); /* Fill in the spaces. */ + buf += pad; /* Don't bother searching them. */ + } + else + { + /* No buffer space for spaces. Must flush. */ + size_t i; + for (i = 0; i < pad; i++) + { #ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - putwc_unlocked (L' ', fs->stream); - else + if (_IO_fwide (fs->stream, 0) > 0) + putwc_unlocked (L' ', fs->stream); + else #endif - putc_unlocked (' ', fs->stream); - } - } - fs->point_col = pad; - } + putc_unlocked (' ', fs->stream); + } + } + fs->point_col = pad; + } len = fs->p - buf; nl = memchr (buf, '\n', len); if (fs->point_col < 0) - fs->point_col = 0; + fs->point_col = 0; if (!nl) - { - /* The buffer ends in a partial line. */ - - if (fs->point_col + len < fs->rmargin) - { - /* The remaining buffer text is a partial line and fits - within the maximum line width. Advance point for the - characters to be written and stop scanning. */ - fs->point_col += len; - break; - } - else - /* Set the end-of-line pointer for the code below to - the end of the buffer. */ - nl = fs->p; - } + { + /* The buffer ends in a partial line. */ + + if (fs->point_col + len < fs->rmargin) + { + /* The remaining buffer text is a partial line and fits + within the maximum line width. Advance point for the + characters to be written and stop scanning. */ + fs->point_col += len; + break; + } + else + /* Set the end-of-line pointer for the code below to + the end of the buffer. */ + nl = fs->p; + } else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin) - { - /* The buffer contains a full line that fits within the maximum - line width. Reset point and scan the next line. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } + { + /* The buffer contains a full line that fits within the maximum + line width. Reset point and scan the next line. */ + fs->point_col = 0; + buf = nl + 1; + continue; + } /* This line is too long. */ r = fs->rmargin - 1; if (fs->wmargin < 0) - { - /* Truncate the line by overwriting the excess with the - newline and anything after it in the buffer. */ - if (nl < fs->p) - { - memmove (buf + (r - fs->point_col), nl, fs->p - nl); - fs->p -= buf + (r - fs->point_col) - nl; - /* Reset point for the next line and start scanning it. */ - fs->point_col = 0; - buf += r + 1; /* Skip full line plus \n. */ - } - else - { - /* The buffer ends with a partial line that is beyond the - maximum line width. Advance point for the characters - written, and discard those past the max from the buffer. */ - fs->point_col += len; - fs->p -= fs->point_col - r; - break; - } - } + { + /* Truncate the line by overwriting the excess with the + newline and anything after it in the buffer. */ + if (nl < fs->p) + { + memmove (buf + (r - fs->point_col), nl, fs->p - nl); + fs->p -= buf + (r - fs->point_col) - nl; + /* Reset point for the next line and start scanning it. */ + fs->point_col = 0; + buf += r + 1; /* Skip full line plus \n. */ + } + else + { + /* The buffer ends with a partial line that is beyond the + maximum line width. Advance point for the characters + written, and discard those past the max from the buffer. */ + fs->point_col += len; + fs->p -= fs->point_col - r; + break; + } + } else - { - /* Do word wrap. Go to the column just past the maximum line - width and scan back for the beginning of the word there. - Then insert a line break. */ - - char *p, *nextline; - int i; - - p = buf + (r + 1 - fs->point_col); - while (p >= buf && !isblank ((unsigned char) *p)) - --p; - nextline = p + 1; /* This will begin the next line. */ - - if (nextline > buf) - { - /* Swallow separating blanks. */ - if (p >= buf) - do - --p; - while (p >= buf && isblank ((unsigned char) *p)); - nl = p + 1; /* The newline will replace the first blank. */ - } - else - { - /* A single word that is greater than the maximum line width. - Oh well. Put it on an overlong line by itself. */ - p = buf + (r + 1 - fs->point_col); - /* Find the end of the long word. */ - if (p < nl) - do - ++p; - while (p < nl && !isblank ((unsigned char) *p)); - if (p == nl) - { - /* It already ends a line. No fussing required. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } - /* We will move the newline to replace the first blank. */ - nl = p; - /* Swallow separating blanks. */ - do - ++p; - while (isblank ((unsigned char) *p)); - /* The next line will start here. */ - nextline = p; - } - - /* Note: There are a bunch of tests below for - NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall - at the end of the buffer, and NEXTLINE is in fact empty (and so - we need not be careful to maintain its contents). */ - - if ((nextline == buf + len + 1 - ? fs->end - nl < fs->wmargin + 1 - : nextline - (nl + 1) < fs->wmargin) - && fs->p > nextline) - { - /* The margin needs more blanks than we removed. */ - if (fs->end - fs->p > fs->wmargin + 1) - /* Make some space for them. */ - { - size_t mv = fs->p - nextline; - memmove (nl + 1 + fs->wmargin, nextline, mv); - nextline = nl + 1 + fs->wmargin; - len = nextline + mv - buf; - *nl++ = '\n'; - } - else - /* Output the first line so we can use the space. */ - { + { + /* Do word wrap. Go to the column just past the maximum line + width and scan back for the beginning of the word there. + Then insert a line break. */ + + char *p, *nextline; + int i; + + p = buf + (r + 1 - fs->point_col); + while (p >= buf && !isblank ((unsigned char) *p)) + --p; + nextline = p + 1; /* This will begin the next line. */ + + if (nextline > buf) + { + /* Swallow separating blanks. */ + if (p >= buf) + do + --p; + while (p >= buf && isblank ((unsigned char) *p)); + nl = p + 1; /* The newline will replace the first blank. */ + } + else + { + /* A single word that is greater than the maximum line width. + Oh well. Put it on an overlong line by itself. */ + p = buf + (r + 1 - fs->point_col); + /* Find the end of the long word. */ + if (p < nl) + do + ++p; + while (p < nl && !isblank ((unsigned char) *p)); + if (p == nl) + { + /* It already ends a line. No fussing required. */ + fs->point_col = 0; + buf = nl + 1; + continue; + } + /* We will move the newline to replace the first blank. */ + nl = p; + /* Swallow separating blanks. */ + do + ++p; + while (isblank ((unsigned char) *p)); + /* The next line will start here. */ + nextline = p; + } + + /* Note: There are a bunch of tests below for + NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall + at the end of the buffer, and NEXTLINE is in fact empty (and so + we need not be careful to maintain its contents). */ + + if ((nextline == buf + len + 1 + ? fs->end - nl < fs->wmargin + 1 + : nextline - (nl + 1) < fs->wmargin) + && fs->p > nextline) + { + /* The margin needs more blanks than we removed. */ + if (fs->end - fs->p > fs->wmargin + 1) + /* Make some space for them. */ + { + size_t mv = fs->p - nextline; + memmove (nl + 1 + fs->wmargin, nextline, mv); + nextline = nl + 1 + fs->wmargin; + len = nextline + mv - buf; + *nl++ = '\n'; + } + else + /* Output the first line so we can use the space. */ + { #ifdef _LIBC - __fxprintf (fs->stream, "%.*s\n", - (int) (nl - fs->buf), fs->buf); + __fxprintf (fs->stream, "%.*s\n", + (int) (nl - fs->buf), fs->buf); #else - if (nl > fs->buf) - fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); - putc_unlocked ('\n', fs->stream); + if (nl > fs->buf) + fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); + putc_unlocked ('\n', fs->stream); #endif - len += buf - fs->buf; - nl = buf = fs->buf; - } - } - else - /* We can fit the newline and blanks in before - the next word. */ - *nl++ = '\n'; - - if (nextline - nl >= fs->wmargin - || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin)) - /* Add blanks up to the wrap margin column. */ - for (i = 0; i < fs->wmargin; ++i) - *nl++ = ' '; - else - for (i = 0; i < fs->wmargin; ++i) + len += buf - fs->buf; + nl = buf = fs->buf; + } + } + else + /* We can fit the newline and blanks in before + the next word. */ + *nl++ = '\n'; + + if (nextline - nl >= fs->wmargin + || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin)) + /* Add blanks up to the wrap margin column. */ + for (i = 0; i < fs->wmargin; ++i) + *nl++ = ' '; + else + for (i = 0; i < fs->wmargin; ++i) #ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - putwc_unlocked (L' ', fs->stream); - else + if (_IO_fwide (fs->stream, 0) > 0) + putwc_unlocked (L' ', fs->stream); + else #endif - putc_unlocked (' ', fs->stream); + putc_unlocked (' ', fs->stream); - /* Copy the tail of the original buffer into the current buffer - position. */ - if (nl < nextline) - memmove (nl, nextline, buf + len - nextline); - len -= nextline - buf; + /* Copy the tail of the original buffer into the current buffer + position. */ + if (nl < nextline) + memmove (nl, nextline, buf + len - nextline); + len -= nextline - buf; - /* Continue the scan on the remaining lines in the buffer. */ - buf = nl; + /* Continue the scan on the remaining lines in the buffer. */ + buf = nl; - /* Restore bufp to include all the remaining text. */ - fs->p = nl + len; + /* Restore bufp to include all the remaining text. */ + fs->p = nl + len; - /* Reset the counter of what has been output this line. If wmargin - is 0, we want to avoid the lmargin getting added, so we set - point_col to a magic value of -1 in that case. */ - fs->point_col = fs->wmargin ? fs->wmargin : -1; - } + /* Reset the counter of what has been output this line. If wmargin + is 0, we want to avoid the lmargin getting added, so we set + point_col to a magic value of -1 in that case. */ + fs->point_col = fs->wmargin ? fs->wmargin : -1; + } } /* Remember that we've scanned as far as the end of the buffer. */ @@ -363,35 +363,35 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); #endif if (wrote == fs->p - fs->buf) - { - fs->p = fs->buf; - fs->point_offs = 0; - } + { + fs->p = fs->buf; + fs->point_offs = 0; + } else - { - fs->p -= wrote; - fs->point_offs -= wrote; - memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf); - return 0; - } + { + fs->p -= wrote; + fs->point_offs -= wrote; + memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf); + return 0; + } if ((size_t) (fs->end - fs->buf) < amount) - /* Gotta grow the buffer. */ - { - size_t old_size = fs->end - fs->buf; - size_t new_size = old_size + amount; - char *new_buf; - - if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size))) - { - __set_errno (ENOMEM); - return 0; - } - - fs->buf = new_buf; - fs->end = new_buf + new_size; - fs->p = fs->buf; - } + /* Gotta grow the buffer. */ + { + size_t old_size = fs->end - fs->buf; + size_t new_size = old_size + amount; + char *new_buf; + + if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size))) + { + __set_errno (ENOMEM); + return 0; + } + + fs->buf = new_buf; + fs->end = new_buf + new_size; + fs->p = fs->buf; + } } return 1; @@ -409,14 +409,14 @@ __argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...) va_list args; if (! __argp_fmtstream_ensure (fs, size_guess)) - return -1; + return -1; va_start (args, fmt); avail = fs->end - fs->p; out = __vsnprintf (fs->p, avail, fmt, args); va_end (args); if ((size_t) out >= avail) - size_guess = out + 1; + size_guess = out + 1; } while ((size_t) out >= avail); diff --git a/lib/argp-fmtstream.h b/lib/argp-fmtstream.h index 73157e0c5..1fe902e94 100644 --- a/lib/argp-fmtstream.h +++ b/lib/argp-fmtstream.h @@ -91,19 +91,19 @@ typedef FILE *argp_fmtstream_t; struct argp_fmtstream { - FILE *stream; /* The stream we're outputting to. */ + FILE *stream; /* The stream we're outputting to. */ - size_t lmargin, rmargin; /* Left and right margins. */ - ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ + size_t lmargin, rmargin; /* Left and right margins. */ + ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ /* Point in buffer to which we've processed for wrapping, but not output. */ size_t point_offs; /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ ssize_t point_col; - char *buf; /* Output buffer. */ - char *p; /* Current end of text in BUF. */ - char *end; /* Absolute end of BUF. */ + char *buf; /* Output buffer. */ + char *p; /* Current end of text in BUF. */ + char *end; /* Absolute end of BUF. */ }; typedef struct argp_fmtstream *argp_fmtstream_t; @@ -115,23 +115,23 @@ typedef struct argp_fmtstream *argp_fmtstream_t; Otherwise, chars beyond RMARGIN are simply dropped until a newline. Returns NULL if there was an error. */ extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); + size_t __lmargin, + size_t __rmargin, + ssize_t __wmargin); extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); + size_t __lmargin, + size_t __rmargin, + ssize_t __wmargin); /* Flush __FS to its stream, and free it (but don't close the stream). */ extern void __argp_fmtstream_free (argp_fmtstream_t __fs); extern void argp_fmtstream_free (argp_fmtstream_t __fs); extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs, - const char *__fmt, ...) + const char *__fmt, ...) __attribute__ ((__format__ (printf, 2, 3))); extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs, - const char *__fmt, ...) + const char *__fmt, ...) __attribute__ ((__format__ (printf, 2, 3))); #if _LIBC || !defined __OPTIMIZE__ @@ -142,9 +142,9 @@ extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs, - const char *__str, size_t __len); + const char *__str, size_t __len); extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, - const char *__str, size_t __len); + const char *__str, size_t __len); #endif /* Access macros for various bits of state. */ @@ -158,21 +158,21 @@ extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, #if _LIBC || !defined __OPTIMIZE__ /* Set __FS's left margin to LMARGIN and return the old value. */ extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); + size_t __lmargin); extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); + size_t __lmargin); /* Set __FS's right margin to __RMARGIN and return the old value. */ extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); + size_t __rmargin); extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); + size_t __rmargin); /* Set __FS's wrap margin to __WMARGIN and return the old value. */ extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); + size_t __wmargin); extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); + size_t __wmargin); /* Return the column number of the current output point in __FS. */ extern size_t argp_fmtstream_point (argp_fmtstream_t __fs); @@ -257,7 +257,7 @@ extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); ARGP_FS_EI size_t __argp_fmtstream_write (argp_fmtstream_t __fs, - const char *__str, size_t __len) + const char *__str, size_t __len) { if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len)) { diff --git a/lib/argp-help.c b/lib/argp-help.c index 150a0ad28..862f9724e 100644 --- a/lib/argp-help.c +++ b/lib/argp-help.c @@ -17,7 +17,7 @@ along with this program. If not, see . */ #ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 +# define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H @@ -62,15 +62,15 @@ UPARAM_NAMES vector, below. */ /* Default parameters. */ -#define DUP_ARGS 0 /* True if option argument can be duplicated. */ -#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */ -#define SHORT_OPT_COL 2 /* column in which short options start */ -#define LONG_OPT_COL 6 /* column in which long options start */ -#define DOC_OPT_COL 2 /* column in which doc options start */ -#define OPT_DOC_COL 29 /* column in which option text starts */ -#define HEADER_COL 1 /* column in which group headers are printed */ -#define USAGE_INDENT 12 /* indentation of wrapped usage lines */ -#define RMARGIN 79 /* right margin used for wrapping */ +#define DUP_ARGS 0 /* True if option argument can be duplicated. */ +#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */ +#define SHORT_OPT_COL 2 /* column in which short options start */ +#define LONG_OPT_COL 6 /* column in which long options start */ +#define DOC_OPT_COL 2 /* column in which doc options start */ +#define OPT_DOC_COL 29 /* column in which option text starts */ +#define HEADER_COL 1 /* column in which group headers are printed */ +#define USAGE_INDENT 12 /* indentation of wrapped usage lines */ +#define RMARGIN 79 /* right margin used for wrapping */ /* User-selectable (using an environment variable) formatting parameters. They must all be of type `int' for the parsing code to work. */ @@ -96,7 +96,7 @@ struct uparams int usage_indent; /* indentation of wrapped usage lines */ int rmargin; /* right margin used for wrapping */ - int valid; /* True when the values in here are valid. */ + int valid; /* True when the values in here are valid. */ }; /* This is a global variable, as user options are only ever read once. */ @@ -110,9 +110,9 @@ static struct uparams uparams = { /* A particular uparam, and what the user name is. */ struct uparam_name { - const char *name; /* User name. */ - int is_bool; /* Whether it's `boolean'. */ - size_t uparams_offs; /* Location of the (int) field in UPARAMS. */ + const char *name; /* User name. */ + int is_bool; /* Whether it's `boolean'. */ + size_t uparams_offs; /* Location of the (int) field in UPARAMS. */ }; /* The name-field mappings we know about. */ @@ -138,17 +138,17 @@ validate_uparams (const struct argp_state *state, struct uparams *upptr) for (up = uparam_names; up->name; up++) { if (up->is_bool - || up->uparams_offs == offsetof (struct uparams, rmargin)) - continue; + || up->uparams_offs == offsetof (struct uparams, rmargin)) + continue; if (*(int *)((char *)upptr + up->uparams_offs) >= upptr->rmargin) - { - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "\ + { + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "\ ARGP_HELP_FMT: %s value is less than or equal to %s"), - "rmargin", up->name); - return; - } + "rmargin", up->name); + return; + } } uparams = *upptr; uparams.valid = 1; @@ -167,87 +167,87 @@ fill_in_uparams (const struct argp_state *state) { /* Parse var. */ while (*var) - { - SKIPWS (var); - - if (isalpha ((unsigned char) *var)) - { - size_t var_len; - const struct uparam_name *un; - int unspec = 0, val = 0; - const char *arg = var; - - while (isalnum ((unsigned char) *arg) || *arg == '-' || *arg == '_') - arg++; - var_len = arg - var; - - SKIPWS (arg); - - if (*arg == '\0' || *arg == ',') - unspec = 1; - else if (*arg == '=') - { - arg++; - SKIPWS (arg); - } - - if (unspec) - { - if (var[0] == 'n' && var[1] == 'o' && var[2] == '-') - { - val = 0; - var += 3; - var_len -= 3; - } - else - val = 1; - } - else if (isdigit ((unsigned char) *arg)) - { - val = atoi (arg); - while (isdigit ((unsigned char) *arg)) - arg++; - SKIPWS (arg); - } - - for (un = uparam_names; un->name; un++) - if (strlen (un->name) == var_len - && strncmp (var, un->name, var_len) == 0) - { - if (unspec && !un->is_bool) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "\ + { + SKIPWS (var); + + if (isalpha ((unsigned char) *var)) + { + size_t var_len; + const struct uparam_name *un; + int unspec = 0, val = 0; + const char *arg = var; + + while (isalnum ((unsigned char) *arg) || *arg == '-' || *arg == '_') + arg++; + var_len = arg - var; + + SKIPWS (arg); + + if (*arg == '\0' || *arg == ',') + unspec = 1; + else if (*arg == '=') + { + arg++; + SKIPWS (arg); + } + + if (unspec) + { + if (var[0] == 'n' && var[1] == 'o' && var[2] == '-') + { + val = 0; + var += 3; + var_len -= 3; + } + else + val = 1; + } + else if (isdigit ((unsigned char) *arg)) + { + val = atoi (arg); + while (isdigit ((unsigned char) *arg)) + arg++; + SKIPWS (arg); + } + + for (un = uparam_names; un->name; un++) + if (strlen (un->name) == var_len + && strncmp (var, un->name, var_len) == 0) + { + if (unspec && !un->is_bool) + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "\ %.*s: ARGP_HELP_FMT parameter requires a value"), - (int) var_len, var); - else if (val < 0) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "\ + (int) var_len, var); + else if (val < 0) + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "\ %.*s: ARGP_HELP_FMT parameter must be positive"), - (int) var_len, var); - else - *(int *)((char *)&new_params + un->uparams_offs) = val; - break; - } - if (! un->name) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, "\ + (int) var_len, var); + else + *(int *)((char *)&new_params + un->uparams_offs) = val; + break; + } + if (! un->name) + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, "\ %.*s: Unknown ARGP_HELP_FMT parameter"), - (int) var_len, var); - - var = arg; - if (*var == ',') - var++; - } - else if (*var) - { - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "Garbage in ARGP_HELP_FMT: %s"), var); - break; - } - } + (int) var_len, var); + + var = arg; + if (*var == ',') + var++; + } + else if (*var) + { + __argp_failure (state, 0, 0, + dgettext (state->root_argp->argp_domain, + "Garbage in ARGP_HELP_FMT: %s"), var); + break; + } + } validate_uparams (state, &new_params); } } @@ -287,22 +287,22 @@ fill_in_uparams (const struct argp_state *state) For example, the following output (from ps): -p PID, --pid=PID List the process PID - --pgrp=PGRP List processes in the process group PGRP + --pgrp=PGRP List processes in the process group PGRP -P, -x, --no-parent Include processes without parents -Q, --all-fields Don't elide unusable fields (normally if there's - some reason ps can't print a field for any - process, it's removed from the output entirely) + some reason ps can't print a field for any + process, it's removed from the output entirely) -r, --reverse, --gratuitously-long-reverse-option - Reverse the order of any sort - --session[=SID] Add the processes from the session SID (which - defaults to the sid of the current process) + Reverse the order of any sort + --session[=SID] Add the processes from the session SID (which + defaults to the sid of the current process) Here are some more options: -f ZOT, --foonly=ZOT Glork a foonly -z, --zaza Snit a zar -?, --help Give this help list - --usage Give a short usage message + --usage Give a short usage message -V, --version Print program version The struct argp_option array for the above could look like: @@ -310,18 +310,18 @@ fill_in_uparams (const struct argp_state *state) { {"pid", 'p', "PID", 0, "List the process PID"}, {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"}, - {"no-parent", 'P', 0, 0, "Include processes without parents"}, + {"no-parent", 'P', 0, 0, "Include processes without parents"}, {0, 'x', 0, OPTION_ALIAS}, {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally" " if there's some reason ps can't" - " print a field for any process, it's" + " print a field for any process, it's" " removed from the output entirely)" }, {"reverse", 'r', 0, 0, "Reverse the order of any sort"}, {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS}, {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL, "Add the processes from the session" - " SID (which defaults to the sid of" - " the current process)" }, + " SID (which defaults to the sid of" + " the current process)" }, {0,0,0,0, "Here are some more options:"}, {"foonly", 'f', "ZOT", 0, "Glork a foonly"}, @@ -347,7 +347,7 @@ find_char (char ch, char *beg, char *end) return 0; } -struct hol_cluster; /* fwd decl */ +struct hol_cluster; /* fwd decl */ struct hol_entry { @@ -452,47 +452,47 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster) /* Calculate the space needed. */ for (o = opts; ! oend (o); o++) - { - if (! oalias (o)) - hol->num_entries++; - if (oshort (o)) - num_short_options++; /* This is an upper bound. */ - } + { + if (! oalias (o)) + hol->num_entries++; + if (oshort (o)) + num_short_options++; /* This is an upper bound. */ + } hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries); hol->short_options = malloc (num_short_options + 1); assert (hol->entries && hol->short_options); if (SIZE_MAX <= UINT_MAX) - assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry)); + assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry)); /* Fill in the entries. */ so = hol->short_options; for (o = opts, entry = hol->entries; ! oend (o); entry++) - { - entry->opt = o; - entry->num = 0; - entry->short_options = so; - entry->group = cur_group = - o->group - ? o->group - : ((!o->name && !o->key) - ? cur_group + 1 - : cur_group); - entry->cluster = cluster; - entry->argp = argp; - - do - { - entry->num++; - if (oshort (o) && ! find_char (o->key, hol->short_options, so)) - /* O has a valid short option which hasn't already been used.*/ - *so++ = o->key; - o++; - } - while (! oend (o) && oalias (o)); - } - *so = '\0'; /* null terminated so we can find the length */ + { + entry->opt = o; + entry->num = 0; + entry->short_options = so; + entry->group = cur_group = + o->group + ? o->group + : ((!o->name && !o->key) + ? cur_group + 1 + : cur_group); + entry->cluster = cluster; + entry->argp = argp; + + do + { + entry->num++; + if (oshort (o) && ! find_char (o->key, hol->short_options, so)) + /* O has a valid short option which hasn't already been used.*/ + *so++ = o->key; + o++; + } + while (! oend (o) && oalias (o)); + } + *so = '\0'; /* null terminated so we can find the length */ } return hol; @@ -503,7 +503,7 @@ make_hol (const struct argp *argp, struct hol_cluster *cluster) to it. ARGP is the argp that this cluster results from. */ static struct hol_cluster * hol_add_cluster (struct hol *hol, int group, const char *header, int index, - struct hol_cluster *parent, const struct argp *argp) + struct hol_cluster *parent, const struct argp *argp) { struct hol_cluster *cl = malloc (sizeof (struct hol_cluster)); if (cl) @@ -546,10 +546,10 @@ hol_free (struct hol *hol) static int hol_entry_short_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) + int (*func)(const struct argp_option *opt, + const struct argp_option *real, + const char *domain, void *cookie), + const char *domain, void *cookie) { unsigned nopts; int val = 0; @@ -559,11 +559,11 @@ hol_entry_short_iterate (const struct hol_entry *entry, for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) if (oshort (opt) && *so == opt->key) { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); - so++; + if (!oalias (opt)) + real = opt; + if (ovisible (opt)) + val = (*func)(opt, real, domain, cookie); + so++; } return val; @@ -572,10 +572,10 @@ hol_entry_short_iterate (const struct hol_entry *entry, static inline int __attribute__ ((always_inline)) hol_entry_long_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) + int (*func)(const struct argp_option *opt, + const struct argp_option *real, + const char *domain, void *cookie), + const char *domain, void *cookie) { unsigned nopts; int val = 0; @@ -584,10 +584,10 @@ hol_entry_long_iterate (const struct hol_entry *entry, for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) if (opt->name) { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); + if (!oalias (opt)) + real = opt; + if (ovisible (opt)) + val = (*func)(opt, real, domain, cookie); } return val; @@ -596,7 +596,7 @@ hol_entry_long_iterate (const struct hol_entry *entry, /* Iterator that returns true for the first short option. */ static int until_short (const struct argp_option *opt, const struct argp_option *real, - const char *domain, void *cookie) + const char *domain, void *cookie) { return oshort (opt) ? opt->key : 0; } @@ -606,7 +606,7 @@ static char hol_entry_first_short (const struct hol_entry *entry) { return hol_entry_short_iterate (entry, until_short, - entry->argp->argp_domain, 0); + entry->argp->argp_domain, 0); } /* Returns the first valid long option in ENTRY, or 0 if there is none. */ @@ -635,10 +635,10 @@ hol_find_entry (struct hol *hol, const char *name) unsigned num_opts = entry->num; while (num_opts-- > 0) - if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0) - return entry; - else - opt++; + if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0) + return entry; + else + opt++; entry++; } @@ -704,7 +704,7 @@ hol_cluster_base (struct hol_cluster *cl) /* Return true if CL1 is a child of CL2. */ static int hol_cluster_is_child (const struct hol_cluster *cl1, - const struct hol_cluster *cl2) + const struct hol_cluster *cl2) { while (cl1 && cl1 != cl2) cl1 = cl1->parent; @@ -725,12 +725,12 @@ canon_doc_option (const char **name) { /* Skip initial whitespace. */ while (isspace ((unsigned char) **name)) - (*name)++; + (*name)++; /* Decide whether this looks like an option (leading `-') or not. */ non_opt = (**name != '-'); /* Skip until part of name used for sorting. */ while (**name && !isalnum ((unsigned char) **name)) - (*name)++; + (*name)++; } return non_opt; } @@ -741,7 +741,7 @@ canon_doc_option (const char **name) listing. */ static int hol_entry_cmp (const struct hol_entry *entry1, - const struct hol_entry *entry2) + const struct hol_entry *entry2) { /* The group numbers by which the entries should be ordered; if either is in a cluster, then this is just the group within the cluster. */ @@ -751,20 +751,20 @@ hol_entry_cmp (const struct hol_entry *entry1, if (entry1->cluster != entry2->cluster) { /* The entries are not within the same cluster, so we can't compare them - directly, we have to use the appropiate clustering level too. */ + directly, we have to use the appropiate clustering level too. */ if (! entry1->cluster) - /* ENTRY1 is at the `base level', not in a cluster, so we have to - compare it's group number with that of the base cluster in which - ENTRY2 resides. Note that if they're in the same group, the - clustered option always comes laster. */ - return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1); + /* ENTRY1 is at the `base level', not in a cluster, so we have to + compare it's group number with that of the base cluster in which + ENTRY2 resides. Note that if they're in the same group, the + clustered option always comes laster. */ + return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1); else if (! entry2->cluster) - /* Likewise, but ENTRY2's not in a cluster. */ - return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1); + /* Likewise, but ENTRY2's not in a cluster. */ + return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1); else - /* Both entries are in clusters, we can just compare the clusters. */ - return (rc = hol_cluster_cmp (entry1->cluster, entry2->cluster)) ? - rc : HOL_ENTRY_PTRCMP(entry1, entry2); + /* Both entries are in clusters, we can just compare the clusters. */ + return (rc = hol_cluster_cmp (entry1->cluster, entry2->cluster)) ? + rc : HOL_ENTRY_PTRCMP(entry1, entry2); } else if (group1 == group2) /* The entries are both in the same cluster and group, so compare them @@ -778,36 +778,36 @@ hol_entry_cmp (const struct hol_entry *entry1, const char *long2 = hol_entry_first_long (entry2); if (doc1) - doc1 = canon_doc_option (&long1); + doc1 = canon_doc_option (&long1); if (doc2) - doc2 = canon_doc_option (&long2); + doc2 = canon_doc_option (&long2); if (doc1 != doc2) - /* `documentation' options always follow normal options (or - documentation options that *look* like normal options). */ - return doc1 - doc2; + /* `documentation' options always follow normal options (or + documentation options that *look* like normal options). */ + return doc1 - doc2; else if (!short1 && !short2 && long1 && long2) - /* Only long options. */ - return (rc = __strcasecmp (long1, long2)) ? + /* Only long options. */ + return (rc = __strcasecmp (long1, long2)) ? rc : HOL_ENTRY_PTRCMP(entry1, entry2); else - /* Compare short/short, long/short, short/long, using the first - character of long options. Entries without *any* valid - options (such as options with OPTION_HIDDEN set) will be put - first, but as they're not displayed, it doesn't matter where - they are. */ - { - unsigned char first1 = short1 ? short1 : long1 ? *long1 : 0; - unsigned char first2 = short2 ? short2 : long2 ? *long2 : 0; - /* Use tolower, not _tolower, since only the former is - guaranteed to work on something already lower case. */ - int lower_cmp = tolower (first1) - tolower (first2); - /* Compare ignoring case, except when the options are both the - same letter, in which case lower-case always comes first. */ - return lower_cmp ? lower_cmp : + /* Compare short/short, long/short, short/long, using the first + character of long options. Entries without *any* valid + options (such as options with OPTION_HIDDEN set) will be put + first, but as they're not displayed, it doesn't matter where + they are. */ + { + unsigned char first1 = short1 ? short1 : long1 ? *long1 : 0; + unsigned char first2 = short2 ? short2 : long2 ? *long2 : 0; + /* Use tolower, not _tolower, since only the former is + guaranteed to work on something already lower case. */ + int lower_cmp = tolower (first1) - tolower (first2); + /* Compare ignoring case, except when the options are both the + same letter, in which case lower-case always comes first. */ + return lower_cmp ? lower_cmp : (rc = first2 - first1) ? - rc : HOL_ENTRY_PTRCMP(entry1, entry2); - } + rc : HOL_ENTRY_PTRCMP(entry1, entry2); + } } else /* Within the same cluster, but not the same group, so just compare @@ -833,9 +833,9 @@ hol_sort (struct hol *hol) unsigned i; struct hol_entry *e; for (i = 0, e = hol->entries; i < hol->num_entries; i++, e++) - e->ord = i; + e->ord = i; qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry), - hol_entry_qcmp); + hol_entry_qcmp); } } @@ -856,77 +856,77 @@ hol_append (struct hol *hol, struct hol *more) if (more->num_entries > 0) { if (hol->num_entries == 0) - { - hol->num_entries = more->num_entries; - hol->entries = more->entries; - hol->short_options = more->short_options; - more->num_entries = 0; /* Mark MORE's fields as invalid. */ - } + { + hol->num_entries = more->num_entries; + hol->entries = more->entries; + hol->short_options = more->short_options; + more->num_entries = 0; /* Mark MORE's fields as invalid. */ + } else - /* Append the entries in MORE to those in HOL, taking care to only add - non-shadowed SHORT_OPTIONS values. */ - { - unsigned left; - char *so, *more_so; - struct hol_entry *e; - unsigned num_entries = hol->num_entries + more->num_entries; - struct hol_entry *entries = - malloc (num_entries * sizeof (struct hol_entry)); - unsigned hol_so_len = strlen (hol->short_options); - char *short_options = - malloc (hol_so_len + strlen (more->short_options) + 1); - - assert (entries && short_options); - if (SIZE_MAX <= UINT_MAX) - assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry)); - - __mempcpy (__mempcpy (entries, hol->entries, - hol->num_entries * sizeof (struct hol_entry)), - more->entries, - more->num_entries * sizeof (struct hol_entry)); - - __mempcpy (short_options, hol->short_options, hol_so_len); - - /* Fix up the short options pointers from HOL. */ - for (e = entries, left = hol->num_entries; left > 0; e++, left--) - e->short_options += (short_options - hol->short_options); - - /* Now add the short options from MORE, fixing up its entries - too. */ - so = short_options + hol_so_len; - more_so = more->short_options; - for (left = more->num_entries; left > 0; e++, left--) - { - int opts_left; - const struct argp_option *opt; - - e->short_options = so; - - for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--) - { - int ch = *more_so; - if (oshort (opt) && ch == opt->key) - /* The next short option in MORE_SO, CH, is from OPT. */ - { - if (! find_char (ch, short_options, - short_options + hol_so_len)) - /* The short option CH isn't shadowed by HOL's options, - so add it to the sum. */ - *so++ = ch; - more_so++; - } - } - } - - *so = '\0'; - - free (hol->entries); - free (hol->short_options); - - hol->entries = entries; - hol->num_entries = num_entries; - hol->short_options = short_options; - } + /* Append the entries in MORE to those in HOL, taking care to only add + non-shadowed SHORT_OPTIONS values. */ + { + unsigned left; + char *so, *more_so; + struct hol_entry *e; + unsigned num_entries = hol->num_entries + more->num_entries; + struct hol_entry *entries = + malloc (num_entries * sizeof (struct hol_entry)); + unsigned hol_so_len = strlen (hol->short_options); + char *short_options = + malloc (hol_so_len + strlen (more->short_options) + 1); + + assert (entries && short_options); + if (SIZE_MAX <= UINT_MAX) + assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry)); + + __mempcpy (__mempcpy (entries, hol->entries, + hol->num_entries * sizeof (struct hol_entry)), + more->entries, + more->num_entries * sizeof (struct hol_entry)); + + __mempcpy (short_options, hol->short_options, hol_so_len); + + /* Fix up the short options pointers from HOL. */ + for (e = entries, left = hol->num_entries; left > 0; e++, left--) + e->short_options += (short_options - hol->short_options); + + /* Now add the short options from MORE, fixing up its entries + too. */ + so = short_options + hol_so_len; + more_so = more->short_options; + for (left = more->num_entries; left > 0; e++, left--) + { + int opts_left; + const struct argp_option *opt; + + e->short_options = so; + + for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--) + { + int ch = *more_so; + if (oshort (opt) && ch == opt->key) + /* The next short option in MORE_SO, CH, is from OPT. */ + { + if (! find_char (ch, short_options, + short_options + hol_so_len)) + /* The short option CH isn't shadowed by HOL's options, + so add it to the sum. */ + *so++ = ch; + more_so++; + } + } + } + + *so = '\0'; + + free (hol->entries); + free (hol->short_options); + + hol->entries = entries; + hol->num_entries = num_entries; + hol->short_options = short_options; + } } hol_free (more); @@ -963,11 +963,11 @@ arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt, if (real->arg) { if (real->flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, opt_fmt, - dgettext (domain, real->arg)); + __argp_fmtstream_printf (stream, opt_fmt, + dgettext (domain, real->arg)); else - __argp_fmtstream_printf (stream, req_fmt, - dgettext (domain, real->arg)); + __argp_fmtstream_printf (stream, req_fmt, + dgettext (domain, real->arg)); } } @@ -1007,7 +1007,7 @@ struct pentry_state /* If a user doc filter should be applied to DOC, do so. */ static const char * filter_doc (const char *doc, int key, const struct argp *argp, - const struct argp_state *state) + const struct argp_state *state) { if (argp->help_filter) /* We must apply a user filter to this output. */ @@ -1027,7 +1027,7 @@ filter_doc (const char *doc, int key, const struct argp *argp, to 0. */ static void print_header (const char *str, const struct argp *argp, - struct pentry_state *pest) + struct pentry_state *pest) { const char *tstr = dgettext (argp->argp_domain, str); const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state); @@ -1035,17 +1035,17 @@ print_header (const char *str, const struct argp *argp, if (fstr) { if (*fstr) - { - if (pest->hhstate->prev_entry) - /* Precede with a blank line. */ - __argp_fmtstream_putc (pest->stream, '\n'); - indent_to (pest->stream, uparams.header_col); - __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col); - __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col); - __argp_fmtstream_puts (pest->stream, fstr); - __argp_fmtstream_set_lmargin (pest->stream, 0); - __argp_fmtstream_putc (pest->stream, '\n'); - } + { + if (pest->hhstate->prev_entry) + /* Precede with a blank line. */ + __argp_fmtstream_putc (pest->stream, '\n'); + indent_to (pest->stream, uparams.header_col); + __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col); + __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col); + __argp_fmtstream_puts (pest->stream, fstr); + __argp_fmtstream_set_lmargin (pest->stream, 0); + __argp_fmtstream_putc (pest->stream, '\n'); + } pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */ } @@ -1067,21 +1067,21 @@ comma (unsigned col, struct pentry_state *pest) const struct hol_cluster *cl = pest->entry->cluster; if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group) - __argp_fmtstream_putc (pest->stream, '\n'); + __argp_fmtstream_putc (pest->stream, '\n'); if (cl && cl->header && *cl->header - && (!pe - || (pe->cluster != cl - && !hol_cluster_is_child (pe->cluster, cl)))) - /* If we're changing clusters, then this must be the start of the - ENTRY's cluster unless that is an ancestor of the previous one - (in which case we had just popped into a sub-cluster for a bit). - If so, then print the cluster's header line. */ - { - int old_wm = __argp_fmtstream_wmargin (pest->stream); - print_header (cl->header, cl->argp, pest); - __argp_fmtstream_set_wmargin (pest->stream, old_wm); - } + && (!pe + || (pe->cluster != cl + && !hol_cluster_is_child (pe->cluster, cl)))) + /* If we're changing clusters, then this must be the start of the + ENTRY's cluster unless that is an ancestor of the previous one + (in which case we had just popped into a sub-cluster for a bit). + If so, then print the cluster's header line. */ + { + int old_wm = __argp_fmtstream_wmargin (pest->stream); + print_header (cl->header, cl->argp, pest); + __argp_fmtstream_set_wmargin (pest->stream, old_wm); + } pest->first = 0; } @@ -1094,12 +1094,12 @@ comma (unsigned col, struct pentry_state *pest) /* Print help for ENTRY to STREAM. */ static void hol_entry_help (struct hol_entry *entry, const struct argp_state *state, - argp_fmtstream_t stream, struct hol_help_state *hhstate) + argp_fmtstream_t stream, struct hol_help_state *hhstate) { unsigned num; const struct argp_option *real = entry->opt, *opt; char *so = entry->short_options; - int have_long_opt = 0; /* We have any long options. */ + int have_long_opt = 0; /* We have any long options. */ /* Saved margins. */ int old_lm = __argp_fmtstream_set_lmargin (stream, 0); int old_wm = __argp_fmtstream_wmargin (stream); @@ -1116,10 +1116,10 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, if (! odoc (real)) for (opt = real, num = entry->num; num > 0; opt++, num--) if (opt->name && ovisible (opt)) - { - have_long_opt = 1; - break; - } + { + have_long_opt = 1; + break; + } /* First emit short options. */ __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */ @@ -1127,17 +1127,17 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, if (oshort (opt) && opt->key == *so) /* OPT has a valid (non shadowed) short option. */ { - if (ovisible (opt)) - { - comma (uparams.short_opt_col, &pest); - __argp_fmtstream_putc (stream, '-'); - __argp_fmtstream_putc (stream, *so); - if (!have_long_opt || uparams.dup_args) - arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } - so++; + if (ovisible (opt)) + { + comma (uparams.short_opt_col, &pest); + __argp_fmtstream_putc (stream, '-'); + __argp_fmtstream_putc (stream, *so); + if (!have_long_opt || uparams.dup_args) + arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream); + else if (real->arg) + hhstate->suppressed_dup_arg = 1; + } + so++; } /* Now, long options. */ @@ -1146,18 +1146,18 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, { __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col); for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && *opt->name && ovisible (opt)) - { - comma (uparams.doc_opt_col, &pest); - /* Calling dgettext here isn't quite right, since sorting will - have been done on the original; but documentation options - should be pretty rare anyway... */ - __argp_fmtstream_puts (stream, - onotrans (opt) ? - opt->name : - dgettext (state->root_argp->argp_domain, - opt->name)); - } + if (opt->name && *opt->name && ovisible (opt)) + { + comma (uparams.doc_opt_col, &pest); + /* Calling dgettext here isn't quite right, since sorting will + have been done on the original; but documentation options + should be pretty rare anyway... */ + __argp_fmtstream_puts (stream, + onotrans (opt) ? + opt->name : + dgettext (state->root_argp->argp_domain, + opt->name)); + } } else /* A real long option. */ @@ -1166,16 +1166,16 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col); for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - comma (uparams.long_opt_col, &pest); - __argp_fmtstream_printf (stream, "--%s", opt->name); - if (first_long_opt || uparams.dup_args) - arg (real, "=%s", "[=%s]", state->root_argp->argp_domain, - stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } + if (opt->name && ovisible (opt)) + { + comma (uparams.long_opt_col, &pest); + __argp_fmtstream_printf (stream, "--%s", opt->name); + if (first_long_opt || uparams.dup_args) + arg (real, "=%s", "[=%s]", state->root_argp->argp_domain, + stream); + else if (real->arg) + hhstate->suppressed_dup_arg = 1; + } } /* Next, documentation strings. */ @@ -1185,35 +1185,35 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state, { /* Didn't print any switches, what's up? */ if (!oshort (real) && !real->name) - /* This is a group header, print it nicely. */ - print_header (real->doc, entry->argp, &pest); + /* This is a group header, print it nicely. */ + print_header (real->doc, entry->argp, &pest); else - /* Just a totally shadowed option or null header; print nothing. */ - goto cleanup; /* Just return, after cleaning up. */ + /* Just a totally shadowed option or null header; print nothing. */ + goto cleanup; /* Just return, after cleaning up. */ } else { const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain, - real->doc) : 0; + real->doc) : 0; const char *fstr = filter_doc (tstr, real->key, entry->argp, state); if (fstr && *fstr) - { - unsigned int col = __argp_fmtstream_point (stream); + { + unsigned int col = __argp_fmtstream_point (stream); - __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col); - __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col); + __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col); + __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col); - if (col > (unsigned int) (uparams.opt_doc_col + 3)) - __argp_fmtstream_putc (stream, '\n'); - else if (col >= (unsigned int) uparams.opt_doc_col) - __argp_fmtstream_puts (stream, " "); - else - indent_to (stream, uparams.opt_doc_col); + if (col > (unsigned int) (uparams.opt_doc_col + 3)) + __argp_fmtstream_putc (stream, '\n'); + else if (col >= (unsigned int) uparams.opt_doc_col) + __argp_fmtstream_puts (stream, " "); + else + indent_to (stream, uparams.opt_doc_col); - __argp_fmtstream_puts (stream, fstr); - } + __argp_fmtstream_puts (stream, fstr); + } if (fstr && fstr != tstr) - free ((char *) fstr); + free ((char *) fstr); /* Reset the left margin. */ __argp_fmtstream_set_lmargin (stream, 0); @@ -1230,7 +1230,7 @@ cleanup: /* Output a long help message about the options in HOL to STREAM. */ static void hol_help (struct hol *hol, const struct argp_state *state, - argp_fmtstream_t stream) + argp_fmtstream_t stream) { unsigned num; struct hol_entry *entry; @@ -1245,15 +1245,15 @@ hol_help (struct hol *hol, const struct argp_state *state, Mandatory or optional arguments to long options are also mandatory or \ optional for any corresponding short options."); const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE, - state ? state->root_argp : 0, state); + state ? state->root_argp : 0, state); if (fstr && *fstr) - { - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, fstr); - __argp_fmtstream_putc (stream, '\n'); - } + { + __argp_fmtstream_putc (stream, '\n'); + __argp_fmtstream_puts (stream, fstr); + __argp_fmtstream_putc (stream, '\n'); + } if (fstr && fstr != tstr) - free ((char *) fstr); + free ((char *) fstr); } } @@ -1263,8 +1263,8 @@ optional for any corresponding short options."); pointer pointer to by COOKIE, and advance the pointer. */ static int add_argless_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) + const struct argp_option *real, + const char *domain, void *cookie) { char **snao_end = cookie; if (!(opt->arg || real->arg) @@ -1277,8 +1277,8 @@ add_argless_short_opt (const struct argp_option *opt, stream pointed at by COOKIE. */ static int usage_argful_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) + const struct argp_option *real, + const char *domain, void *cookie) { argp_fmtstream_t stream = cookie; const char *arg = opt->arg; @@ -1292,14 +1292,14 @@ usage_argful_short_opt (const struct argp_option *opt, arg = dgettext (domain, arg); if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg); + __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg); else - { - /* Manually do line wrapping so that it (probably) won't - get wrapped at the embedded space. */ - space (stream, 6 + strlen (arg)); - __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg); - } + { + /* Manually do line wrapping so that it (probably) won't + get wrapped at the embedded space. */ + space (stream, 6 + strlen (arg)); + __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg); + } } return 0; @@ -1309,8 +1309,8 @@ usage_argful_short_opt (const struct argp_option *opt, COOKIE. */ static int usage_long_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) + const struct argp_option *real, + const char *domain, void *cookie) { argp_fmtstream_t stream = cookie; const char *arg = opt->arg; @@ -1322,15 +1322,15 @@ usage_long_opt (const struct argp_option *opt, if (! (flags & OPTION_NO_USAGE) && !odoc (opt)) { if (arg) - { - arg = dgettext (domain, arg); - if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg); - else - __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg); - } + { + arg = dgettext (domain, arg); + if (flags & OPTION_ARG_OPTIONAL) + __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg); + else + __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg); + } else - __argp_fmtstream_printf (stream, " [--%s]", opt->name); + __argp_fmtstream_printf (stream, " [--%s]", opt->name); } return 0; @@ -1349,29 +1349,29 @@ hol_usage (struct hol *hol, argp_fmtstream_t stream) /* First we put a list of short options without arguments. */ for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, add_argless_short_opt, - entry->argp->argp_domain, &snao_end); + ; nentries > 0 + ; entry++, nentries--) + hol_entry_short_iterate (entry, add_argless_short_opt, + entry->argp->argp_domain, &snao_end); if (snao_end > short_no_arg_opts) - { - *snao_end++ = 0; - __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts); - } + { + *snao_end++ = 0; + __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts); + } /* Now a list of short options *with* arguments. */ for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, usage_argful_short_opt, - entry->argp->argp_domain, stream); + ; nentries > 0 + ; entry++, nentries--) + hol_entry_short_iterate (entry, usage_argful_short_opt, + entry->argp->argp_domain, stream); /* Finally, a list of long options (whew!). */ for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_long_iterate (entry, usage_long_opt, - entry->argp->argp_domain, stream); + ; nentries > 0 + ; entry++, nentries--) + hol_entry_long_iterate (entry, usage_long_opt, + entry->argp->argp_domain, stream); } } @@ -1385,15 +1385,15 @@ argp_hol (const struct argp *argp, struct hol_cluster *cluster) if (child) while (child->argp) { - struct hol_cluster *child_cluster = - ((child->group || child->header) - /* Put CHILD->argp within its own cluster. */ - ? hol_add_cluster (hol, child->group, child->header, - child - argp->children, cluster, argp) - /* Just merge it into the parent's cluster. */ - : cluster); - hol_append (hol, argp_hol (child->argp, child_cluster)) ; - child++; + struct hol_cluster *child_cluster = + ((child->group || child->header) + /* Put CHILD->argp within its own cluster. */ + ? hol_add_cluster (hol, child->group, child->header, + child - argp->children, cluster, argp) + /* Just merge it into the parent's cluster. */ + : cluster); + hol_append (hol, argp_hol (child->argp, child_cluster)) ; + child++; } return hol; } @@ -1423,7 +1423,7 @@ argp_args_levels (const struct argp *argp) returned as long as there are more patterns to output. */ static int argp_args_usage (const struct argp *argp, const struct argp_state *state, - char **levels, int advance, argp_fmtstream_t stream) + char **levels, int advance, argp_fmtstream_t stream) { char *our_level = *levels; int multiple = 0; @@ -1436,24 +1436,24 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, const char *cp = fdoc; nl = __strchrnul (cp, '\n'); if (*nl != '\0') - /* This is a `multi-level' args doc; advance to the correct position - as determined by our state in LEVELS, and update LEVELS. */ - { - int i; - multiple = 1; - for (i = 0; i < *our_level; i++) - cp = nl + 1, nl = __strchrnul (cp, '\n'); - (*levels)++; - } + /* This is a `multi-level' args doc; advance to the correct position + as determined by our state in LEVELS, and update LEVELS. */ + { + int i; + multiple = 1; + for (i = 0; i < *our_level; i++) + cp = nl + 1, nl = __strchrnul (cp, '\n'); + (*levels)++; + } /* Manually do line wrapping so that it (probably) won't get wrapped at - any embedded spaces. */ + any embedded spaces. */ space (stream, 1 + nl - cp); __argp_fmtstream_write (stream, cp, nl - cp); } if (fdoc && fdoc != tdoc) - free ((char *)fdoc); /* Free user's modified doc string. */ + free ((char *)fdoc); /* Free user's modified doc string. */ if (child) while (child->argp) @@ -1463,14 +1463,14 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, { /* Need to increment our level. */ if (*nl) - /* There's more we can do here. */ - { - (*our_level)++; - advance = 0; /* Our parent shouldn't advance also. */ - } + /* There's more we can do here. */ + { + (*our_level)++; + advance = 0; /* Our parent shouldn't advance also. */ + } else if (*our_level > 0) - /* We had multiple levels, but used them up; reset to zero. */ - *our_level = 0; + /* We had multiple levels, but used them up; reset to zero. */ + *our_level = 0; } return !advance; @@ -1485,8 +1485,8 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, occurrence is output. Returns true if anything was output. */ static int argp_doc (const struct argp *argp, const struct argp_state *state, - int post, int pre_blank, int first_only, - argp_fmtstream_t stream) + int post, int pre_blank, int first_only, + argp_fmtstream_t stream) { const char *text; const char *inp_text; @@ -1500,17 +1500,17 @@ argp_doc (const struct argp *argp, const struct argp_state *state, { char *vt = strchr (argp->doc, '\v'); if (vt) - { - if (post) - inp_text = vt + 1; - else - { - inp_text_len = vt - argp->doc; - inp_text = __strndup (argp->doc, inp_text_len); - } - } + { + if (post) + inp_text = vt + 1; + else + { + inp_text_len = vt - argp->doc; + inp_text = __strndup (argp->doc, inp_text_len); + } + } else - inp_text = post ? 0 : argp->doc; + inp_text = post ? 0 : argp->doc; trans_text = inp_text ? dgettext (argp->argp_domain, inp_text) : NULL; } else @@ -1521,10 +1521,10 @@ argp_doc (const struct argp *argp, const struct argp_state *state, { input = __argp_input (argp, state); text = - (*argp->help_filter) (post - ? ARGP_KEY_HELP_POST_DOC - : ARGP_KEY_HELP_PRE_DOC, - trans_text, input); + (*argp->help_filter) (post + ? ARGP_KEY_HELP_POST_DOC + : ARGP_KEY_HELP_PRE_DOC, + trans_text, input); } else text = (const char *) trans_text; @@ -1532,45 +1532,45 @@ argp_doc (const struct argp *argp, const struct argp_state *state, if (text) { if (pre_blank) - __argp_fmtstream_putc (stream, '\n'); + __argp_fmtstream_putc (stream, '\n'); __argp_fmtstream_puts (stream, text); if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); + __argp_fmtstream_putc (stream, '\n'); anything = 1; } if (text && text != trans_text) - free ((char *) text); /* Free TEXT returned from the help filter. */ + free ((char *) text); /* Free TEXT returned from the help filter. */ if (inp_text && inp_text_len) - free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */ + free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */ if (post && argp->help_filter) /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text. */ { text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input); if (text) - { - if (anything || pre_blank) - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, text); - free ((char *) text); - if (__argp_fmtstream_point (stream) - > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - anything = 1; - } + { + if (anything || pre_blank) + __argp_fmtstream_putc (stream, '\n'); + __argp_fmtstream_puts (stream, text); + free ((char *) text); + if (__argp_fmtstream_point (stream) + > __argp_fmtstream_lmargin (stream)) + __argp_fmtstream_putc (stream, '\n'); + anything = 1; + } } if (child) while (child->argp && !(first_only && anything)) anything |= - argp_doc ((child++)->argp, state, - post, anything || pre_blank, first_only, - stream); + argp_doc ((child++)->argp, state, + post, anything || pre_blank, first_only, + stream); return anything; } @@ -1583,7 +1583,7 @@ static void _help (const struct argp *argp, const struct argp_state *state, FILE *stream, unsigned flags, char *name) { - int anything = 0; /* Whether we've output anything. */ + int anything = 0; /* Whether we've output anything. */ struct hol *hol = 0; argp_fmtstream_t fs; @@ -1627,48 +1627,48 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream, memset (pattern_levels, 0, num_pattern_levels); do - { - int old_lm; - int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent); - char *levels = pattern_levels; - - if (first_pattern) - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, "Usage:"), - name); - else - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, " or: "), - name); - - /* We set the lmargin as well as the wmargin, because hol_usage - manually wraps options with newline to avoid annoying breaks. */ - old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent); - - if (flags & ARGP_HELP_SHORT_USAGE) - /* Just show where the options go. */ - { - if (hol->num_entries > 0) - __argp_fmtstream_puts (fs, dgettext (argp->argp_domain, - " [OPTION...]")); - } - else - /* Actually print the options. */ - { - hol_usage (hol, fs); - flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */ - } - - more_patterns = argp_args_usage (argp, state, &levels, 1, fs); - - __argp_fmtstream_set_wmargin (fs, old_wm); - __argp_fmtstream_set_lmargin (fs, old_lm); - - __argp_fmtstream_putc (fs, '\n'); - anything = 1; - - first_pattern = 0; - } + { + int old_lm; + int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent); + char *levels = pattern_levels; + + if (first_pattern) + __argp_fmtstream_printf (fs, "%s %s", + dgettext (argp->argp_domain, "Usage:"), + name); + else + __argp_fmtstream_printf (fs, "%s %s", + dgettext (argp->argp_domain, " or: "), + name); + + /* We set the lmargin as well as the wmargin, because hol_usage + manually wraps options with newline to avoid annoying breaks. */ + old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent); + + if (flags & ARGP_HELP_SHORT_USAGE) + /* Just show where the options go. */ + { + if (hol->num_entries > 0) + __argp_fmtstream_puts (fs, dgettext (argp->argp_domain, + " [OPTION...]")); + } + else + /* Actually print the options. */ + { + hol_usage (hol, fs); + flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */ + } + + more_patterns = argp_args_usage (argp, state, &levels, 1, fs); + + __argp_fmtstream_set_wmargin (fs, old_wm); + __argp_fmtstream_set_lmargin (fs, old_lm); + + __argp_fmtstream_putc (fs, '\n'); + anything = 1; + + first_pattern = 0; + } while (more_patterns); } @@ -1679,7 +1679,7 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream, { __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\ Try `%s --help' or `%s --usage' for more information.\n"), - name, name); + name, name); anything = 1; } @@ -1688,12 +1688,12 @@ Try `%s --help' or `%s --usage' for more information.\n"), { /* Print info about all the options. */ if (hol->num_entries > 0) - { - if (anything) - __argp_fmtstream_putc (fs, '\n'); - hol_help (hol, state, fs); - anything = 1; - } + { + if (anything) + __argp_fmtstream_putc (fs, '\n'); + hol_help (hol, state, fs); + anything = 1; + } } if (flags & ARGP_HELP_POST_DOC) @@ -1703,10 +1703,10 @@ Try `%s --help' or `%s --usage' for more information.\n"), if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address) { if (anything) - __argp_fmtstream_putc (fs, '\n'); + __argp_fmtstream_putc (fs, '\n'); __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, - "Report bugs to %s.\n"), - argp_program_bug_address); + "Report bugs to %s.\n"), + argp_program_bug_address); anything = 1; } @@ -1723,7 +1723,7 @@ Try `%s --help' or `%s --usage' for more information.\n"), /* Output a usage message for ARGP to STREAM. FLAGS are from the set ARGP_HELP_*. NAME is what to use wherever a `program name' is needed. */ void __argp_help (const struct argp *argp, FILE *stream, - unsigned flags, char *name) + unsigned flags, char *name) { struct argp_state state; memset (&state, 0, sizeof state); @@ -1760,18 +1760,18 @@ __argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags) if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream) { if (state && (state->flags & ARGP_LONG_ONLY)) - flags |= ARGP_HELP_LONG_ONLY; + flags |= ARGP_HELP_LONG_ONLY; _help (state ? state->root_argp : 0, state, stream, flags, - state ? state->name : __argp_short_program_name ()); + state ? state->name : __argp_short_program_name ()); if (!state || ! (state->flags & ARGP_NO_EXIT)) - { - if (flags & ARGP_HELP_EXIT_ERR) - exit (argp_err_exit_status); - if (flags & ARGP_HELP_EXIT_OK) - exit (0); - } + { + if (flags & ARGP_HELP_EXIT_ERR) + exit (argp_err_exit_status); + if (flags & ARGP_HELP_EXIT_OK) + exit (0); + } } } #ifdef weak_alias @@ -1789,51 +1789,51 @@ __argp_error (const struct argp_state *state, const char *fmt, ...) FILE *stream = state ? state->err_stream : stderr; if (stream) - { - va_list ap; + { + va_list ap; #if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __flockfile (stream); + __flockfile (stream); #endif - va_start (ap, fmt); + va_start (ap, fmt); #ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - { - char *buf; + if (_IO_fwide (stream, 0) > 0) + { + char *buf; - if (__asprintf (&buf, fmt, ap) < 0) - buf = NULL; + if (__asprintf (&buf, fmt, ap) < 0) + buf = NULL; - __fwprintf (stream, L"%s: %s\n", - state ? state->name : __argp_short_program_name (), - buf); + __fwprintf (stream, L"%s: %s\n", + state ? state->name : __argp_short_program_name (), + buf); - free (buf); - } - else + free (buf); + } + else #endif - { - fputs_unlocked (state - ? state->name : __argp_short_program_name (), - stream); - putc_unlocked (':', stream); - putc_unlocked (' ', stream); + { + fputs_unlocked (state + ? state->name : __argp_short_program_name (), + stream); + putc_unlocked (':', stream); + putc_unlocked (' ', stream); - vfprintf (stream, fmt, ap); + vfprintf (stream, fmt, ap); - putc_unlocked ('\n', stream); - } + putc_unlocked ('\n', stream); + } - __argp_state_help (state, stream, ARGP_HELP_STD_ERR); + __argp_state_help (state, stream, ARGP_HELP_STD_ERR); - va_end (ap); + va_end (ap); #if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __funlockfile (stream); + __funlockfile (stream); #endif - } + } } } #ifdef weak_alias @@ -1850,100 +1850,100 @@ weak_alias (__argp_error, argp_error) parsing but don't reflect a (syntactic) problem with the input. */ void __argp_failure (const struct argp_state *state, int status, int errnum, - const char *fmt, ...) + const char *fmt, ...) { if (!state || !(state->flags & ARGP_NO_ERRS)) { FILE *stream = state ? state->err_stream : stderr; if (stream) - { + { #if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __flockfile (stream); + __flockfile (stream); #endif #ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - __fwprintf (stream, L"%s", - state ? state->name : __argp_short_program_name ()); - else + if (_IO_fwide (stream, 0) > 0) + __fwprintf (stream, L"%s", + state ? state->name : __argp_short_program_name ()); + else #endif - fputs_unlocked (state - ? state->name : __argp_short_program_name (), - stream); + fputs_unlocked (state + ? state->name : __argp_short_program_name (), + stream); - if (fmt) - { - va_list ap; + if (fmt) + { + va_list ap; - va_start (ap, fmt); + va_start (ap, fmt); #ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - { - char *buf; + if (_IO_fwide (stream, 0) > 0) + { + char *buf; - if (__asprintf (&buf, fmt, ap) < 0) - buf = NULL; + if (__asprintf (&buf, fmt, ap) < 0) + buf = NULL; - __fwprintf (stream, L": %s", buf); + __fwprintf (stream, L": %s", buf); - free (buf); - } - else + free (buf); + } + else #endif - { - putc_unlocked (':', stream); - putc_unlocked (' ', stream); + { + putc_unlocked (':', stream); + putc_unlocked (' ', stream); - vfprintf (stream, fmt, ap); - } + vfprintf (stream, fmt, ap); + } - va_end (ap); - } + va_end (ap); + } - if (errnum) - { - char buf[200]; + if (errnum) + { + char buf[200]; #ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - __fwprintf (stream, L": %s", - __strerror_r (errnum, buf, sizeof (buf))); - else + if (_IO_fwide (stream, 0) > 0) + __fwprintf (stream, L": %s", + __strerror_r (errnum, buf, sizeof (buf))); + else #endif - { - char const *s = NULL; - putc_unlocked (':', stream); - putc_unlocked (' ', stream); + { + char const *s = NULL; + putc_unlocked (':', stream); + putc_unlocked (' ', stream); #if _LIBC || (HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P) - s = __strerror_r (errnum, buf, sizeof buf); + s = __strerror_r (errnum, buf, sizeof buf); #elif HAVE_DECL_STRERROR_R - if (__strerror_r (errnum, buf, sizeof buf) == 0) - s = buf; + if (__strerror_r (errnum, buf, sizeof buf) == 0) + s = buf; #endif #if !_LIBC - if (! s && ! (s = strerror (errnum))) - s = dgettext (state->root_argp->argp_domain, - "Unknown system error"); + if (! s && ! (s = strerror (errnum))) + s = dgettext (state->root_argp->argp_domain, + "Unknown system error"); #endif - fputs (s, stream); - } - } + fputs (s, stream); + } + } #ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - putwc_unlocked (L'\n', stream); - else + if (_IO_fwide (stream, 0) > 0) + putwc_unlocked (L'\n', stream); + else #endif - putc_unlocked ('\n', stream); + putc_unlocked ('\n', stream); #if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __funlockfile (stream); + __funlockfile (stream); #endif - if (status && (!state || !(state->flags & ARGP_NO_EXIT))) - exit (status); - } + if (status && (!state || !(state->flags & ARGP_NO_EXIT))) + exit (status); + } } } #ifdef weak_alias diff --git a/lib/argp-namefrob.h b/lib/argp-namefrob.h index 7b7b173d3..75d5b9ac9 100644 --- a/lib/argp-namefrob.h +++ b/lib/argp-namefrob.h @@ -151,7 +151,7 @@ extern char *__argp_base_name(const char *arg); #endif #if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME -# define __argp_short_program_name() (program_invocation_short_name) +# define __argp_short_program_name() (program_invocation_short_name) #else extern char *__argp_short_program_name (void); #endif diff --git a/lib/argp-parse.c b/lib/argp-parse.c index 317ce21b3..47ae7ef80 100644 --- a/lib/argp-parse.c +++ b/lib/argp-parse.c @@ -46,9 +46,9 @@ #define alignto(n, d) ((((n) + (d) - 1) / (d)) * (d)) /* Getopt return values. */ -#define KEY_END (-1) /* The end of the options. */ -#define KEY_ARG 1 /* A non-option argument. */ -#define KEY_ERR '?' /* An error parsing the options. */ +#define KEY_END (-1) /* The end of the options. */ +#define KEY_ARG 1 /* A non-option argument. */ +#define KEY_ERR '?' /* An error parsing the options. */ /* The meta-argument used to prevent any further arguments being interpreted as options. */ @@ -72,16 +72,16 @@ it to 0 yourself. */ static volatile int _argp_hang; -#define OPT_PROGNAME -2 -#define OPT_USAGE -3 -#define OPT_HANG -4 +#define OPT_PROGNAME -2 +#define OPT_USAGE -3 +#define OPT_HANG -4 static const struct argp_option argp_default_options[] = { - {"help", '?', 0, 0, N_("give this help list"), -1}, - {"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0}, + {"help", '?', 0, 0, N_("give this help list"), -1}, + {"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0}, {"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0}, - {"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN, + {"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN, N_("hang for SECS seconds (default 3600)"), 0}, {NULL, 0, 0, 0, NULL, 0} }; @@ -96,16 +96,16 @@ argp_default_parser (int key, char *arg, struct argp_state *state) break; case OPT_USAGE: __argp_state_help (state, state->out_stream, - ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); + ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); break; - case OPT_PROGNAME: /* Set the program name. */ + case OPT_PROGNAME: /* Set the program name. */ #if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME program_invocation_name = arg; #endif /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka - __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined - to be that, so we have to be a bit careful here.] */ + __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined + to be that, so we have to be a bit careful here.] */ /* Update what we use for messages. */ state->name = __argp_base_name (arg); @@ -115,16 +115,16 @@ argp_default_parser (int key, char *arg, struct argp_state *state) #endif if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS)) - == ARGP_PARSE_ARGV0) - /* Update what getopt uses too. */ - state->argv[0] = arg; + == ARGP_PARSE_ARGV0) + /* Update what getopt uses too. */ + state->argv[0] = arg; break; case OPT_HANG: _argp_hang = atoi (arg ? arg : "3600"); while (_argp_hang-- > 0) - __sleep (1); + __sleep (1); break; default: @@ -139,7 +139,7 @@ static const struct argp argp_default_argp = static const struct argp_option argp_version_options[] = { - {"version", 'V', 0, 0, N_("print program version"), -1}, + {"version", 'V', 0, 0, N_("print program version"), -1}, {NULL, 0, 0, 0, NULL, 0} }; @@ -150,14 +150,14 @@ argp_version_parser (int key, char *arg, struct argp_state *state) { case 'V': if (argp_program_version_hook) - (*argp_program_version_hook) (state->out_stream, state); + (*argp_program_version_hook) (state->out_stream, state); else if (argp_program_version) - fprintf (state->out_stream, "%s\n", argp_program_version); + fprintf (state->out_stream, "%s\n", argp_program_version); else - __argp_error (state, dgettext (state->root_argp->argp_domain, - "(PROGRAM ERROR) No version known!?")); + __argp_error (state, dgettext (state->root_argp->argp_domain, + "(PROGRAM ERROR) No version known!?")); if (! (state->flags & ARGP_NO_EXIT)) - exit (0); + exit (0); break; default: return EBADKEY; @@ -208,7 +208,7 @@ struct group /* This group's parser's parent's group. */ struct group *parent; - unsigned parent_index; /* And the our position in the parent. */ + unsigned parent_index; /* And the our position in the parent. */ /* These fields are swapped into and out of the state structure when calling this group's parser. */ @@ -286,8 +286,8 @@ struct parser_convert_state next unused group entry. CVT holds state used during the conversion. */ static struct group * convert_options (const struct argp *argp, - struct group *parent, unsigned parent_index, - struct group *group, struct parser_convert_state *cvt) + struct group *parent, unsigned parent_index, + struct group *group, struct parser_convert_state *cvt) { /* REAL is the most recent non-alias value of OPT. */ const struct argp_option *real = argp->options; @@ -298,55 +298,55 @@ convert_options (const struct argp *argp, const struct argp_option *opt; if (real) - for (opt = real; !__option_is_end (opt); opt++) - { - if (! (opt->flags & OPTION_ALIAS)) - /* OPT isn't an alias, so we can use values from it. */ - real = opt; - - if (! (real->flags & OPTION_DOC)) - /* A real option (not just documentation). */ - { - if (__option_is_short (opt)) - /* OPT can be used as a short option. */ - { - *cvt->short_end++ = opt->key; - if (real->arg) - { - *cvt->short_end++ = ':'; - if (real->flags & OPTION_ARG_OPTIONAL) - *cvt->short_end++ = ':'; - } - *cvt->short_end = '\0'; /* keep 0 terminated */ - } - - if (opt->name - && find_long_option (cvt->parser->long_opts, opt->name) < 0) - /* OPT can be used as a long option. */ - { - cvt->long_end->name = opt->name; - cvt->long_end->has_arg = - (real->arg - ? (real->flags & OPTION_ARG_OPTIONAL - ? optional_argument - : required_argument) - : no_argument); - cvt->long_end->flag = 0; - /* we add a disambiguating code to all the user's - values (which is removed before we actually call - the function to parse the value); this means that - the user loses use of the high 8 bits in all his - values (the sign of the lower bits is preserved - however)... */ - cvt->long_end->val = - ((opt->key | real->key) & USER_MASK) - + (((group - cvt->parser->groups) + 1) << USER_BITS); - - /* Keep the LONG_OPTS list terminated. */ - (++cvt->long_end)->name = NULL; - } - } - } + for (opt = real; !__option_is_end (opt); opt++) + { + if (! (opt->flags & OPTION_ALIAS)) + /* OPT isn't an alias, so we can use values from it. */ + real = opt; + + if (! (real->flags & OPTION_DOC)) + /* A real option (not just documentation). */ + { + if (__option_is_short (opt)) + /* OPT can be used as a short option. */ + { + *cvt->short_end++ = opt->key; + if (real->arg) + { + *cvt->short_end++ = ':'; + if (real->flags & OPTION_ARG_OPTIONAL) + *cvt->short_end++ = ':'; + } + *cvt->short_end = '\0'; /* keep 0 terminated */ + } + + if (opt->name + && find_long_option (cvt->parser->long_opts, opt->name) < 0) + /* OPT can be used as a long option. */ + { + cvt->long_end->name = opt->name; + cvt->long_end->has_arg = + (real->arg + ? (real->flags & OPTION_ARG_OPTIONAL + ? optional_argument + : required_argument) + : no_argument); + cvt->long_end->flag = 0; + /* we add a disambiguating code to all the user's + values (which is removed before we actually call + the function to parse the value); this means that + the user loses use of the high 8 bits in all his + values (the sign of the lower bits is preserved + however)... */ + cvt->long_end->val = + ((opt->key | real->key) & USER_MASK) + + (((group - cvt->parser->groups) + 1) << USER_BITS); + + /* Keep the LONG_OPTS list terminated. */ + (++cvt->long_end)->name = NULL; + } + } + } group->parser = argp->parser; group->argp = argp; @@ -359,15 +359,15 @@ convert_options (const struct argp *argp, group->child_inputs = 0; if (children) - /* Assign GROUP's CHILD_INPUTS field some space from + /* Assign GROUP's CHILD_INPUTS field some space from CVT->child_inputs_end.*/ - { - unsigned num_children = 0; - while (children[num_children].argp) - num_children++; - group->child_inputs = cvt->child_inputs_end; - cvt->child_inputs_end += num_children; - } + { + unsigned num_children = 0; + while (children[num_children].argp) + num_children++; + group->child_inputs = cvt->child_inputs_end; + cvt->child_inputs_end += num_children; + } parent = group++; } @@ -378,8 +378,8 @@ convert_options (const struct argp *argp, { unsigned index = 0; while (children->argp) - group = - convert_options (children++->argp, parent, index++, group, cvt); + group = + convert_options (children++->argp, parent, index++, group, cvt); } return group; @@ -415,10 +415,10 @@ parser_convert (struct parser *parser, const struct argp *argp, int flags) /* Lengths of various parser fields which we will allocated. */ struct parser_sizes { - size_t short_len; /* Getopt short options string. */ - size_t long_len; /* Getopt long options vector. */ - size_t num_groups; /* Group structures we allocate. */ - size_t num_child_inputs; /* Child input slots. */ + size_t short_len; /* Getopt short options string. */ + size_t long_len; /* Getopt long options vector. */ + size_t num_groups; /* Group structures we allocate. */ + size_t num_child_inputs; /* Child input slots. */ }; /* For ARGP, increments the NUM_GROUPS field in SZS by the total number of @@ -435,27 +435,27 @@ calc_sizes (const struct argp *argp, struct parser_sizes *szs) { szs->num_groups++; if (opt) - { - int num_opts = 0; - while (!__option_is_end (opt++)) - num_opts++; - szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */ - szs->long_len += num_opts; - } + { + int num_opts = 0; + while (!__option_is_end (opt++)) + num_opts++; + szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */ + szs->long_len += num_opts; + } } if (child) while (child->argp) { - calc_sizes ((child++)->argp, szs); - szs->num_child_inputs++; + calc_sizes ((child++)->argp, szs); + szs->num_child_inputs++; } } /* Initializes PARSER to parse ARGP in a manner described by FLAGS. */ static error_t parser_init (struct parser *parser, const struct argp *argp, - int argc, char **argv, int flags, void *input) + int argc, char **argv, int flags, void *input) { error_t err = 0; struct group *group; @@ -512,7 +512,7 @@ parser_init (struct parser *parser, const struct argp *argp, parser->state.flags = flags; parser->state.err_stream = stderr; parser->state.out_stream = stdout; - parser->state.next = 0; /* Tell getopt to initialize. */ + parser->state.next = 0; /* Tell getopt to initialize. */ parser->state.pstate = parser; parser->try_getopt = 1; @@ -526,20 +526,20 @@ parser_init (struct parser *parser, const struct argp *argp, group++) { if (group->parent) - /* If a child parser, get the initial input value from the parent. */ - group->input = group->parent->child_inputs[group->parent_index]; + /* If a child parser, get the initial input value from the parent. */ + group->input = group->parent->child_inputs[group->parent_index]; if (!group->parser - && group->argp->children && group->argp->children->argp) - /* For the special case where no parsing function is supplied for an - argp, propagate its input to its first child, if any (this just - makes very simple wrapper argps more convenient). */ - group->child_inputs[0] = group->input; + && group->argp->children && group->argp->children->argp) + /* For the special case where no parsing function is supplied for an + argp, propagate its input to its first child, if any (this just + makes very simple wrapper argps more convenient). */ + group->child_inputs[0] = group->input; err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0); } if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ + err = 0; /* Some parser didn't understand. */ if (err) return err; @@ -548,12 +548,12 @@ parser_init (struct parser *parser, const struct argp *argp, { parser->opt_data.opterr = 0; if (parser->state.flags & ARGP_PARSE_ARGV0) - /* getopt always skips ARGV[0], so we have to fake it out. As long - as OPTERR is 0, then it shouldn't actually try to access it. */ - parser->state.argv--, parser->state.argc++; + /* getopt always skips ARGV[0], so we have to fake it out. As long + as OPTERR is 0, then it shouldn't actually try to access it. */ + parser->state.argv--, parser->state.argc++; } else - parser->opt_data.opterr = 1; /* Print error messages. */ + parser->opt_data.opterr = 1; /* Print error messages. */ if (parser->state.argv == argv && argv[0]) /* There's an argv[0]; use it for messages. */ @@ -567,7 +567,7 @@ parser_init (struct parser *parser, const struct argp *argp, /* Free any storage consumed by PARSER (but not PARSER itself). */ static error_t parser_finalize (struct parser *parser, - error_t err, int arg_ebadkey, int *end_index) + error_t err, int arg_ebadkey, int *end_index) { struct group *group; @@ -578,40 +578,40 @@ parser_finalize (struct parser *parser, if (! err) { if (parser->state.next == parser->state.argc) - /* We successfully parsed all arguments! Call all the parsers again, - just a few more times... */ - { - for (group = parser->groups; - group < parser->egroup && (!err || err==EBADKEY); - group++) - if (group->args_processed == 0) - err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0); - for (group = parser->egroup - 1; - group >= parser->groups && (!err || err==EBADKEY); - group--) - err = group_parse (group, &parser->state, ARGP_KEY_END, 0); - - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - - /* Tell the user that all arguments are parsed. */ - if (end_index) - *end_index = parser->state.next; - } + /* We successfully parsed all arguments! Call all the parsers again, + just a few more times... */ + { + for (group = parser->groups; + group < parser->egroup && (!err || err==EBADKEY); + group++) + if (group->args_processed == 0) + err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0); + for (group = parser->egroup - 1; + group >= parser->groups && (!err || err==EBADKEY); + group--) + err = group_parse (group, &parser->state, ARGP_KEY_END, 0); + + if (err == EBADKEY) + err = 0; /* Some parser didn't understand. */ + + /* Tell the user that all arguments are parsed. */ + if (end_index) + *end_index = parser->state.next; + } else if (end_index) - /* Return any remaining arguments to the user. */ - *end_index = parser->state.next; + /* Return any remaining arguments to the user. */ + *end_index = parser->state.next; else - /* No way to return the remaining arguments, they must be bogus. */ - { - if (!(parser->state.flags & ARGP_NO_ERRS) - && parser->state.err_stream) - fprintf (parser->state.err_stream, - dgettext (parser->argp->argp_domain, - "%s: Too many arguments\n"), - parser->state.name); - err = EBADKEY; - } + /* No way to return the remaining arguments, they must be bogus. */ + { + if (!(parser->state.flags & ARGP_NO_ERRS) + && parser->state.err_stream) + fprintf (parser->state.err_stream, + dgettext (parser->argp->argp_domain, + "%s: Too many arguments\n"), + parser->state.name); + err = EBADKEY; + } } /* Okay, we're all done, with either an error or success; call the parsers @@ -621,27 +621,27 @@ parser_finalize (struct parser *parser, { /* Maybe print an error message. */ if (err == EBADKEY) - /* An appropriate message describing what the error was should have - been printed earlier. */ - __argp_state_help (&parser->state, parser->state.err_stream, - ARGP_HELP_STD_ERR); + /* An appropriate message describing what the error was should have + been printed earlier. */ + __argp_state_help (&parser->state, parser->state.err_stream, + ARGP_HELP_STD_ERR); /* Since we didn't exit, give each parser an error indication. */ for (group = parser->groups; group < parser->egroup; group++) - group_parse (group, &parser->state, ARGP_KEY_ERROR, 0); + group_parse (group, &parser->state, ARGP_KEY_ERROR, 0); } else /* Notify parsers of success, and propagate back values from parsers. */ { /* We pass over the groups in reverse order so that child groups are - given a chance to do there processing before passing back a value to - the parent. */ + given a chance to do there processing before passing back a value to + the parent. */ for (group = parser->egroup - 1 - ; group >= parser->groups && (!err || err == EBADKEY) - ; group--) - err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0); + ; group >= parser->groups && (!err || err == EBADKEY) + ; group--) + err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0); if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ + err = 0; /* Some parser didn't understand. */ } /* Call parsers once more, to do any final cleanup. Errors are ignored. */ @@ -669,42 +669,42 @@ parser_parse_arg (struct parser *parser, char *val) int index = --parser->state.next; error_t err = EBADKEY; struct group *group; - int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */ + int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */ /* Try to parse the argument in each parser. */ for (group = parser->groups ; group < parser->egroup && err == EBADKEY ; group++) { - parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */ + parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */ key = ARGP_KEY_ARG; err = group_parse (group, &parser->state, key, val); if (err == EBADKEY) - /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */ - { - parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */ - key = ARGP_KEY_ARGS; - err = group_parse (group, &parser->state, key, 0); - } + /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */ + { + parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */ + key = ARGP_KEY_ARGS; + err = group_parse (group, &parser->state, key, 0); + } } if (! err) { if (key == ARGP_KEY_ARGS) - /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't - changed by the user, *all* arguments should be considered - consumed. */ - parser->state.next = parser->state.argc; + /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't + changed by the user, *all* arguments should be considered + consumed. */ + parser->state.next = parser->state.argc; if (parser->state.next > index) - /* Remember that we successfully processed a non-option - argument -- but only if the user hasn't gotten tricky and set - the clock back. */ - (--group)->args_processed += (parser->state.next - index); + /* Remember that we successfully processed a non-option + argument -- but only if the user hasn't gotten tricky and set + the clock back. */ + (--group)->args_processed += (parser->state.next - index); else - /* The user wants to reparse some args, give getopt another try. */ - parser->try_getopt = 1; + /* The user wants to reparse some args, give getopt another try. */ + parser->try_getopt = 1; } return err; @@ -729,21 +729,21 @@ parser_parse_opt (struct parser *parser, int opt, char *val) char *short_index = strchr (parser->short_opts, opt); if (short_index) - for (group = parser->groups; group < parser->egroup; group++) - if (group->short_end > short_index) - { - err = group_parse (group, &parser->state, opt, - parser->opt_data.optarg); - break; - } + for (group = parser->groups; group < parser->egroup; group++) + if (group->short_end > short_index) + { + err = group_parse (group, &parser->state, opt, + parser->opt_data.optarg); + break; + } } else /* A long option. We use shifts instead of masking for extracting the user value in order to preserve the sign. */ err = group_parse (&parser->groups[group_key - 1], &parser->state, - (opt << GROUP_BITS) >> GROUP_BITS, - parser->opt_data.optarg); + (opt << GROUP_BITS) >> GROUP_BITS, + parser->opt_data.optarg); if (err == EBADKEY) /* At least currently, an option not recognized is an error in the @@ -751,19 +751,19 @@ parser_parse_opt (struct parser *parser, int opt, char *val) with each option. */ { static const char bad_key_err[] = - N_("(PROGRAM ERROR) Option should have been recognized!?"); + N_("(PROGRAM ERROR) Option should have been recognized!?"); if (group_key == 0) - __argp_error (&parser->state, "-%c: %s", opt, - dgettext (parser->argp->argp_domain, bad_key_err)); + __argp_error (&parser->state, "-%c: %s", opt, + dgettext (parser->argp->argp_domain, bad_key_err)); else - { - struct option *long_opt = parser->long_opts; - while (long_opt->val != opt && long_opt->name) - long_opt++; - __argp_error (&parser->state, "--%s: %s", - long_opt->name ? long_opt->name : "???", - dgettext (parser->argp->argp_domain, bad_key_err)); - } + { + struct option *long_opt = parser->long_opts; + while (long_opt->val != opt && long_opt->name) + long_opt++; + __argp_error (&parser->state, "--%s: %s", + long_opt->name ? long_opt->name : "???", + dgettext (parser->argp->argp_domain, bad_key_err)); + } } return err; @@ -794,38 +794,38 @@ parser_parse_next (struct parser *parser, int *arg_ebadkey) /* Distinguish KEY_ERR from a real option. */ parser->opt_data.optopt = KEY_END; if (parser->state.flags & ARGP_LONG_ONLY) - opt = _getopt_long_only_r (parser->state.argc, parser->state.argv, - parser->short_opts, parser->long_opts, 0, - &parser->opt_data); + opt = _getopt_long_only_r (parser->state.argc, parser->state.argv, + parser->short_opts, parser->long_opts, 0, + &parser->opt_data); else - opt = _getopt_long_r (parser->state.argc, parser->state.argv, - parser->short_opts, parser->long_opts, 0, - &parser->opt_data); + opt = _getopt_long_r (parser->state.argc, parser->state.argv, + parser->short_opts, parser->long_opts, 0, + &parser->opt_data); /* And see what getopt did. */ parser->state.next = parser->opt_data.optind; if (opt == KEY_END) - /* Getopt says there are no more options, so stop using - getopt; we'll continue if necessary on our own. */ - { - parser->try_getopt = 0; - if (parser->state.next > 1 - && strcmp (parser->state.argv[parser->state.next - 1], QUOTE) - == 0) - /* Not only is this the end of the options, but it's a - `quoted' region, which may have args that *look* like - options, so we definitely shouldn't try to use getopt past - here, whatever happens. */ - parser->state.quoted = parser->state.next; - } + /* Getopt says there are no more options, so stop using + getopt; we'll continue if necessary on our own. */ + { + parser->try_getopt = 0; + if (parser->state.next > 1 + && strcmp (parser->state.argv[parser->state.next - 1], QUOTE) + == 0) + /* Not only is this the end of the options, but it's a + `quoted' region, which may have args that *look* like + options, so we definitely shouldn't try to use getopt past + here, whatever happens. */ + parser->state.quoted = parser->state.next; + } else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END) - /* KEY_ERR can have the same value as a valid user short - option, but in the case of a real error, getopt sets OPTOPT - to the offending character, which can never be KEY_END. */ - { - *arg_ebadkey = 0; - return EBADKEY; - } + /* KEY_ERR can have the same value as a valid user short + option, but in the case of a real error, getopt sets OPTOPT + to the offending character, which can never be KEY_END. */ + { + *arg_ebadkey = 0; + return EBADKEY; + } } else opt = KEY_END; @@ -834,18 +834,18 @@ parser_parse_next (struct parser *parser, int *arg_ebadkey) { /* We're past what getopt considers the options. */ if (parser->state.next >= parser->state.argc - || (parser->state.flags & ARGP_NO_ARGS)) - /* Indicate that we're done. */ - { - *arg_ebadkey = 1; - return EBADKEY; - } + || (parser->state.flags & ARGP_NO_ARGS)) + /* Indicate that we're done. */ + { + *arg_ebadkey = 1; + return EBADKEY; + } else - /* A non-option arg; simulate what getopt might have done. */ - { - opt = KEY_ARG; - parser->opt_data.optarg = parser->state.argv[parser->state.next++]; - } + /* A non-option arg; simulate what getopt might have done. */ + { + opt = KEY_ARG; + parser->opt_data.optarg = parser->state.argv[parser->state.next++]; + } } if (opt == KEY_ARG) @@ -867,7 +867,7 @@ parser_parse_next (struct parser *parser, int *arg_ebadkey) returned a non-zero value, it is returned; otherwise 0 is returned. */ error_t __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, - int *end_index, void *input) + int *end_index, void *input) { error_t err; struct parser parser; @@ -881,11 +881,11 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, { #ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME if (!program_invocation_name) - program_invocation_name = argv[0]; + program_invocation_name = argv[0]; #endif #ifdef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME if (!program_invocation_short_name) - program_invocation_short_name = __argp_base_name (argv[0]); + program_invocation_short_name = __argp_base_name (argv[0]); #endif } #endif @@ -897,17 +897,17 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, struct argp *top_argp = alloca (sizeof (struct argp)); /* TOP_ARGP has no options, it just serves to group the user & default - argps. */ + argps. */ memset (top_argp, 0, sizeof (*top_argp)); top_argp->children = child; memset (child, 0, 4 * sizeof (struct argp_child)); if (argp) - (child++)->argp = argp; + (child++)->argp = argp; (child++)->argp = &argp_default_argp; if (argp_program_version || argp_program_version_hook) - (child++)->argp = &argp_version_argp; + (child++)->argp = &argp_version_argp; child->argp = 0; argp = top_argp; @@ -920,7 +920,7 @@ __argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, /* Parse! */ { while (! err) - err = parser_parse_next (&parser, &arg_ebadkey); + err = parser_parse_next (&parser, &arg_ebadkey); err = parser_finalize (&parser, err, arg_ebadkey, end_index); } @@ -941,8 +941,8 @@ __argp_input (const struct argp *argp, const struct argp_state *state) struct parser *parser = state->pstate; for (group = parser->groups; group < parser->egroup; group++) - if (group->argp == argp) - return group->input; + if (group->argp == argp) + return group->input; } return 0; diff --git a/lib/argp-version-etc.c b/lib/argp-version-etc.c index 2b9119579..ce3b47671 100644 --- a/lib/argp-version-etc.c +++ b/lib/argp-version-etc.c @@ -26,7 +26,7 @@ static void version_etc_hook (FILE *stream, struct argp_state *state) { version_etc_ar (stream, program_canonical_name, PACKAGE_NAME, VERSION, - program_authors); + program_authors); } void diff --git a/lib/argp-xinl.c b/lib/argp-xinl.c index 0904e9dc6..0fb674377 100644 --- a/lib/argp-xinl.c +++ b/lib/argp-xinl.c @@ -25,7 +25,7 @@ #endif #ifndef __USE_EXTERN_INLINES -# define __USE_EXTERN_INLINES 1 +# define __USE_EXTERN_INLINES 1 #endif #define ARGP_EI #undef __OPTIMIZE__ diff --git a/lib/argp.h b/lib/argp.h index 90c452831..a51b24ec6 100644 --- a/lib/argp.h +++ b/lib/argp.h @@ -112,15 +112,15 @@ struct argp_option }; /* The argument associated with this option is optional. */ -#define OPTION_ARG_OPTIONAL 0x1 +#define OPTION_ARG_OPTIONAL 0x1 /* This option isn't displayed in any help messages. */ -#define OPTION_HIDDEN 0x2 +#define OPTION_HIDDEN 0x2 /* This option is an alias for the closest previous non-alias option. This means that it will be displayed in the same help entry, and will inherit fields other than NAME and KEY from the aliased option. */ -#define OPTION_ALIAS 0x4 +#define OPTION_ALIAS 0x4 /* This option isn't actually an option (and so should be ignored by the actual option parser), but rather an arbitrary piece of documentation that @@ -133,7 +133,7 @@ struct argp_option ignored, except that if the first non-whitespace character is not `-', this entry is displayed after all options (and OPTION_DOC entries with a leading `-') in the same group. */ -#define OPTION_DOC 0x8 +#define OPTION_DOC 0x8 /* This option shouldn't be included in `long' usage messages (but is still included in help messages). This is mainly intended for options that are @@ -142,27 +142,27 @@ struct argp_option if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to distinguish these two cases, -x should probably be marked OPTION_NO_USAGE. */ -#define OPTION_NO_USAGE 0x10 +#define OPTION_NO_USAGE 0x10 /* Valid only in conjunction with OPTION_DOC. This option disables translation of option name. */ #define OPTION_NO_TRANS 0x20 -struct argp; /* fwd declare this type */ -struct argp_state; /* " */ -struct argp_child; /* " */ +struct argp; /* fwd declare this type */ +struct argp_state; /* " */ +struct argp_child; /* " */ /* The type of a pointer to an argp parsing function. */ typedef error_t (*argp_parser_t) (int key, char *arg, - struct argp_state *state); + struct argp_state *state); /* What to return for unrecognized keys. For special ARGP_KEY_ keys, such returns will simply be ignored. For user keys, this error will be turned into EINVAL (if the call to argp_parse is such that errors are propagated back to the user instead of exiting); returning EINVAL itself would result in an immediate stop to parsing in *all* cases. */ -#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */ +#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */ /* Special values for the KEY argument to an argument parsing function. ARGP_ERR_UNKNOWN should be returned if they aren't understood. @@ -190,32 +190,32 @@ typedef error_t (*argp_parser_t) (int key, char *arg, passed, the option won't be considered processed; this is to allow you to actually modify the argument (perhaps into an option), and have it processed again. */ -#define ARGP_KEY_ARG 0 +#define ARGP_KEY_ARG 0 /* There are remaining arguments not parsed by any parser, which may be found starting at (STATE->argv + STATE->next). If success is returned, but STATE->next left untouched, it's assumed that all arguments were consume, otherwise, the parser should adjust STATE->next to reflect any arguments consumed. */ -#define ARGP_KEY_ARGS 0x1000006 +#define ARGP_KEY_ARGS 0x1000006 /* There are no more command line arguments at all. */ -#define ARGP_KEY_END 0x1000001 +#define ARGP_KEY_END 0x1000001 /* Because it's common to want to do some special processing if there aren't any non-option args, user parsers are called with this key if they didn't successfully process any non-option arguments. Called just before ARGP_KEY_END (where more general validity checks on previously parsed arguments can take place). */ -#define ARGP_KEY_NO_ARGS 0x1000002 +#define ARGP_KEY_NO_ARGS 0x1000002 /* Passed in before any parsing is done. Afterwards, the values of each element of the CHILD_INPUT field, if any, in the state structure is copied to each child's state to be the initial value of the INPUT field. */ -#define ARGP_KEY_INIT 0x1000003 +#define ARGP_KEY_INIT 0x1000003 /* Use after all other keys, including SUCCESS & END. */ -#define ARGP_KEY_FINI 0x1000007 +#define ARGP_KEY_FINI 0x1000007 /* Passed in when parsing has successfully been completed (even if there are still arguments remaining). */ -#define ARGP_KEY_SUCCESS 0x1000004 +#define ARGP_KEY_SUCCESS 0x1000004 /* Passed in if an error occurs. */ -#define ARGP_KEY_ERROR 0x1000005 +#define ARGP_KEY_ERROR 0x1000005 /* An argp structure contains a set of options declarations, a function to deal with parsing one, documentation string, a possible vector of child @@ -279,15 +279,15 @@ struct argp }; /* Possible KEY arguments to a help filter function. */ -#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */ -#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */ -#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */ -#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation; - TEXT is NULL for this key. */ +#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */ +#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */ +#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */ +#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation; + TEXT is NULL for this key. */ /* Explanatory note emitted when duplicate option arguments have been suppressed. */ #define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005 -#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */ +#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */ /* When an argp has a non-zero CHILDREN field, it should point to a vector of argp_child structures, each of which describes a subsidiary argp. */ @@ -356,10 +356,10 @@ struct argp_state char *name; /* Streams used when argp prints something. */ - FILE *err_stream; /* For errors; initialized to stderr. */ - FILE *out_stream; /* For information; initialized to stdout. */ + FILE *err_stream; /* For errors; initialized to stderr. */ + FILE *out_stream; /* For information; initialized to stdout. */ - void *pstate; /* Private, for use by argp. */ + void *pstate; /* Private, for use by argp. */ }; /* Flags for argp_parse (note that the defaults are those that are @@ -375,7 +375,7 @@ struct argp_state is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program name in the error messages. This flag implies ARGP_NO_EXIT (on the assumption that silent exiting upon errors is bad behaviour). */ -#define ARGP_NO_ERRS 0x02 +#define ARGP_NO_ERRS 0x02 /* Don't parse any non-option args. Normally non-option args are parsed by calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg @@ -387,21 +387,21 @@ struct argp_state last time with a key of ARGP_KEY_END. This flag needn't normally be set, as the normal behavior is to stop parsing as soon as some argument can't be handled. */ -#define ARGP_NO_ARGS 0x04 +#define ARGP_NO_ARGS 0x04 /* Parse options and arguments in the same order they occur on the command line -- normally they're rearranged so that all options come first. */ -#define ARGP_IN_ORDER 0x08 +#define ARGP_IN_ORDER 0x08 /* Don't provide the standard long option --help, which causes usage and option help information to be output to stdout, and exit (0) called. */ -#define ARGP_NO_HELP 0x10 +#define ARGP_NO_HELP 0x10 /* Don't exit on errors (they may still result in error messages). */ -#define ARGP_NO_EXIT 0x20 +#define ARGP_NO_EXIT 0x20 /* Use the gnu getopt `long-only' rules for parsing arguments. */ -#define ARGP_LONG_ONLY 0x40 +#define ARGP_LONG_ONLY 0x40 /* Turns off any message-printing/exiting options. */ #define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP) @@ -414,13 +414,13 @@ struct argp_state returned. This function may also call exit unless the ARGP_NO_HELP flag is set. INPUT is a pointer to a value to be passed in to the parser. */ extern error_t argp_parse (const struct argp *__restrict __argp, - int /*argc*/, char **__restrict /*argv*/, - unsigned __flags, int *__restrict __arg_index, - void *__restrict __input); + int /*argc*/, char **__restrict /*argv*/, + unsigned __flags, int *__restrict __arg_index, + void *__restrict __input); extern error_t __argp_parse (const struct argp *__restrict __argp, - int /*argc*/, char **__restrict /*argv*/, - unsigned __flags, int *__restrict __arg_index, - void *__restrict __input); + int /*argc*/, char **__restrict /*argv*/, + unsigned __flags, int *__restrict __arg_index, + void *__restrict __input); /* Global variables. */ @@ -450,8 +450,8 @@ extern const char *argp_program_version; the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ extern void (*argp_program_version_hook) (FILE *__restrict __stream, - struct argp_state *__restrict - __state); + struct argp_state *__restrict + __state); /* If defined or set by the user program, it should point to string that is the bug-reporting address for the program. It will be printed by @@ -466,20 +466,20 @@ extern const char *argp_program_bug_address; extern error_t argp_err_exit_status; /* Flags for argp_help. */ -#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */ -#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */ -#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */ -#define ARGP_HELP_LONG 0x08 /* a long help message. */ -#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */ -#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */ -#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC) -#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */ -#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to - reflect ARGP_LONG_ONLY mode. */ +#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */ +#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */ +#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */ +#define ARGP_HELP_LONG 0x08 /* a long help message. */ +#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */ +#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */ +#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC) +#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */ +#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to + reflect ARGP_LONG_ONLY mode. */ /* These ARGP_HELP flags are only understood by argp_state_help. */ -#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */ -#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */ +#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */ +#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */ /* The standard thing to do after a program command line parsing error, if an error message has already been printed. */ @@ -497,11 +497,11 @@ extern error_t argp_err_exit_status; /* Output a usage message for ARGP to STREAM. FLAGS are from the set ARGP_HELP_*. */ extern void argp_help (const struct argp *__restrict __argp, - FILE *__restrict __stream, - unsigned __flags, char *__restrict __name); + FILE *__restrict __stream, + unsigned __flags, char *__restrict __name); extern void __argp_help (const struct argp *__restrict __argp, - FILE *__restrict __stream, unsigned __flags, - char *__name); + FILE *__restrict __stream, unsigned __flags, + char *__name); /* The following routines are intended to be called from within an argp parsing routine (thus taking an argp_state structure as the first @@ -514,11 +514,11 @@ extern void __argp_help (const struct argp *__restrict __argp, /* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are from the set ARGP_HELP_*. */ extern void argp_state_help (const struct argp_state *__restrict __state, - FILE *__restrict __stream, - unsigned int __flags); + FILE *__restrict __stream, + unsigned int __flags); extern void __argp_state_help (const struct argp_state *__restrict __state, - FILE *__restrict __stream, - unsigned int __flags); + FILE *__restrict __stream, + unsigned int __flags); #if _LIBC || !defined __USE_EXTERN_INLINES /* Possibly output the standard usage message for ARGP to stderr and exit. */ @@ -530,10 +530,10 @@ extern void __argp_usage (const struct argp_state *__state); by the program name and `:', to stderr, and followed by a `Try ... --help' message, then exit (1). */ extern void argp_error (const struct argp_state *__restrict __state, - const char *__restrict __fmt, ...) + const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); extern void __argp_error (const struct argp_state *__restrict __state, - const char *__restrict __fmt, ...) + const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); /* Similar to the standard gnu error-reporting function error(), but will @@ -545,12 +545,12 @@ extern void __argp_error (const struct argp_state *__restrict __state, *parsing errors*, and the former is for other problems that occur during parsing but don't reflect a (syntactic) problem with the input. */ extern void argp_failure (const struct argp_state *__restrict __state, - int __status, int __errnum, - const char *__restrict __fmt, ...) + int __status, int __errnum, + const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 4, 5))); extern void __argp_failure (const struct argp_state *__restrict __state, - int __status, int __errnum, - const char *__restrict __fmt, ...) + int __status, int __errnum, + const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 4, 5))); #if _LIBC || !defined __USE_EXTERN_INLINES @@ -567,10 +567,10 @@ extern int __option_is_end (const struct argp_option *__opt) __THROW; /* Return the input field for ARGP in the parser corresponding to STATE; used by the help routines. */ extern void *_argp_input (const struct argp *__restrict __argp, - const struct argp_state *__restrict __state) + const struct argp_state *__restrict __state) __THROW; extern void *__argp_input (const struct argp *__restrict __argp, - const struct argp_state *__restrict __state) + const struct argp_state *__restrict __state) __THROW; #ifdef __USE_EXTERN_INLINES diff --git a/lib/argz.c b/lib/argz.c index 8f5d1f57f..47caedc77 100644 --- a/lib/argz.c +++ b/lib/argz.c @@ -64,20 +64,20 @@ argz_add_sep (char **argz, size_t *argz_len, const char *string, int delim) *argz = (char *) realloc (*argz, *argz_len + nlen); if (*argz == NULL) - return ENOMEM; + return ENOMEM; wp = *argz + *argz_len; rp = string; do - if (*rp == delim) - { - if (wp > *argz && wp[-1] != '\0') - *wp++ = '\0'; - else - --nlen; - } - else - *wp++ = *rp; + if (*rp == delim) + { + if (wp > *argz && wp[-1] != '\0') + *wp++ = '\0'; + else + --nlen; + } + else + *wp++ = *rp; while (*rp++ != '\0'); *argz_len += nlen; @@ -100,28 +100,28 @@ argz_create_sep (const char *string, int delim, char **argz, size_t *len) *argz = (char *) malloc (nlen); if (*argz == NULL) - return ENOMEM; + return ENOMEM; rp = string; wp = *argz; do - if (*rp == delim) - { - if (wp > *argz && wp[-1] != '\0') - *wp++ = '\0'; - else - --nlen; - } - else - *wp++ = *rp; + if (*rp == delim) + { + if (wp > *argz && wp[-1] != '\0') + *wp++ = '\0'; + else + --nlen; + } + else + *wp++ = *rp; while (*rp++ != '\0'); if (nlen == 0) - { - free (*argz); - *argz = NULL; - *len = 0; - } + { + free (*argz); + *argz = NULL; + *len = 0; + } *len = nlen; } @@ -163,12 +163,12 @@ argz_insert (char **argz, size_t *argz_len, char *before, const char *entry) if (new_argz) { - before = new_argz + (before - *argz); - memmove (before + entry_len, before, after_before); - memmove (before, entry, entry_len); - *argz = new_argz; - *argz_len = new_argz_len; - return 0; + before = new_argz + (before - *argz); + memmove (before + entry_len, before, after_before); + memmove (before, entry, entry_len); + *argz = new_argz; + *argz_len = new_argz_len; + return 0; } else return ENOMEM; @@ -182,7 +182,7 @@ argz_next (const char *argz, size_t argz_len, const char *entry) if (entry) { if (entry < argz + argz_len) - entry = strchr (entry, '\0') + 1; + entry = strchr (entry, '\0') + 1; return entry >= argz + argz_len ? NULL : (char *) entry; } @@ -202,12 +202,12 @@ argz_stringify (char *argz, size_t len, int sep) if (len > 0) while (1) { - size_t part_len = strnlen (argz, len); - argz += part_len; - len -= part_len; - if (len-- <= 1) /* includes final '\0' we want to stop at */ - break; - *argz++ = sep; + size_t part_len = strnlen (argz, len); + argz += part_len; + len -= part_len; + if (len-- <= 1) /* includes final '\0' we want to stop at */ + break; + *argz++ = sep; } } @@ -264,10 +264,10 @@ argz_create (char *const argv[], char **argz, size_t *len) { *argz = malloc (tlen); if (*argz == NULL) - return ENOMEM; + return ENOMEM; for (p = *argz, ap = argv; *ap; ++ap, ++p) - p = stpcpy (p, *ap); + p = stpcpy (p, *ap); } *len = tlen; @@ -286,10 +286,10 @@ argz_delete (char **argz, size_t *argz_len, char *entry) *argz_len -= entry_len; memmove (entry, entry + entry_len, *argz_len - (entry - *argz)); if (*argz_len == 0) - { - free (*argz); - *argz = 0; - } + { + free (*argz); + *argz = 0; + } } } @@ -321,7 +321,7 @@ str_append (char **to, size_t *to_len, const char *buf, const size_t buf_len) incremented by number of replacements performed. */ error_t argz_replace (char **argz, size_t *argz_len, const char *str, const char *with, - unsigned *replace_count) + unsigned *replace_count) { error_t err = 0; @@ -332,74 +332,74 @@ argz_replace (char **argz, size_t *argz_len, const char *str, const char *with, size_t src_len = *argz_len; char *dst = 0; size_t dst_len = 0; - int delayed_copy = 1; /* True while we've avoided copying anything. */ + int delayed_copy = 1; /* True while we've avoided copying anything. */ size_t str_len = strlen (str), with_len = strlen (with); while (!err && (arg = argz_next (src, src_len, arg))) - { - char *match = strstr (arg, str); - if (match) - { - char *from = match + str_len; - size_t to_len = match - arg; - char *to = strndup (arg, to_len); - - while (to && from) - { - str_append (&to, &to_len, with, with_len); - if (to) - { - match = strstr (from, str); - if (match) - { - str_append (&to, &to_len, from, match - from); - from = match + str_len; - } - else - { - str_append (&to, &to_len, from, strlen (from)); - from = 0; - } - } - } - - if (to) - { - if (delayed_copy) - /* We avoided copying SRC to DST until we found a match; + { + char *match = strstr (arg, str); + if (match) + { + char *from = match + str_len; + size_t to_len = match - arg; + char *to = strndup (arg, to_len); + + while (to && from) + { + str_append (&to, &to_len, with, with_len); + if (to) + { + match = strstr (from, str); + if (match) + { + str_append (&to, &to_len, from, match - from); + from = match + str_len; + } + else + { + str_append (&to, &to_len, from, strlen (from)); + from = 0; + } + } + } + + if (to) + { + if (delayed_copy) + /* We avoided copying SRC to DST until we found a match; now that we've done so, copy everything from the start of SRC. */ - { - if (arg > src) - err = argz_append (&dst, &dst_len, src, (arg - src)); - delayed_copy = 0; - } - if (! err) - err = argz_add (&dst, &dst_len, to); - free (to); - } - else - err = ENOMEM; - - if (replace_count) - (*replace_count)++; - } - else if (! delayed_copy) - err = argz_add (&dst, &dst_len, arg); - } + { + if (arg > src) + err = argz_append (&dst, &dst_len, src, (arg - src)); + delayed_copy = 0; + } + if (! err) + err = argz_add (&dst, &dst_len, to); + free (to); + } + else + err = ENOMEM; + + if (replace_count) + (*replace_count)++; + } + else if (! delayed_copy) + err = argz_add (&dst, &dst_len, arg); + } if (! err) - { - if (! delayed_copy) - /* We never found any instances of str. */ - { - free (src); - *argz = dst; - *argz_len = dst_len; - } - } + { + if (! delayed_copy) + /* We never found any instances of str. */ + { + free (src); + *argz = dst; + *argz_len = dst_len; + } + } else if (dst_len > 0) - free (dst); + free (dst); } return err; diff --git a/lib/argz.in.h b/lib/argz.in.h index 696473d7d..ab41e76ce 100644 --- a/lib/argz.in.h +++ b/lib/argz.in.h @@ -16,12 +16,12 @@ along with this program. If not, see . */ #ifndef _ARGZ_H -#define _ARGZ_H 1 +#define _ARGZ_H 1 #define __need_error_t #include -#include /* Need size_t, and strchr is called below. */ +#include /* Need size_t, and strchr is called below. */ #ifndef const # define const const @@ -38,7 +38,7 @@ typedef int error_t; ENOMEM is returned, otherwise 0. The result can be destroyed using free. */ extern error_t argz_create (char *const __argv[], char **restrict __argz, - size_t *restrict __len); + size_t *restrict __len); /* Make a '\0' separated arg vector from a SEP separated list in STRING, returning it in ARGZ, and the total length in LEN. If a @@ -46,8 +46,8 @@ extern error_t argz_create (char *const __argv[], char **restrict __argz, The result can be destroyed using free. */ extern error_t argz_create_sep (const char *restrict string, - int __sep, char **restrict __argz, - size_t *restrict __len); + int __sep, char **restrict __argz, + size_t *restrict __len); /* Returns the number of strings in ARGZ. */ @@ -58,7 +58,7 @@ extern size_t argz_count (const char *__argz, size_t __len) to hold them all. */ extern void argz_extract (const char *restrict __argz, size_t __len, - char **restrict __argv); + char **restrict __argv); /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's except the last into the character SEP. */ @@ -68,29 +68,29 @@ extern void argz_stringify (char *__argz, size_t __len, int __sep); /* Append BUF, of length BUF_LEN to the argz vector in ARGZ & ARGZ_LEN. */ extern error_t argz_append (char **restrict __argz, - size_t *restrict __argz_len, - const char *restrict __buf, size_t __buf_len) + size_t *restrict __argz_len, + const char *restrict __buf, size_t __buf_len) ; /* Append STR to the argz vector in ARGZ & ARGZ_LEN. */ extern error_t argz_add (char **restrict __argz, - size_t *restrict __argz_len, - const char *restrict str); + size_t *restrict __argz_len, + const char *restrict str); /* Append SEP separated list in STRING to the argz vector in ARGZ & ARGZ_LEN. */ extern error_t argz_add_sep (char **restrict __argz, - size_t *restrict __argz_len, - const char *restrict string, int __delim) + size_t *restrict __argz_len, + const char *restrict string, int __delim) ; /* Delete ENTRY from ARGZ & ARGZ_LEN, if it appears there. */ extern void argz_delete (char **restrict __argz, - size_t *restrict __argz_len, - char *restrict __entry); + size_t *restrict __argz_len, + char *restrict __entry); /* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end. @@ -100,19 +100,19 @@ extern void argz_delete (char **restrict __argz, ARGZ, ENOMEM is returned, else 0. */ extern error_t argz_insert (char **restrict __argz, - size_t *restrict __argz_len, - char *restrict __before, - const char *restrict __entry); + size_t *restrict __argz_len, + char *restrict __before, + const char *restrict __entry); /* Replace any occurrences of the string STR in ARGZ with WITH, reallocating ARGZ as necessary. If REPLACE_COUNT is non-zero, *REPLACE_COUNT will be incremented by number of replacements performed. */ extern error_t argz_replace (char **restrict __argz, - size_t *restrict __argz_len, - const char *restrict str, - const char *restrict __with, - unsigned int *restrict __replace_count); + size_t *restrict __argz_len, + const char *restrict str, + const char *restrict __with, + unsigned int *restrict __replace_count); /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there are no more. If entry is NULL, then the first entry is returned. This @@ -130,17 +130,17 @@ extern error_t argz_replace (char **restrict __argz, */ extern char *argz_next (const char *restrict __argz, size_t __argz_len, - const char *restrict __entry); + const char *restrict __entry); #ifdef __USE_EXTERN_INLINES __extern_inline char * __NTH (argz_next (const char *__argz, size_t __argz_len, - const char *__entry)) + const char *__entry)) { if (__entry) { if (__entry < __argz + __argz_len) - __entry = strchr (__entry, '\0') + 1; + __entry = strchr (__entry, '\0') + 1; return __entry >= __argz + __argz_len ? (char *) NULL : (char *) __entry; } @@ -149,7 +149,7 @@ __NTH (argz_next (const char *__argz, size_t __argz_len, } __extern_inline char * __NTH (argz_next (const char *__argz, size_t __argz_len, - const char *__entry)) + const char *__entry)) { return argz_next (__argz, __argz_len, __entry); } diff --git a/lib/arpa_inet.in.h b/lib/arpa_inet.in.h index 315d9661f..26b60737f 100644 --- a/lib/arpa_inet.in.h +++ b/lib/arpa_inet.in.h @@ -60,7 +60,7 @@ extern "C" { For more details, see the POSIX:2001 specification . */ extern const char *inet_ntop (int af, const void *restrict src, - char *restrict dst, socklen_t cnt); + char *restrict dst, socklen_t cnt); # endif #elif defined GNULIB_POSIXCHECK # undef inet_ntop @@ -78,7 +78,7 @@ extern int inet_pton (int af, const char *restrict src, void *restrict dst); # undef inet_pton # define inet_pton(af,src,dst) \ (GL_LINK_WARNING ("inet_pton is unportable - " \ - "use gnulib module inet_pton for portability"), \ + "use gnulib module inet_pton for portability"), \ inet_pton (af, src, dst)) #endif diff --git a/lib/array-mergesort.h b/lib/array-mergesort.h index 3988d2891..908747b5c 100644 --- a/lib/array-mergesort.h +++ b/lib/array-mergesort.h @@ -47,40 +47,40 @@ merge (const ELEMENT *src1, size_t n1, for (;;) /* while (n1 > 0 && n2 > 0) */ { if (COMPARE (src1, src2) <= 0) - { - *dst++ = *src1++; - n1--; - if (n1 == 0) - break; - } + { + *dst++ = *src1++; + n1--; + if (n1 == 0) + break; + } else - { - *dst++ = *src2++; - n2--; - if (n2 == 0) - break; - } + { + *dst++ = *src2++; + n2--; + if (n2 == 0) + break; + } } /* Here n1 == 0 || n2 == 0 but also n1 > 0 || n2 > 0. */ if (n1 > 0) { if (dst != src1) - do - { - *dst++ = *src1++; - n1--; - } - while (n1 > 0); + do + { + *dst++ = *src1++; + n1--; + } + while (n1 > 0); } else /* n2 > 0 */ { if (dst != src2) - do - { - *dst++ = *src2++; - n2--; - } - while (n2 > 0); + do + { + *dst++ = *src2++; + n2--; + } + while (n2 > 0); } } @@ -101,79 +101,79 @@ merge_sort_fromto (const ELEMENT *src, ELEMENT *dst, size_t n, ELEMENT *tmp) case 2: /* Trivial case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - /* src[0] <= src[1] */ - dst[0] = src[0]; - dst[1] = src[1]; - } + { + /* src[0] <= src[1] */ + dst[0] = src[0]; + dst[1] = src[1]; + } else - { - dst[0] = src[1]; - dst[1] = src[0]; - } + { + dst[0] = src[1]; + dst[1] = src[0]; + } break; case 3: /* Simple case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[0] <= src[1] <= src[2] */ - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - } - else if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[0] <= src[2] < src[1] */ - dst[0] = src[0]; - dst[1] = src[2]; - dst[2] = src[1]; - } - else - { - /* src[2] < src[0] <= src[1] */ - dst[0] = src[2]; - dst[1] = src[0]; - dst[2] = src[1]; - } - } + { + if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[0] <= src[1] <= src[2] */ + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + } + else if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[0] <= src[2] < src[1] */ + dst[0] = src[0]; + dst[1] = src[2]; + dst[2] = src[1]; + } + else + { + /* src[2] < src[0] <= src[1] */ + dst[0] = src[2]; + dst[1] = src[0]; + dst[2] = src[1]; + } + } else - { - if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[1] < src[0] <= src[2] */ - dst[0] = src[1]; - dst[1] = src[0]; - dst[2] = src[2]; - } - else if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[1] <= src[2] < src[0] */ - dst[0] = src[1]; - dst[1] = src[2]; - dst[2] = src[0]; - } - else - { - /* src[2] < src[1] < src[0] */ - dst[0] = src[2]; - dst[1] = src[1]; - dst[2] = src[0]; - } - } + { + if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[1] < src[0] <= src[2] */ + dst[0] = src[1]; + dst[1] = src[0]; + dst[2] = src[2]; + } + else if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[1] <= src[2] < src[0] */ + dst[0] = src[1]; + dst[1] = src[2]; + dst[2] = src[0]; + } + else + { + /* src[2] < src[1] < src[0] */ + dst[0] = src[2]; + dst[1] = src[1]; + dst[2] = src[0]; + } + } break; default: { - size_t n1 = n / 2; - size_t n2 = (n + 1) / 2; - /* Note: n1 + n2 = n, n1 <= n2. */ - /* Sort src[n1..n-1] into dst[n1..n-1], scratching tmp[0..n2/2-1]. */ - merge_sort_fromto (src + n1, dst + n1, n2, tmp); - /* Sort src[0..n1-1] into tmp[0..n1-1], scratching dst[0..n1-1]. */ - merge_sort_fromto (src, tmp, n1, dst); - /* Merge the two half results. */ - merge (tmp, n1, dst + n1, n2, dst); + size_t n1 = n / 2; + size_t n2 = (n + 1) / 2; + /* Note: n1 + n2 = n, n1 <= n2. */ + /* Sort src[n1..n-1] into dst[n1..n-1], scratching tmp[0..n2/2-1]. */ + merge_sort_fromto (src + n1, dst + n1, n2, tmp); + /* Sort src[0..n1-1] into tmp[0..n1-1], scratching dst[0..n1-1]. */ + merge_sort_fromto (src, tmp, n1, dst); + /* Merge the two half results. */ + merge (tmp, n1, dst + n1, n2, dst); } break; } @@ -193,77 +193,77 @@ merge_sort_inplace (ELEMENT *src, size_t n, ELEMENT *tmp) case 2: /* Trivial case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - /* src[0] <= src[1] */ - } + { + /* src[0] <= src[1] */ + } else - { - ELEMENT t = src[0]; - src[0] = src[1]; - src[1] = t; - } + { + ELEMENT t = src[0]; + src[0] = src[1]; + src[1] = t; + } break; case 3: /* Simple case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[0] <= src[1] <= src[2] */ - } - else if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[0] <= src[2] < src[1] */ - ELEMENT t = src[1]; - src[1] = src[2]; - src[2] = t; - } - else - { - /* src[2] < src[0] <= src[1] */ - ELEMENT t = src[0]; - src[0] = src[2]; - src[2] = src[1]; - src[1] = t; - } - } + { + if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[0] <= src[1] <= src[2] */ + } + else if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[0] <= src[2] < src[1] */ + ELEMENT t = src[1]; + src[1] = src[2]; + src[2] = t; + } + else + { + /* src[2] < src[0] <= src[1] */ + ELEMENT t = src[0]; + src[0] = src[2]; + src[2] = src[1]; + src[1] = t; + } + } else - { - if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[1] < src[0] <= src[2] */ - ELEMENT t = src[0]; - src[0] = src[1]; - src[1] = t; - } - else if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[1] <= src[2] < src[0] */ - ELEMENT t = src[0]; - src[0] = src[1]; - src[1] = src[2]; - src[2] = t; - } - else - { - /* src[2] < src[1] < src[0] */ - ELEMENT t = src[0]; - src[0] = src[2]; - src[2] = t; - } - } + { + if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[1] < src[0] <= src[2] */ + ELEMENT t = src[0]; + src[0] = src[1]; + src[1] = t; + } + else if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[1] <= src[2] < src[0] */ + ELEMENT t = src[0]; + src[0] = src[1]; + src[1] = src[2]; + src[2] = t; + } + else + { + /* src[2] < src[1] < src[0] */ + ELEMENT t = src[0]; + src[0] = src[2]; + src[2] = t; + } + } break; default: { - size_t n1 = n / 2; - size_t n2 = (n + 1) / 2; - /* Note: n1 + n2 = n, n1 <= n2. */ - /* Sort src[n1..n-1], scratching tmp[0..n2-1]. */ - merge_sort_inplace (src + n1, n2, tmp); - /* Sort src[0..n1-1] into tmp[0..n1-1], scratching tmp[n1..2*n1-1]. */ - merge_sort_fromto (src, tmp, n1, tmp + n1); - /* Merge the two half results. */ - merge (tmp, n1, src + n1, n2, src); + size_t n1 = n / 2; + size_t n2 = (n + 1) / 2; + /* Note: n1 + n2 = n, n1 <= n2. */ + /* Sort src[n1..n-1], scratching tmp[0..n2-1]. */ + merge_sort_inplace (src + n1, n2, tmp); + /* Sort src[0..n1-1] into tmp[0..n1-1], scratching tmp[n1..2*n1-1]. */ + merge_sort_fromto (src, tmp, n1, tmp + n1); + /* Merge the two half results. */ + merge (tmp, n1, src + n1, n2, src); } break; } diff --git a/lib/asinl.c b/lib/asinl.c index 3b896fa39..5dee0cbc8 100644 --- a/lib/asinl.c +++ b/lib/asinl.c @@ -21,17 +21,17 @@ /* asin(x) * Method : - * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... - * we approximate asin(x) on [0,0.5] by - * asin(x) = x + x*x^2*R(x^2) + * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... + * we approximate asin(x) on [0,0.5] by + * asin(x) = x + x*x^2*R(x^2) * Between .5 and .625 the approximation is * asin(0.5625 + x) = asin(0.5625) + x rS(x) / sS(x) - * For x in [0.625,1] - * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) + * For x in [0.625,1] + * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) * * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. * */ @@ -43,7 +43,7 @@ static const long double pio2_lo = 4.3359050650618905123985220130216759843812E-35L, pio4_hi = 7.8539816339744830961566084581987569936977E-1L, - /* coefficient for R(x^2) */ + /* coefficient for R(x^2) */ /* asin(x) = x + x^3 pS(x^2) / qS(x^2) 0 <= x <= 0.5 @@ -114,19 +114,19 @@ asinl (long double x) y = -x; } - if (y >= 1.0L) /* |x|>= 1 */ + if (y >= 1.0L) /* |x|>= 1 */ { if (y == 1.0L) - /* asin(1)=+-pi/2 with inexact */ - return x * pio2_hi + x * pio2_lo; + /* asin(1)=+-pi/2 with inexact */ + return x * pio2_hi + x * pio2_lo; - return (x - x) / (x - x); /* asin(|x|>1) is NaN */ + return (x - x) / (x - x); /* asin(|x|>1) is NaN */ } else if (y < 0.5L) /* |x| < 0.5 */ { if (y < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2**-57 */ - if (huge + y > one) - return y; /* return x with inexact if x!=0 */ + if (huge + y > one) + return y; /* return x with inexact if x!=0 */ t = x * x; p = (((((((((pS9 * t @@ -158,28 +158,28 @@ asinl (long double x) { t = y - 0.5625; p = ((((((((((rS10 * t - + rS9) * t - + rS8) * t - + rS7) * t - + rS6) * t - + rS5) * t - + rS4) * t - + rS3) * t - + rS2) * t - + rS1) * t - + rS0) * t; + + rS9) * t + + rS8) * t + + rS7) * t + + rS6) * t + + rS5) * t + + rS4) * t + + rS3) * t + + rS2) * t + + rS1) * t + + rS0) * t; q = ((((((((( t - + sS9) * t - + sS8) * t - + sS7) * t - + sS6) * t - + sS5) * t - + sS4) * t - + sS3) * t - + sS2) * t - + sS1) * t - + sS0; + + sS9) * t + + sS8) * t + + sS7) * t + + sS6) * t + + sS5) * t + + sS4) * t + + sS3) * t + + sS2) * t + + sS1) * t + + sS0; t = asinr5625 + p / q; } else diff --git a/lib/at-func.c b/lib/at-func.c index 73be401a3..5034d598c 100644 --- a/lib/at-func.c +++ b/lib/at-func.c @@ -22,15 +22,15 @@ #include "save-cwd.h" #ifdef AT_FUNC_USE_F1_COND -# define CALL_FUNC(F) \ - (flag == AT_FUNC_USE_F1_COND \ - ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS) \ +# define CALL_FUNC(F) \ + (flag == AT_FUNC_USE_F1_COND \ + ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS) \ : AT_FUNC_F2 (F AT_FUNC_POST_FILE_ARGS)) -# define VALIDATE_FLAG(F) \ - if (flag & ~AT_FUNC_USE_F1_COND) \ - { \ - errno = EINVAL; \ - return FUNC_FAIL; \ +# define VALIDATE_FLAG(F) \ + if (flag & ~AT_FUNC_USE_F1_COND) \ + { \ + errno = EINVAL; \ + return FUNC_FAIL; \ } #else # define CALL_FUNC(F) (AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS)) diff --git a/lib/atanl.c b/lib/atanl.c index 19c52e134..22a882d4d 100644 --- a/lib/atanl.c +++ b/lib/atanl.c @@ -18,9 +18,9 @@ /* Specification. */ #include -/* s_atanl.c +/* s_atanl.c * - * Inverse circular tangent for 128-bit long double precision + * Inverse circular tangent for 128-bit long double precision * (arctangent) * * @@ -185,9 +185,9 @@ atanl (long double x) { /* Infinity. */ if (sign) - return -atantbl[83]; + return -atantbl[83]; else - return atantbl[83]; + return atantbl[83]; } if (sign) @@ -201,7 +201,7 @@ atanl (long double x) else { /* Index of nearest table element. - Roundoff to integer is asymmetrical to avoid cancellation when t < 0 + Roundoff to integer is asymmetrical to avoid cancellation when t < 0 (cf. fdlibm). */ k = 8.0 * x + 0.25; u = 0.125 * k; diff --git a/lib/backupfile.c b/lib/backupfile.c index f6cf73779..ea527f558 100644 --- a/lib/backupfile.c +++ b/lib/backupfile.c @@ -103,18 +103,18 @@ check_extension (char *file, size_t filelen, char e) long name_max; /* Temporarily modify the buffer into its parent directory name, - invoke pathconf on the directory, and then restore the buffer. */ + invoke pathconf on the directory, and then restore the buffer. */ char tmp[sizeof "."]; memcpy (tmp, base, sizeof "."); strcpy (base, "."); errno = 0; name_max = pathconf (file, _PC_NAME_MAX); if (0 <= name_max || errno == 0) - { - long size = baselen_max = name_max; - if (name_max != size) - baselen_max = SIZE_MAX; - } + { + long size = baselen_max = name_max; + if (name_max != size) + baselen_max = SIZE_MAX; + } memcpy (base, tmp, sizeof "."); } @@ -123,21 +123,21 @@ check_extension (char *file, size_t filelen, char e) /* Live within DOS's 8.3 limit. */ char *dot = strchr (base, '.'); if (!dot) - baselen_max = 8; + baselen_max = 8; else - { - char const *second_dot = strchr (dot + 1, '.'); - baselen_max = (second_dot - ? second_dot - base - : dot + 1 - base + 3); - } + { + char const *second_dot = strchr (dot + 1, '.'); + baselen_max = (second_dot + ? second_dot - base + : dot + 1 - base + 3); + } } if (baselen_max < baselen) { baselen = file + filelen - base; if (baselen_max <= baselen) - baselen = baselen_max - 1; + baselen = baselen_max - 1; base[baselen] = e; base[baselen + 1] = '\0'; } @@ -203,41 +203,41 @@ numbered_backup (char **buffer, size_t buffer_size, size_t filelen) size_t new_buflen; if (! REAL_DIR_ENTRY (dp) || _D_EXACT_NAMLEN (dp) < baselen + 4) - continue; + continue; if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0) - continue; + continue; p = dp->d_name + baselen + 2; /* Check whether this file has a version number and if so, - whether it is larger. Use string operations rather than - integer arithmetic, to avoid problems with integer overflow. */ + whether it is larger. Use string operations rather than + integer arithmetic, to avoid problems with integer overflow. */ if (! ('1' <= *p && *p <= '9')) - continue; + continue; all_9s = (*p == '9'); for (versionlen = 1; ISDIGIT (p[versionlen]); versionlen++) - all_9s &= (p[versionlen] == '9'); + all_9s &= (p[versionlen] == '9'); if (! (p[versionlen] == '~' && !p[versionlen + 1] - && (versionlenmax < versionlen - || (versionlenmax == versionlen - && memcmp (buf + filelen + 2, p, versionlen) <= 0)))) - continue; + && (versionlenmax < versionlen + || (versionlenmax == versionlen + && memcmp (buf + filelen + 2, p, versionlen) <= 0)))) + continue; /* This directory has the largest version number seen so far. - Append this highest numbered extension to the file name, - prepending '0' to the number if it is all 9s. */ + Append this highest numbered extension to the file name, + prepending '0' to the number if it is all 9s. */ versionlenmax = all_9s + versionlen; result = (all_9s ? BACKUP_IS_LONGER : BACKUP_IS_SAME_LENGTH); new_buflen = filelen + 2 + versionlenmax + 1; if (buffer_size <= new_buflen) - { - buf = xnrealloc (buf, 2, new_buflen); - buffer_size = new_buflen * 2; - } + { + buf = xnrealloc (buf, 2, new_buflen); + buffer_size = new_buflen * 2; + } q = buf + filelen; *q++ = '.'; *q++ = '~'; @@ -249,7 +249,7 @@ numbered_backup (char **buffer, size_t buffer_size, size_t filelen) q += versionlen; while (*--q == '9') - *q = '0'; + *q = '0'; ++*q; } @@ -286,15 +286,15 @@ find_backup_file_name (char const *file, enum backup_type backup_type) switch (numbered_backup (&s, ssize, filelen)) { case BACKUP_IS_SAME_LENGTH: - return s; + return s; case BACKUP_IS_LONGER: - simple = false; - break; + simple = false; + break; case BACKUP_IS_NEW: - simple = (backup_type == numbered_existing_backups); - break; + simple = (backup_type == numbered_existing_backups); + break; } if (simple) diff --git a/lib/backupfile.h b/lib/backupfile.h index 3cfdd8c68..dfc894d4d 100644 --- a/lib/backupfile.h +++ b/lib/backupfile.h @@ -41,7 +41,7 @@ enum backup_type numbered_backups }; -# define VALID_BACKUP_TYPE(Type) \ +# define VALID_BACKUP_TYPE(Type) \ ((unsigned int) (Type) <= numbered_backups) extern char const *simple_backup_suffix; diff --git a/lib/base64.c b/lib/base64.c index 8aff43002..8852f7d8d 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -67,7 +67,7 @@ to_uchar (char ch) terminate the output buffer. */ void base64_encode (const char *restrict in, size_t inlen, - char *restrict out, size_t outlen) + char *restrict out, size_t outlen) { static const char b64str[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -76,27 +76,27 @@ base64_encode (const char *restrict in, size_t inlen, { *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f]; if (!--outlen) - break; + break; *out++ = b64str[((to_uchar (in[0]) << 4) - + (--inlen ? to_uchar (in[1]) >> 4 : 0)) - & 0x3f]; + + (--inlen ? to_uchar (in[1]) >> 4 : 0)) + & 0x3f]; if (!--outlen) - break; + break; *out++ = - (inlen - ? b64str[((to_uchar (in[1]) << 2) - + (--inlen ? to_uchar (in[2]) >> 6 : 0)) - & 0x3f] - : '='); + (inlen + ? b64str[((to_uchar (in[1]) << 2) + + (--inlen ? to_uchar (in[2]) >> 6 : 0)) + & 0x3f] + : '='); if (!--outlen) - break; + break; *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '='; if (!--outlen) - break; + break; if (inlen) - inlen--; + inlen--; if (inlen) - in += 3; + in += 3; } if (outlen) @@ -153,71 +153,71 @@ base64_encode_alloc (const char *in, size_t inlen, char **out) IBM C V6 for AIX mishandles "#define B64(x) ...'x'...", so use "_" as the formal parameter rather than "x". */ -#define B64(_) \ - ((_) == 'A' ? 0 \ - : (_) == 'B' ? 1 \ - : (_) == 'C' ? 2 \ - : (_) == 'D' ? 3 \ - : (_) == 'E' ? 4 \ - : (_) == 'F' ? 5 \ - : (_) == 'G' ? 6 \ - : (_) == 'H' ? 7 \ - : (_) == 'I' ? 8 \ - : (_) == 'J' ? 9 \ - : (_) == 'K' ? 10 \ - : (_) == 'L' ? 11 \ - : (_) == 'M' ? 12 \ - : (_) == 'N' ? 13 \ - : (_) == 'O' ? 14 \ - : (_) == 'P' ? 15 \ - : (_) == 'Q' ? 16 \ - : (_) == 'R' ? 17 \ - : (_) == 'S' ? 18 \ - : (_) == 'T' ? 19 \ - : (_) == 'U' ? 20 \ - : (_) == 'V' ? 21 \ - : (_) == 'W' ? 22 \ - : (_) == 'X' ? 23 \ - : (_) == 'Y' ? 24 \ - : (_) == 'Z' ? 25 \ - : (_) == 'a' ? 26 \ - : (_) == 'b' ? 27 \ - : (_) == 'c' ? 28 \ - : (_) == 'd' ? 29 \ - : (_) == 'e' ? 30 \ - : (_) == 'f' ? 31 \ - : (_) == 'g' ? 32 \ - : (_) == 'h' ? 33 \ - : (_) == 'i' ? 34 \ - : (_) == 'j' ? 35 \ - : (_) == 'k' ? 36 \ - : (_) == 'l' ? 37 \ - : (_) == 'm' ? 38 \ - : (_) == 'n' ? 39 \ - : (_) == 'o' ? 40 \ - : (_) == 'p' ? 41 \ - : (_) == 'q' ? 42 \ - : (_) == 'r' ? 43 \ - : (_) == 's' ? 44 \ - : (_) == 't' ? 45 \ - : (_) == 'u' ? 46 \ - : (_) == 'v' ? 47 \ - : (_) == 'w' ? 48 \ - : (_) == 'x' ? 49 \ - : (_) == 'y' ? 50 \ - : (_) == 'z' ? 51 \ - : (_) == '0' ? 52 \ - : (_) == '1' ? 53 \ - : (_) == '2' ? 54 \ - : (_) == '3' ? 55 \ - : (_) == '4' ? 56 \ - : (_) == '5' ? 57 \ - : (_) == '6' ? 58 \ - : (_) == '7' ? 59 \ - : (_) == '8' ? 60 \ - : (_) == '9' ? 61 \ - : (_) == '+' ? 62 \ - : (_) == '/' ? 63 \ +#define B64(_) \ + ((_) == 'A' ? 0 \ + : (_) == 'B' ? 1 \ + : (_) == 'C' ? 2 \ + : (_) == 'D' ? 3 \ + : (_) == 'E' ? 4 \ + : (_) == 'F' ? 5 \ + : (_) == 'G' ? 6 \ + : (_) == 'H' ? 7 \ + : (_) == 'I' ? 8 \ + : (_) == 'J' ? 9 \ + : (_) == 'K' ? 10 \ + : (_) == 'L' ? 11 \ + : (_) == 'M' ? 12 \ + : (_) == 'N' ? 13 \ + : (_) == 'O' ? 14 \ + : (_) == 'P' ? 15 \ + : (_) == 'Q' ? 16 \ + : (_) == 'R' ? 17 \ + : (_) == 'S' ? 18 \ + : (_) == 'T' ? 19 \ + : (_) == 'U' ? 20 \ + : (_) == 'V' ? 21 \ + : (_) == 'W' ? 22 \ + : (_) == 'X' ? 23 \ + : (_) == 'Y' ? 24 \ + : (_) == 'Z' ? 25 \ + : (_) == 'a' ? 26 \ + : (_) == 'b' ? 27 \ + : (_) == 'c' ? 28 \ + : (_) == 'd' ? 29 \ + : (_) == 'e' ? 30 \ + : (_) == 'f' ? 31 \ + : (_) == 'g' ? 32 \ + : (_) == 'h' ? 33 \ + : (_) == 'i' ? 34 \ + : (_) == 'j' ? 35 \ + : (_) == 'k' ? 36 \ + : (_) == 'l' ? 37 \ + : (_) == 'm' ? 38 \ + : (_) == 'n' ? 39 \ + : (_) == 'o' ? 40 \ + : (_) == 'p' ? 41 \ + : (_) == 'q' ? 42 \ + : (_) == 'r' ? 43 \ + : (_) == 's' ? 44 \ + : (_) == 't' ? 45 \ + : (_) == 'u' ? 46 \ + : (_) == 'v' ? 47 \ + : (_) == 'w' ? 48 \ + : (_) == 'x' ? 49 \ + : (_) == 'y' ? 50 \ + : (_) == 'z' ? 51 \ + : (_) == '0' ? 52 \ + : (_) == '1' ? 53 \ + : (_) == '2' ? 54 \ + : (_) == '3' ? 55 \ + : (_) == '4' ? 56 \ + : (_) == '5' ? 57 \ + : (_) == '6' ? 58 \ + : (_) == '7' ? 59 \ + : (_) == '8' ? 60 \ + : (_) == '9' ? 61 \ + : (_) == '+' ? 62 \ + : (_) == '/' ? 63 \ : -1) static const signed char b64[0x100] = { @@ -328,12 +328,12 @@ get_4 (struct base64_decode_context *ctx, { char const *t = *in; if (4 <= in_end - *in && memchr (t, '\n', 4) == NULL) - { - /* This is the common case: no newline. */ - *in += 4; - *n_non_newline = 4; - return (char *) t; - } + { + /* This is the common case: no newline. */ + *in += 4; + *n_non_newline = 4; + return (char *) t; + } } { @@ -341,13 +341,13 @@ get_4 (struct base64_decode_context *ctx, char const *p = *in; while (p < in_end) { - char c = *p++; - if (c != '\n') - { - ctx->buf[ctx->i++] = c; - if (ctx->i == 4) - break; - } + char c = *p++; + if (c != '\n') + { + ctx->buf[ctx->i++] = c; + if (ctx->i == 4) + break; + } } *in = p; @@ -356,12 +356,12 @@ get_4 (struct base64_decode_context *ctx, } } -#define return_false \ - do \ - { \ - *outp = out; \ - return false; \ - } \ +#define return_false \ + do \ + { \ + *outp = out; \ + return false; \ + } \ while (false) /* Decode up to four bytes of base64-encoded data, IN, of length INLEN @@ -372,7 +372,7 @@ get_4 (struct base64_decode_context *ctx, *OUTLEN to reflect the number of bytes remaining in *OUT. */ static inline bool decode_4 (char const *restrict in, size_t inlen, - char *restrict *outp, size_t *outleft) + char *restrict *outp, size_t *outleft) { char *out = *outp; if (inlen < 2) @@ -384,7 +384,7 @@ decode_4 (char const *restrict in, size_t inlen, if (*outleft) { *out++ = ((b64[to_uchar (in[0])] << 2) - | (b64[to_uchar (in[1])] >> 4)); + | (b64[to_uchar (in[1])] >> 4)); --*outleft; } @@ -394,43 +394,43 @@ decode_4 (char const *restrict in, size_t inlen, if (in[2] == '=') { if (inlen != 4) - return_false; + return_false; if (in[3] != '=') - return_false; + return_false; } else { if (!isbase64 (in[2])) - return_false; + return_false; if (*outleft) - { - *out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0) - | (b64[to_uchar (in[2])] >> 2)); - --*outleft; - } + { + *out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0) + | (b64[to_uchar (in[2])] >> 2)); + --*outleft; + } if (inlen == 3) - return_false; + return_false; if (in[3] == '=') - { - if (inlen != 4) - return_false; - } + { + if (inlen != 4) + return_false; + } else - { - if (!isbase64 (in[3])) - return_false; - - if (*outleft) - { - *out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0) - | b64[to_uchar (in[3])]); - --*outleft; - } - } + { + if (!isbase64 (in[3])) + return_false; + + if (*outleft) + { + *out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0) + | b64[to_uchar (in[3])]); + --*outleft; + } + } } *outp = out; @@ -457,8 +457,8 @@ decode_4 (char const *restrict in, size_t inlen, bool base64_decode_ctx (struct base64_decode_context *ctx, - const char *restrict in, size_t inlen, - char *restrict out, size_t *outlen) + const char *restrict in, size_t inlen, + char *restrict out, size_t *outlen) { size_t outleft = *outlen; bool ignore_newlines = ctx != NULL; @@ -476,57 +476,57 @@ base64_decode_ctx (struct base64_decode_context *ctx, { size_t outleft_save = outleft; if (ctx_i == 0 && !flush_ctx) - { - while (true) - { - /* Save a copy of outleft, in case we need to re-parse this - block of four bytes. */ - outleft_save = outleft; - if (!decode_4 (in, inlen, &out, &outleft)) - break; - - in += 4; - inlen -= 4; - } - } + { + while (true) + { + /* Save a copy of outleft, in case we need to re-parse this + block of four bytes. */ + outleft_save = outleft; + if (!decode_4 (in, inlen, &out, &outleft)) + break; + + in += 4; + inlen -= 4; + } + } if (inlen == 0 && !flush_ctx) - break; + break; /* Handle the common case of 72-byte wrapped lines. - This also handles any other multiple-of-4-byte wrapping. */ + This also handles any other multiple-of-4-byte wrapping. */ if (inlen && *in == '\n' && ignore_newlines) - { - ++in; - --inlen; - continue; - } + { + ++in; + --inlen; + continue; + } /* Restore OUT and OUTLEFT. */ out -= outleft_save - outleft; outleft = outleft_save; { - char const *in_end = in + inlen; - char const *non_nl; - - if (ignore_newlines) - non_nl = get_4 (ctx, &in, in_end, &inlen); - else - non_nl = in; /* Might have nl in this case. */ - - /* If the input is empty or consists solely of newlines (0 non-newlines), - then we're done. Likewise if there are fewer than 4 bytes when not - flushing context and not treating newlines as garbage. */ - if (inlen == 0 || (inlen < 4 && !flush_ctx && ignore_newlines)) - { - inlen = 0; - break; - } - if (!decode_4 (non_nl, inlen, &out, &outleft)) - break; - - inlen = in_end - in; + char const *in_end = in + inlen; + char const *non_nl; + + if (ignore_newlines) + non_nl = get_4 (ctx, &in, in_end, &inlen); + else + non_nl = in; /* Might have nl in this case. */ + + /* If the input is empty or consists solely of newlines (0 non-newlines), + then we're done. Likewise if there are fewer than 4 bytes when not + flushing context and not treating newlines as garbage. */ + if (inlen == 0 || (inlen < 4 && !flush_ctx && ignore_newlines)) + { + inlen = 0; + break; + } + if (!decode_4 (non_nl, inlen, &out, &outleft)) + break; + + inlen = in_end - in; } } @@ -548,8 +548,8 @@ base64_decode_ctx (struct base64_decode_context *ctx, undefined. */ bool base64_decode_alloc_ctx (struct base64_decode_context *ctx, - const char *in, size_t inlen, char **out, - size_t *outlen) + const char *in, size_t inlen, char **out, + size_t *outlen) { /* This may allocate a few bytes too many, depending on input, but it's not worth the extra CPU time to compute the exact size. diff --git a/lib/base64.h b/lib/base64.h index 9c31651e4..406496ea7 100644 --- a/lib/base64.h +++ b/lib/base64.h @@ -38,24 +38,24 @@ struct base64_decode_context extern bool isbase64 (char ch); extern void base64_encode (const char *restrict in, size_t inlen, - char *restrict out, size_t outlen); + char *restrict out, size_t outlen); extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out); extern void base64_decode_ctx_init (struct base64_decode_context *ctx); extern bool base64_decode_ctx (struct base64_decode_context *ctx, - const char *restrict in, size_t inlen, - char *restrict out, size_t *outlen); + const char *restrict in, size_t inlen, + char *restrict out, size_t *outlen); extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx, - const char *in, size_t inlen, - char **out, size_t *outlen); + const char *in, size_t inlen, + char **out, size_t *outlen); #define base64_decode(in, inlen, out, outlen) \ - base64_decode_ctx (NULL, in, inlen, out, outlen) + base64_decode_ctx (NULL, in, inlen, out, outlen) #define base64_decode_alloc(in, inlen, out, outlen) \ - base64_decode_alloc_ctx (NULL, in, inlen, out, outlen) + base64_decode_alloc_ctx (NULL, in, inlen, out, outlen) #endif /* BASE64_H */ diff --git a/lib/btowc.c b/lib/btowc.c index 7f3b9663c..61020e015 100644 --- a/lib/btowc.c +++ b/lib/btowc.c @@ -32,7 +32,7 @@ btowc (int c) buf[0] = c; if (mbtowc (&wc, buf, 1) >= 0) - return wc; + return wc; } return WEOF; } diff --git a/lib/byteswap.in.h b/lib/byteswap.in.h index 91bf919fc..031431a2f 100644 --- a/lib/byteswap.in.h +++ b/lib/byteswap.in.h @@ -21,24 +21,24 @@ /* Given an unsigned 16-bit argument X, return the value corresponding to X with reversed byte order. */ #define bswap_16(x) ((((x) & 0x00FF) << 8) | \ - (((x) & 0xFF00) >> 8)) + (((x) & 0xFF00) >> 8)) /* Given an unsigned 32-bit argument X, return the value corresponding to X with reversed byte order. */ #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ - (((x) & 0x0000FF00) << 8) | \ - (((x) & 0x00FF0000) >> 8) | \ - (((x) & 0xFF000000) >> 24)) + (((x) & 0x0000FF00) << 8) | \ + (((x) & 0x00FF0000) >> 8) | \ + (((x) & 0xFF000000) >> 24)) /* Given an unsigned 64-bit argument X, return the value corresponding to X with reversed byte order. */ #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ - (((x) & 0x000000000000FF00ULL) << 40) | \ - (((x) & 0x0000000000FF0000ULL) << 24) | \ - (((x) & 0x00000000FF000000ULL) << 8) | \ - (((x) & 0x000000FF00000000ULL) >> 8) | \ - (((x) & 0x0000FF0000000000ULL) >> 24) | \ - (((x) & 0x00FF000000000000ULL) >> 40) | \ - (((x) & 0xFF00000000000000ULL) >> 56)) + (((x) & 0x000000000000FF00ULL) << 40) | \ + (((x) & 0x0000000000FF0000ULL) << 24) | \ + (((x) & 0x00000000FF000000ULL) << 8) | \ + (((x) & 0x000000FF00000000ULL) >> 8) | \ + (((x) & 0x0000FF0000000000ULL) >> 24) | \ + (((x) & 0x00FF000000000000ULL) >> 40) | \ + (((x) & 0xFF00000000000000ULL) >> 56)) #endif /* _GL_BYTESWAP_H */ diff --git a/lib/c-stack.c b/lib/c-stack.c index 1ee356074..36f84d0d9 100644 --- a/lib/c-stack.c +++ b/lib/c-stack.c @@ -151,7 +151,7 @@ static volatile int segv_handler_missing; overflow. This function is async-signal-safe. */ static int segv_handler (void *address __attribute__ ((unused)), - int serious) + int serious) { # if DEBUG { @@ -175,13 +175,13 @@ static void overflow_handler (int, stackoverflow_context_t) __attribute__ ((noreturn)); static void overflow_handler (int emergency, - stackoverflow_context_t context __attribute__ ((unused))) + 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); + emergency, segv_handler_missing); write (STDERR_FILENO, buf, strlen (buf)); } # endif @@ -236,7 +236,7 @@ find_stack_direction (char const *addr) static void segv_handler (int, siginfo_t *, void *) __attribute__((noreturn)); static void segv_handler (int signo, siginfo_t *info, - void *context __attribute__ ((unused))) + void *context __attribute__ ((unused))) { /* Clear SIGNO if it seems to have been a stack overflow. */ # if ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC @@ -255,8 +255,8 @@ segv_handler (int signo, siginfo_t *info, if (0 < info->si_code) { /* If the faulting address is within the stack, or within one - page of the stack end, assume that it is a stack - overflow. */ + page of the stack end, 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; @@ -264,18 +264,18 @@ segv_handler (int signo, siginfo_t *info, size_t s = faulting_address - stack_base; size_t page_size = sysconf (_SC_PAGESIZE); if (find_stack_direction (NULL) < 0) - s += page_size; + s += page_size; if (s < stack_size + page_size) - signo = 0; + 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)); + 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 } @@ -330,7 +330,7 @@ c_stack_action (void (*action) (int)) } #else /* ! ((HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK - && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV) */ + && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV) */ int c_stack_action (void (*action) (int) __attribute__ ((unused))) diff --git a/lib/c-strcasecmp.c b/lib/c-strcasecmp.c index 13b15f989..2fe7d1caf 100644 --- a/lib/c-strcasecmp.c +++ b/lib/c-strcasecmp.c @@ -40,7 +40,7 @@ c_strcasecmp (const char *s1, const char *s2) c2 = c_tolower (*p2); if (c1 == '\0') - break; + break; ++p1; ++p2; diff --git a/lib/c-strcasestr.c b/lib/c-strcasestr.c index 0185ba950..6c8a858ef 100644 --- a/lib/c-strcasestr.c +++ b/lib/c-strcasestr.c @@ -28,11 +28,11 @@ /* Two-Way algorithm. */ #define RETURN_TYPE char * -#define AVAILABLE(h, h_l, j, n_l) \ - (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ +#define AVAILABLE(h, h_l, j, n_l) \ + (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ && ((h_l) = (j) + (n_l))) #define CANON_ELEMENT c_tolower -#define CMP_FUNC(p1, p2, l) \ +#define CMP_FUNC(p1, p2, l) \ c_strncasecmp ((const char *) (p1), (const char *) (p2), l) #include "str-two-way.h" @@ -52,7 +52,7 @@ c_strcasestr (const char *haystack_start, const char *needle_start) NEEDLE if HAYSTACK is too short). */ while (*haystack && *needle) ok &= (c_tolower ((unsigned char) *haystack++) - == c_tolower ((unsigned char) *needle++)); + == c_tolower ((unsigned char) *needle++)); if (*needle) return NULL; if (ok) @@ -66,12 +66,12 @@ c_strcasestr (const char *haystack_start, const char *needle_start) 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_start, - needle_len); + haystack_len, + (const unsigned char *) needle_start, + needle_len); return two_way_long_needle ((const unsigned char *) haystack, haystack_len, - (const unsigned char *) needle_start, - needle_len); + (const unsigned char *) needle_start, + needle_len); } #undef LONG_NEEDLE_THRESHOLD diff --git a/lib/c-strncasecmp.c b/lib/c-strncasecmp.c index 274e9b7ea..d1aec3687 100644 --- a/lib/c-strncasecmp.c +++ b/lib/c-strncasecmp.c @@ -40,7 +40,7 @@ c_strncasecmp (const char *s1, const char *s2, size_t n) c2 = c_tolower (*p2); if (--n == 0 || c1 == '\0') - break; + break; ++p1; ++p2; diff --git a/lib/c-strtod.c b/lib/c-strtod.c index 51e996e5d..8c75043f3 100644 --- a/lib/c-strtod.c +++ b/lib/c-strtod.c @@ -73,7 +73,7 @@ C_STRTOD (char const *nptr, char **endptr) if (!locale) { if (endptr) - *endptr = (char *) nptr; + *endptr = (char *) nptr; return 0; /* errno is set here */ } @@ -87,11 +87,11 @@ C_STRTOD (char const *nptr, char **endptr) { saved_locale = strdup (saved_locale); if (saved_locale == NULL) - { - if (endptr) - *endptr = (char *) nptr; - return 0; /* errno is set here */ - } + { + if (endptr) + *endptr = (char *) nptr; + return 0; /* errno is set here */ + } setlocale (LC_NUMERIC, "C"); } diff --git a/lib/calloc.c b/lib/calloc.c index 554a58da9..12b0ef51f 100644 --- a/lib/calloc.c +++ b/lib/calloc.c @@ -49,13 +49,13 @@ rpl_calloc (size_t n, size_t s) else { /* Defend against buggy calloc implementations that mishandle - size_t overflow. */ + size_t overflow. */ size_t bytes = n * s; if (bytes / s != n) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } } #endif diff --git a/lib/canon-host.c b/lib/canon-host.c index df9cbbfb2..cd144ace0 100644 --- a/lib/canon-host.c +++ b/lib/canon-host.c @@ -69,11 +69,11 @@ canon_host_r (char const *host, int *cherror) if (!status) { /* http://lists.gnu.org/archive/html/bug-coreutils/2006-09/msg00300.html - says Darwin 7.9.0 getaddrinfo returns 0 but sets - res->ai_canonname to NULL. */ + says Darwin 7.9.0 getaddrinfo returns 0 but sets + res->ai_canonname to NULL. */ retval = strdup (res->ai_canonname ? res->ai_canonname : host); if (!retval && cherror) - *cherror = EAI_MEMORY; + *cherror = EAI_MEMORY; freeaddrinfo (res); } else if (cherror) diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index fa310fb59..c71721eaa 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -94,9 +94,9 @@ __realpath (const char *name, char *resolved) 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. */ + 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; } @@ -104,7 +104,7 @@ __realpath (const char *name, char *resolved) if (name[0] == '\0') { /* As per Single Unix Specification V2 we must return an error if - the name argument points to an empty string. */ + the name argument points to an empty string. */ __set_errno (ENOENT); return NULL; } @@ -121,12 +121,12 @@ __realpath (const char *name, char *resolved) { 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; - } + { + /* It's easier to set errno to ENOMEM than to rely on the + 'malloc-posix' gnulib module. */ + errno = ENOMEM; + return NULL; + } } else rpath = resolved; @@ -135,10 +135,10 @@ __realpath (const char *name, char *resolved) if (name[0] != '/') { if (!__getcwd (rpath, path_max)) - { - rpath[0] = '\0'; - goto error; - } + { + rpath[0] = '\0'; + goto error; + } dest = strchr (rpath, '\0'); } else @@ -146,7 +146,7 @@ __realpath (const char *name, char *resolved) rpath[0] = '/'; dest = rpath + 1; if (DOUBLE_SLASH_IS_DISTINCT_ROOT && name[1] == '/') - *dest++ = '/'; + *dest++ = '/'; } for (start = end = name; *start; start = end) @@ -160,153 +160,153 @@ __realpath (const char *name, char *resolved) /* Skip sequence of multiple path-separators. */ while (*start == '/') - ++start; + ++start; /* Find end of path component. */ for (end = start; *end && *end != '/'; ++end) - /* Nothing. */; + /* Nothing. */; if (end - start == 0) - break; + break; else if (end - start == 1 && start[0] == '.') - /* nothing */; + /* nothing */; else if (end - start == 2 && start[0] == '.' && start[1] == '.') - { - /* Back up to previous component, ignore if at root already. */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 - && *dest == '/') - dest++; - } + { + /* Back up to previous component, ignore if at root already. */ + if (dest > rpath + 1) + while ((--dest)[-1] != '/'); + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 + && *dest == '/') + dest++; + } else - { - size_t new_size; - - if (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 + 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; - } + { + size_t new_size; + + if (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 + 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); + dest = __mempcpy (dest, start, end - start); #else - memcpy (dest, start, end - start); - dest += end - start; + memcpy (dest, start, end - start); + dest += end - start; #endif - *dest = '\0'; + *dest = '\0'; #ifdef _LIBC - if (__lxstat64 (_STAT_VER, rpath, &st) < 0) + if (__lxstat64 (_STAT_VER, rpath, &st) < 0) #else - if (lstat (rpath, &st) < 0) + 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 (buf[0] == '/') - { - dest = rpath + 1; /* It's an absolute symlink */ - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && buf[1] == '/') - *dest++ = '/'; - } - else - { - /* Back up to previous component, ignore if at root - already: */ - if (dest > rpath + 1) - while ((--dest)[-1] != '/'); - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 - && *dest == '/') - dest++; - } - } - else if (!S_ISDIR (st.st_mode) && *end != '\0') - { - __set_errno (ENOTDIR); - goto error; - } - } + 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 (buf[0] == '/') + { + dest = rpath + 1; /* It's an absolute symlink */ + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && buf[1] == '/') + *dest++ = '/'; + } + else + { + /* Back up to previous component, ignore if at root + already: */ + if (dest > rpath + 1) + while ((--dest)[-1] != '/'); + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 + && *dest == '/') + dest++; + } + } + else if (!S_ISDIR (st.st_mode) && *end != '\0') + { + __set_errno (ENOTDIR); + goto error; + } + } } if (dest > rpath + 1 && dest[-1] == '/') --dest; diff --git a/lib/canonicalize.c b/lib/canonicalize.c index 65e73a703..2f008e068 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -35,7 +35,7 @@ # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 #endif -#if !((HAVE_CANONICALIZE_FILE_NAME && FUNC_REALPATH_WORKS) \ +#if !((HAVE_CANONICALIZE_FILE_NAME && FUNC_REALPATH_WORKS) \ || GNULIB_CANONICALIZE_LGPL) /* Return the canonical absolute name of file NAME. A canonical name does not contain any `.', `..' components nor any repeated file name @@ -58,12 +58,12 @@ seen_triple (Hash_table **ht, char const *filename, struct stat const *st) { size_t initial_capacity = 7; *ht = hash_initialize (initial_capacity, - NULL, - triple_hash, - triple_compare_ino_str, - triple_free); + NULL, + triple_hash, + triple_compare_ino_str, + triple_free); if (*ht == NULL) - xalloc_die (); + xalloc_die (); } if (seen_file (*ht, filename, st)) @@ -106,19 +106,19 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) { rname = xgetcwd (); if (!rname) - return NULL; + return NULL; dest = strchr (rname, '\0'); if (dest - rname < PATH_MAX) - { - char *p = xrealloc (rname, PATH_MAX); - dest = p + (dest - rname); - rname = p; - rname_limit = rname + PATH_MAX; - } + { + char *p = xrealloc (rname, PATH_MAX); + dest = p + (dest - rname); + rname = p; + rname_limit = rname + PATH_MAX; + } else - { - rname_limit = dest; - } + { + rname_limit = dest; + } } else { @@ -127,145 +127,145 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) rname[0] = '/'; dest = rname + 1; if (DOUBLE_SLASH_IS_DISTINCT_ROOT && name[1] == '/') - *dest++ = '/'; + *dest++ = '/'; } for (start = name; *start; start = end) { /* Skip sequence of multiple file name separators. */ while (*start == '/') - ++start; + ++start; /* Find end of component. */ for (end = start; *end && *end != '/'; ++end) - /* Nothing. */; + /* Nothing. */; if (end - start == 0) - break; + break; else if (end - start == 1 && start[0] == '.') - /* nothing */; + /* nothing */; else if (end - start == 2 && start[0] == '.' && start[1] == '.') - { - /* Back up to previous component, ignore if at root already. */ - if (dest > rname + 1) - while ((--dest)[-1] != '/'); - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 - && *dest == '/') - dest++; - } + { + /* Back up to previous component, ignore if at root already. */ + if (dest > rname + 1) + while ((--dest)[-1] != '/'); + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 + && *dest == '/') + dest++; + } else - { - struct stat st; - - if (dest[-1] != '/') - *dest++ = '/'; - - if (dest + (end - start) >= rname_limit) - { - ptrdiff_t dest_offset = dest - rname; - size_t new_size = rname_limit - rname; - - if (end - start + 1 > PATH_MAX) - new_size += end - start + 1; - else - new_size += PATH_MAX; - rname = xrealloc (rname, new_size); - rname_limit = rname + new_size; - - dest = rname + dest_offset; - } - - dest = memcpy (dest, start, end - start); - dest += end - start; - *dest = '\0'; - - if (lstat (rname, &st) != 0) - { - saved_errno = errno; - if (can_mode == CAN_EXISTING) - goto error; - if (can_mode == CAN_ALL_BUT_LAST) - { - if (end[strspn (end, "/")] || saved_errno != ENOENT) - goto error; - continue; - } - st.st_mode = 0; - } - - if (S_ISLNK (st.st_mode)) - { - char *buf; - size_t n, len; - - /* Detect loops. We cannot use the cycle-check module here, - since it's actually possible to encounter the same symlink - more than once in a given traversal. However, encountering - the same symlink,NAME pair twice does indicate a loop. */ - if (seen_triple (&ht, name, &st)) - { - if (can_mode == CAN_MISSING) - continue; - saved_errno = ELOOP; - goto error; - } - - buf = areadlink_with_size (rname, st.st_size); - if (!buf) - { - if (can_mode == CAN_MISSING && errno != ENOMEM) - continue; - saved_errno = errno; - goto error; - } - - n = strlen (buf); - len = strlen (end); - - if (!extra_len) - { - extra_len = - ((n + len + 1) > PATH_MAX) ? (n + len + 1) : PATH_MAX; - extra_buf = xmalloc (extra_len); - } - else if ((n + len + 1) > extra_len) - { - extra_len = n + len + 1; - extra_buf = xrealloc (extra_buf, extra_len); - } - - /* 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 (buf[0] == '/') - { - dest = rname + 1; /* It's an absolute symlink */ - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && buf[1] == '/') - *dest++ = '/'; - } - else - { - /* Back up to previous component, ignore if at root - already: */ - if (dest > rname + 1) - while ((--dest)[-1] != '/'); - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 - && *dest == '/') - dest++; - } - - free (buf); - } - else - { - if (!S_ISDIR (st.st_mode) && *end && (can_mode != CAN_MISSING)) - { - saved_errno = ENOTDIR; - goto error; - } - } - } + { + struct stat st; + + if (dest[-1] != '/') + *dest++ = '/'; + + if (dest + (end - start) >= rname_limit) + { + ptrdiff_t dest_offset = dest - rname; + size_t new_size = rname_limit - rname; + + if (end - start + 1 > PATH_MAX) + new_size += end - start + 1; + else + new_size += PATH_MAX; + rname = xrealloc (rname, new_size); + rname_limit = rname + new_size; + + dest = rname + dest_offset; + } + + dest = memcpy (dest, start, end - start); + dest += end - start; + *dest = '\0'; + + if (lstat (rname, &st) != 0) + { + saved_errno = errno; + if (can_mode == CAN_EXISTING) + goto error; + if (can_mode == CAN_ALL_BUT_LAST) + { + if (end[strspn (end, "/")] || saved_errno != ENOENT) + goto error; + continue; + } + st.st_mode = 0; + } + + if (S_ISLNK (st.st_mode)) + { + char *buf; + size_t n, len; + + /* Detect loops. We cannot use the cycle-check module here, + since it's actually possible to encounter the same symlink + more than once in a given traversal. However, encountering + the same symlink,NAME pair twice does indicate a loop. */ + if (seen_triple (&ht, name, &st)) + { + if (can_mode == CAN_MISSING) + continue; + saved_errno = ELOOP; + goto error; + } + + buf = areadlink_with_size (rname, st.st_size); + if (!buf) + { + if (can_mode == CAN_MISSING && errno != ENOMEM) + continue; + saved_errno = errno; + goto error; + } + + n = strlen (buf); + len = strlen (end); + + if (!extra_len) + { + extra_len = + ((n + len + 1) > PATH_MAX) ? (n + len + 1) : PATH_MAX; + extra_buf = xmalloc (extra_len); + } + else if ((n + len + 1) > extra_len) + { + extra_len = n + len + 1; + extra_buf = xrealloc (extra_buf, extra_len); + } + + /* 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 (buf[0] == '/') + { + dest = rname + 1; /* It's an absolute symlink */ + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && buf[1] == '/') + *dest++ = '/'; + } + else + { + /* Back up to previous component, ignore if at root + already: */ + if (dest > rname + 1) + while ((--dest)[-1] != '/'); + if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 + && *dest == '/') + dest++; + } + + free (buf); + } + else + { + if (!S_ISDIR (st.st_mode) && *end && (can_mode != CAN_MISSING)) + { + saved_errno = ENOTDIR; + goto error; + } + } + } } if (dest > rname + 1 && dest[-1] == '/') --dest; diff --git a/lib/ceil.c b/lib/ceil.c index b5a0316cf..53895a0ef 100644 --- a/lib/ceil.c +++ b/lib/ceil.c @@ -67,27 +67,27 @@ FUNC (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; } diff --git a/lib/chdir-long.c b/lib/chdir-long.c index afe018d16..c033f962c 100644 --- a/lib/chdir-long.c +++ b/lib/chdir-long.c @@ -72,7 +72,7 @@ static int cdb_advance_fd (struct cd_buf *cdb, char const *dir) { int new_fd = openat (cdb->fd, dir, - O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK); + O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK); if (new_fd < 0) return -1; @@ -135,27 +135,27 @@ chdir_long (char *dir) code in the following loop cleaner. */ if (n_leading_slash == 2) { - int err; - /* Find next slash. - We already know that dir[2] is neither a slash nor '\0'. */ - char *slash = memchr (dir + 3, '/', dir_end - (dir + 3)); - if (slash == NULL) - { - errno = ENAMETOOLONG; - return -1; - } - *slash = '\0'; - err = cdb_advance_fd (&cdb, dir); - *slash = '/'; - if (err != 0) - goto Fail; - dir = find_non_slash (slash + 1); + int err; + /* Find next slash. + We already know that dir[2] is neither a slash nor '\0'. */ + char *slash = memchr (dir + 3, '/', dir_end - (dir + 3)); + if (slash == NULL) + { + errno = ENAMETOOLONG; + return -1; + } + *slash = '\0'; + err = cdb_advance_fd (&cdb, dir); + *slash = '/'; + if (err != 0) + goto Fail; + dir = find_non_slash (slash + 1); } else if (n_leading_slash) { - if (cdb_advance_fd (&cdb, "/") != 0) - goto Fail; - dir += n_leading_slash; + if (cdb_advance_fd (&cdb, "/") != 0) + goto Fail; + dir += n_leading_slash; } assert (*dir != '/'); @@ -163,31 +163,31 @@ chdir_long (char *dir) while (PATH_MAX <= dir_end - dir) { - int err; - /* Find a slash that is PATH_MAX or fewer bytes away from dir. - I.e. see if there is a slash that will give us a name of - length PATH_MAX-1 or less. */ - char *slash = memrchr (dir, '/', PATH_MAX); - if (slash == NULL) - { - errno = ENAMETOOLONG; - return -1; - } - - *slash = '\0'; - assert (slash - dir < PATH_MAX); - err = cdb_advance_fd (&cdb, dir); - *slash = '/'; - if (err != 0) - goto Fail; - - dir = find_non_slash (slash + 1); + int err; + /* Find a slash that is PATH_MAX or fewer bytes away from dir. + I.e. see if there is a slash that will give us a name of + length PATH_MAX-1 or less. */ + char *slash = memrchr (dir, '/', PATH_MAX); + if (slash == NULL) + { + errno = ENAMETOOLONG; + return -1; + } + + *slash = '\0'; + assert (slash - dir < PATH_MAX); + err = cdb_advance_fd (&cdb, dir); + *slash = '/'; + if (err != 0) + goto Fail; + + dir = find_non_slash (slash + 1); } if (dir < dir_end) { - if (cdb_advance_fd (&cdb, dir) != 0) - goto Fail; + if (cdb_advance_fd (&cdb, dir) != 0) + goto Fail; } if (cdb_fchdir (&cdb) != 0) @@ -228,10 +228,10 @@ main (int argc, char *argv[]) { int saved_errno = errno; if (feof (stdin)) - exit (0); + exit (0); error (EXIT_FAILURE, saved_errno, - "reading standard input"); + "reading standard input"); } else if (len == 0) exit (0); @@ -241,12 +241,12 @@ main (int argc, char *argv[]) if (chdir_long (line) != 0) error (EXIT_FAILURE, errno, - "chdir_long failed: %s", line); + "chdir_long failed: %s", line); if (argc <= 1) { /* Using `pwd' here makes sense only if it is a robust implementation, - like the one in coreutils after the 2004-04-19 changes. */ + like the one in coreutils after the 2004-04-19 changes. */ char const *cmd = "pwd"; execlp (cmd, (char *) NULL); error (EXIT_FAILURE, errno, "%s", cmd); diff --git a/lib/chdir-long.h b/lib/chdir-long.h index 5bf0bbc25..ced8ee303 100644 --- a/lib/chdir-long.h +++ b/lib/chdir-long.h @@ -20,7 +20,7 @@ #include #ifndef PATH_MAX -# ifdef MAXPATHLEN +# ifdef MAXPATHLEN # define PATH_MAX MAXPATHLEN # endif #endif diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c index a6f77b0af..c111a0d99 100644 --- a/lib/chdir-safer.c +++ b/lib/chdir-safer.c @@ -43,7 +43,7 @@ chdir_no_follow (char const *dir) int result = 0; int saved_errno; int fd = open (dir, - O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK); + O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK); if (fd < 0) return -1; @@ -58,15 +58,15 @@ chdir_no_follow (char const *dir) struct stat sb1; result = lstat (dir, &sb1); if (result == 0) - { - struct stat sb2; - result = fstat (fd, &sb2); - if (result == 0 && ! SAME_INODE (sb1, sb2)) - { - errno = ELOOP; - result = -1; - } - } + { + struct stat sb2; + result = fstat (fd, &sb2); + if (result == 0 && ! SAME_INODE (sb1, sb2)) + { + errno = ELOOP; + result = -1; + } + } } if (result == 0) diff --git a/lib/classpath.c b/lib/classpath.c index 0651d0f82..d9821e3db 100644 --- a/lib/classpath.c +++ b/lib/classpath.c @@ -46,7 +46,7 @@ CLASSPATH is ignored. */ char * new_classpath (const char * const *classpaths, unsigned int classpaths_count, - bool use_minimal_classpath) + bool use_minimal_classpath) { const char *old_classpath; unsigned int length; @@ -81,7 +81,7 @@ new_classpath (const char * const *classpaths, unsigned int classpaths_count, else { if (classpaths_count > 0) - p--; + p--; } *p = '\0'; @@ -91,7 +91,7 @@ new_classpath (const char * const *classpaths, unsigned int classpaths_count, /* Set CLASSPATH and returns a safe copy of its old value. */ char * set_classpath (const char * const *classpaths, unsigned int classpaths_count, - bool use_minimal_classpath, bool verbose) + bool use_minimal_classpath, bool verbose) { const char *old_CLASSPATH = getenv (CLASSPATHVAR); char *result = (old_CLASSPATH != NULL ? xstrdup (old_CLASSPATH) : NULL); diff --git a/lib/classpath.h b/lib/classpath.h index e628e34a7..f345dd444 100644 --- a/lib/classpath.h +++ b/lib/classpath.h @@ -21,13 +21,13 @@ the current CLASSPATH value. If use_minimal_classpath, the current CLASSPATH is ignored. */ extern char * new_classpath (const char * const *classpaths, - unsigned int classpaths_count, - bool use_minimal_classpath); + unsigned int classpaths_count, + bool use_minimal_classpath); /* Set CLASSPATH and returns a safe copy of its old value. */ extern char * set_classpath (const char * const *classpaths, - unsigned int classpaths_count, - bool use_minimal_classpath, bool verbose); + unsigned int classpaths_count, + bool use_minimal_classpath, bool verbose); /* Restore CLASSPATH to its previous value. */ extern void reset_classpath (char *old_classpath); diff --git a/lib/clean-temp.c b/lib/clean-temp.c index 283d8af23..99c81d146 100644 --- a/lib/clean-temp.c +++ b/lib/clean-temp.c @@ -199,16 +199,16 @@ cleanup () 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); + 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); } } @@ -217,31 +217,31 @@ cleanup () 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); - } + { + 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); + } } } @@ -256,7 +256,7 @@ cleanup () is shown and NULL is returned. */ struct temp_dir * create_temp_dir (const char *prefix, const char *parentdir, - bool cleanup_verbose) + bool cleanup_verbose) { struct tempdir * volatile *tmpdirp = NULL; struct tempdir *tmpdir; @@ -269,47 +269,47 @@ create_temp_dir (const char *prefix, const char *parentdir, for (i = 0; i < cleanup_list.tempdir_count; i++) if (cleanup_list.tempdir_list[i] == NULL) { - tmpdirp = &cleanup_list.tempdir_list[i]; - break; + 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); - } + { + /* 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. */ + cleanup() will skip this entry before it is fully initialized. */ *tmpdirp = NULL; cleanup_list.tempdir_count++; } @@ -319,18 +319,18 @@ create_temp_dir (const char *prefix, const char *parentdir, tmpdir->dirname = NULL; tmpdir->cleanup_verbose = cleanup_verbose; tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST, - string_equals, string_hash, NULL, - false); + string_equals, string_hash, NULL, + false); tmpdir->files = gl_list_create_empty (GL_LINKEDHASH_LIST, - string_equals, string_hash, NULL, - false); + 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")); + _("cannot find a temporary directory, try setting $TMPDIR")); goto quit; } block_fatal_signals (); @@ -344,8 +344,8 @@ create_temp_dir (const char *prefix, const char *parentdir, if (tmpdirname == NULL) { error (0, errno, - _("cannot create a temporary directory using template \"%s\""), - xtemplate); + _("cannot create a temporary directory using template \"%s\""), + xtemplate); goto quit; } /* Replace tmpdir->dirname with a copy that has indefinite extent. @@ -366,7 +366,7 @@ create_temp_dir (const char *prefix, const char *parentdir, Should be called before the file ABSOLUTE_FILE_NAME is created. */ void register_temp_file (struct temp_dir *dir, - const char *absolute_file_name) + const char *absolute_file_name) { struct tempdir *tmpdir = (struct tempdir *)dir; @@ -380,7 +380,7 @@ register_temp_file (struct temp_dir *dir, 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) + const char *absolute_file_name) { struct tempdir *tmpdir = (struct tempdir *)dir; gl_list_t list = tmpdir->files; @@ -401,7 +401,7 @@ unregister_temp_file (struct temp_dir *dir, Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */ void register_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name) + const char *absolute_dir_name) { struct tempdir *tmpdir = (struct tempdir *)dir; @@ -416,7 +416,7 @@ register_temp_subdir (struct temp_dir *dir, created. */ void unregister_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name) + const char *absolute_dir_name) { struct tempdir *tmpdir = (struct tempdir *)dir; gl_list_t list = tmpdir->subdirs; @@ -455,7 +455,7 @@ do_rmdir (struct temp_dir *dir, const char *absolute_dir_name) && errno != ENOENT) { error (0, errno, - _("cannot remove temporary directory %s"), absolute_dir_name); + _("cannot remove temporary directory %s"), absolute_dir_name); return -1; } return 0; @@ -465,7 +465,7 @@ do_rmdir (struct temp_dir *dir, const char *absolute_dir_name) Return 0 upon success, or -1 if there was some problem. */ int cleanup_temp_file (struct temp_dir *dir, - const char *absolute_file_name) + const char *absolute_file_name) { int err; @@ -479,7 +479,7 @@ cleanup_temp_file (struct temp_dir *dir, Return 0 upon success, or -1 if there was some problem. */ int cleanup_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name) + const char *absolute_dir_name) { int err; @@ -548,19 +548,19 @@ cleanup_temp_dir (struct temp_dir *dir) 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 and tmpdir itself. */ - free (tmpdir->dirname); - free (tmpdir); - return err; + /* 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 and tmpdir itself. */ + free (tmpdir->dirname); + free (tmpdir); + return err; } /* The user passed an invalid DIR argument. */ @@ -585,9 +585,9 @@ supports_delete_on_close () OSVERSIONINFO v; if (GetVersionEx (&v)) - known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1); + known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1); else - known = -1; + known = -1; } return (known > 0); } @@ -601,7 +601,7 @@ register_fd (int fd) { if (descriptors == NULL) descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL, - false); + false); gl_list_add_first (descriptors, (void *) (uintptr_t) fd); } @@ -682,11 +682,11 @@ fopen_temp (const char *file_name, const char *mode) 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. */ + 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 (); + abort (); register_fd (fd); } unblock_fatal_signals (); @@ -702,12 +702,12 @@ close_temp (int fd) if (fd >= 0) { /* No blocking of signals is needed here, since a double close of a - file descriptor is harmless. */ + 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. */ + fd cannot be re-opened here. */ unregister_fd (fd); diff --git a/lib/clean-temp.h b/lib/clean-temp.h index 65c427c38..0d658de6b 100644 --- a/lib/clean-temp.h +++ b/lib/clean-temp.h @@ -60,43 +60,43 @@ struct temp_dir 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); + 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); + 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); + 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); + 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); + 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); + 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); + const char *absolute_dir_name); /* Remove all registered files and subdirectories inside DIR. Return 0 upon success, or -1 if there was some problem. */ diff --git a/lib/close-hook.c b/lib/close-hook.c index afe8e56a0..427629acd 100644 --- a/lib/close-hook.c +++ b/lib/close-hook.c @@ -66,7 +66,7 @@ register_close_hook (close_hook_fn hook, struct close_hook *link) { /* The link is already in use. */ if (link->private_fn != hook) - abort (); + abort (); } } diff --git a/lib/close-stream.c b/lib/close-stream.c index 59ab616b1..f71eaeffe 100644 --- a/lib/close-stream.c +++ b/lib/close-stream.c @@ -71,7 +71,7 @@ close_stream (FILE *stream) if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) { if (! fclose_fail) - errno = 0; + errno = 0; return EOF; } diff --git a/lib/closein.c b/lib/closein.c index c7fb581ea..150bc9a25 100644 --- a/lib/closein.c +++ b/lib/closein.c @@ -86,22 +86,22 @@ close_stdin (void) if (freadahead (stdin) > 0) { /* Only attempt flush if stdin is seekable, as fflush is entitled to - fail on non-seekable streams. */ + fail on non-seekable streams. */ if (fseeko (stdin, 0, SEEK_CUR) == 0 && fflush (stdin) != 0) - fail = true; + 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. */ + 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); + error (0, errno, "%s: %s", quotearg_colon (file_name), + close_error); else - error (0, errno, "%s", close_error); + error (0, errno, "%s", close_error); } close_stdout (); diff --git a/lib/closeout.c b/lib/closeout.c index 6a0b82ffa..d5310e153 100644 --- a/lib/closeout.c +++ b/lib/closeout.c @@ -111,10 +111,10 @@ close_stdout (void) { char const *write_error = _("write error"); if (file_name) - error (0, errno, "%s: %s", quotearg_colon (file_name), - write_error); + error (0, errno, "%s: %s", quotearg_colon (file_name), + write_error); else - error (0, errno, "%s", write_error); + error (0, errno, "%s", write_error); _exit (exit_failure); } diff --git a/lib/concat-filename.c b/lib/concat-filename.c index a1d22fa54..54a66f811 100644 --- a/lib/concat-filename.c +++ b/lib/concat-filename.c @@ -34,7 +34,7 @@ upon memory allocation failure. */ char * concatenated_filename (const char *directory, const char *filename, - const char *suffix) + const char *suffix) { char *result; char *p; @@ -43,28 +43,28 @@ concatenated_filename (const char *directory, const char *filename, { /* No need to prepend the directory. */ result = (char *) malloc (strlen (filename) - + (suffix != NULL ? strlen (suffix) : 0) - + 1); + + (suffix != NULL ? strlen (suffix) : 0) + + 1); if (result == NULL) - return NULL; /* errno is set here */ + 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])); + (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); + + strlen (filename) + + (suffix != NULL ? strlen (suffix) : 0) + + 1); if (result == NULL) - return NULL; /* errno is set here */ + return NULL; /* errno is set here */ memcpy (result, directory, directory_len); p = result + directory_len; if (need_slash) - *p++ = '/'; + *p++ = '/'; } p = stpcpy (p, filename); if (suffix != NULL) diff --git a/lib/concat-filename.h b/lib/concat-filename.h index 1f02eadbb..635477924 100644 --- a/lib/concat-filename.h +++ b/lib/concat-filename.h @@ -26,12 +26,12 @@ extern "C" { 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); + 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); + const char *filename, const char *suffix); #ifdef __cplusplus diff --git a/lib/connect.c b/lib/connect.c index c7abf204d..df4143865 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -36,9 +36,9 @@ rpl_connect (int fd, struct sockaddr *sockaddr, int len) if (r < 0) { /* EINPROGRESS is not returned by WinSock 2.0; for backwards - compatibility, connect(2) uses EWOULDBLOCK. */ + compatibility, connect(2) uses EWOULDBLOCK. */ if (WSAGetLastError () == WSAEWOULDBLOCK) - WSASetLastError (WSAEINPROGRESS); + WSASetLastError (WSAEINPROGRESS); set_winsock_errno (); } diff --git a/lib/copy-acl.c b/lib/copy-acl.c index af85a08fb..ca2692654 100644 --- a/lib/copy-acl.c +++ b/lib/copy-acl.c @@ -40,7 +40,7 @@ static int qcopy_acl (const char *src_name, int source_desc, const char *dst_name, - int dest_desc, mode_t mode) + int dest_desc, mode_t mode) { #if USE_ACL && HAVE_ACL_GET_FILE /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ @@ -58,9 +58,9 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (acl == NULL) { if (ACL_NOT_WELL_SUPPORTED (errno)) - return qset_acl (dst_name, dest_desc, mode); + return qset_acl (dst_name, dest_desc, mode); else - return -2; + return -2; } if (HAVE_ACL_SET_FD && dest_desc != -1) @@ -72,17 +72,17 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, int saved_errno = errno; if (ACL_NOT_WELL_SUPPORTED (errno) && !acl_access_nontrivial (acl)) - { - acl_free (acl); - return chmod_or_fchmod (dst_name, dest_desc, mode); - } + { + acl_free (acl); + return chmod_or_fchmod (dst_name, dest_desc, mode); + } else - { - acl_free (acl); - chmod_or_fchmod (dst_name, dest_desc, mode); - errno = saved_errno; - return -1; - } + { + acl_free (acl); + chmod_or_fchmod (dst_name, dest_desc, mode); + errno = saved_errno; + return -1; + } } else acl_free (acl); @@ -90,28 +90,28 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (mode & (S_ISUID | S_ISGID | S_ISVTX)) { /* We did not call chmod so far, and either the mode and the ACL are - separate or special bits are to be set which don't fit into ACLs. */ + separate or special bits are to be set which don't fit into ACLs. */ if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) - return -1; + return -1; } if (S_ISDIR (mode)) { acl = acl_get_file (src_name, ACL_TYPE_DEFAULT); if (acl == NULL) - return -2; + return -2; if (acl_set_file (dst_name, ACL_TYPE_DEFAULT, acl)) - { - int saved_errno = errno; + { + int saved_errno = errno; - acl_free (acl); - errno = saved_errno; - return -1; - } + acl_free (acl); + errno = saved_errno; + return -1; + } else - acl_free (acl); + acl_free (acl); } return 0; @@ -125,14 +125,14 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS) and acl_get_file (name, ACL_TYPE_DEFAULT) always return NULL / EINVAL. You have to use - acl_get_file (name, ACL_TYPE_EXTENDED) + acl_get_file (name, ACL_TYPE_EXTENDED) or acl_get_fd (open (name, ...)) to retrieve an ACL. On the other hand, - acl_set_file (name, ACL_TYPE_ACCESS, acl) + acl_set_file (name, ACL_TYPE_ACCESS, acl) and acl_set_file (name, ACL_TYPE_DEFAULT, acl) have the same effect as - acl_set_file (name, ACL_TYPE_EXTENDED, acl): + acl_set_file (name, ACL_TYPE_EXTENDED, acl): Each of these calls sets the file's ACL. */ acl_t acl; @@ -145,9 +145,9 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (acl == NULL) { if (ACL_NOT_WELL_SUPPORTED (errno)) - return qset_acl (dst_name, dest_desc, mode); + return qset_acl (dst_name, dest_desc, mode); else - return -2; + return -2; } if (HAVE_ACL_SET_FD && dest_desc != -1) @@ -159,17 +159,17 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, int saved_errno = errno; if (ACL_NOT_WELL_SUPPORTED (errno) && !acl_extended_nontrivial (acl)) - { - acl_free (acl); - return chmod_or_fchmod (dst_name, dest_desc, mode); - } + { + acl_free (acl); + return chmod_or_fchmod (dst_name, dest_desc, mode); + } else - { - acl_free (acl); - chmod_or_fchmod (dst_name, dest_desc, mode); - errno = saved_errno; - return -1; - } + { + acl_free (acl); + chmod_or_fchmod (dst_name, dest_desc, mode); + errno = saved_errno; + return -1; + } } else acl_free (acl); @@ -189,8 +189,8 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, int ret; acl_t *aclp = NULL; ret = (source_desc < 0 - ? acl_get (src_name, ACL_NO_TRIVIAL, &aclp) - : facl_get (source_desc, ACL_NO_TRIVIAL, &aclp)); + ? acl_get (src_name, ACL_NO_TRIVIAL, &aclp) + : facl_get (source_desc, ACL_NO_TRIVIAL, &aclp)); if (ret != 0 && errno != ENOSYS) return -2; @@ -201,16 +201,16 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (aclp) { ret = (dest_desc < 0 - ? acl_set (dst_name, aclp) - : facl_set (dest_desc, aclp)); + ? acl_set (dst_name, aclp) + : facl_set (dest_desc, aclp)); if (ret != 0) - { - int saved_errno = errno; + { + int saved_errno = errno; - acl_free (aclp); - errno = saved_errno; - return -1; - } + acl_free (aclp); + errno = saved_errno; + return -1; + } acl_free (aclp); } @@ -248,82 +248,82 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, for (;;) { ace_count = (source_desc != -1 - ? facl (source_desc, ACE_GETACLCNT, 0, NULL) - : acl (src_name, ACE_GETACLCNT, 0, NULL)); + ? facl (source_desc, ACE_GETACLCNT, 0, NULL) + : acl (src_name, ACE_GETACLCNT, 0, NULL)); if (ace_count < 0) - { - if (errno == ENOSYS || errno == EINVAL) - { - ace_count = 0; - ace_entries = NULL; - break; - } - else - return -2; - } + { + if (errno == ENOSYS || errno == EINVAL) + { + ace_count = 0; + ace_entries = NULL; + break; + } + else + return -2; + } if (ace_count == 0) - { - ace_entries = NULL; - break; - } + { + ace_entries = NULL; + break; + } ace_entries = (ace_t *) malloc (ace_count * sizeof (ace_t)); if (ace_entries == NULL) - { - errno = ENOMEM; - return -2; - } + { + errno = ENOMEM; + return -2; + } if ((source_desc != -1 - ? facl (source_desc, ACE_GETACL, ace_count, ace_entries) - : acl (src_name, ACE_GETACL, ace_count, ace_entries)) - == ace_count) - break; + ? facl (source_desc, ACE_GETACL, ace_count, ace_entries) + : acl (src_name, ACE_GETACL, ace_count, ace_entries)) + == ace_count) + break; /* Huh? The number of ACL entries changed since the last call. - Repeat. */ + Repeat. */ } # endif for (;;) { count = (source_desc != -1 - ? facl (source_desc, GETACLCNT, 0, NULL) - : acl (src_name, GETACLCNT, 0, NULL)); + ? facl (source_desc, GETACLCNT, 0, NULL) + : acl (src_name, GETACLCNT, 0, NULL)); if (count < 0) - { - if (errno == ENOSYS || errno == ENOTSUP) - { - count = 0; - entries = NULL; - break; - } - else - return -2; - } + { + if (errno == ENOSYS || errno == ENOTSUP) + { + count = 0; + entries = NULL; + break; + } + else + return -2; + } if (count == 0) - { - entries = NULL; - break; - } + { + entries = NULL; + break; + } entries = (aclent_t *) malloc (count * sizeof (aclent_t)); if (entries == NULL) - { - errno = ENOMEM; - return -2; - } + { + errno = ENOMEM; + return -2; + } if ((source_desc != -1 - ? facl (source_desc, GETACL, count, entries) - : acl (src_name, GETACL, count, entries)) - == count) - break; + ? facl (source_desc, GETACL, count, entries) + : acl (src_name, GETACL, count, entries)) + == count) + break; /* Huh? The number of ACL entries changed since the last call. - Repeat. */ + Repeat. */ } /* Is there an ACL of either kind? */ @@ -339,10 +339,10 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (!MODE_INSIDE_ACL) { /* On Cygwin, it is necessary to call chmod before acl, because - chmod can change the contents of the ACL (in ways that don't - change the allowed accesses, but still visible). */ + chmod can change the contents of the ACL (in ways that don't + change the allowed accesses, but still visible). */ if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) - saved_errno = errno; + saved_errno = errno; did_chmod = 1; } @@ -353,16 +353,16 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (count > 0) { ret = (dest_desc != -1 - ? facl (dest_desc, SETACL, count, entries) - : acl (dst_name, SETACL, count, entries)); + ? facl (dest_desc, SETACL, count, entries) + : acl (dst_name, SETACL, count, entries)); if (ret < 0 && saved_errno == 0) - { - saved_errno = errno; - if (errno == ENOSYS && !acl_nontrivial (count, entries)) - saved_errno = 0; - } + { + saved_errno = errno; + if (errno == ENOSYS && !acl_nontrivial (count, entries)) + saved_errno = 0; + } else - did_chmod = 1; + did_chmod = 1; } free (entries); @@ -370,15 +370,15 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (ace_count > 0) { ret = (dest_desc != -1 - ? facl (dest_desc, ACE_SETACL, ace_count, ace_entries) - : acl (dst_name, ACE_SETACL, ace_count, ace_entries)); + ? facl (dest_desc, ACE_SETACL, ace_count, ace_entries) + : acl (dst_name, ACE_SETACL, ace_count, ace_entries)); if (ret < 0 && saved_errno == 0) - { - saved_errno = errno; - if ((errno == ENOSYS || errno == EINVAL || errno == ENOTSUP) - && !acl_ace_nontrivial (ace_count, ace_entries)) - saved_errno = 0; - } + { + saved_errno = errno; + if ((errno == ENOSYS || errno == EINVAL || errno == ENOTSUP) + && !acl_ace_nontrivial (ace_count, ace_entries)) + saved_errno = 0; + } } free (ace_entries); # endif @@ -387,13 +387,13 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, && did_chmod <= ((mode & (S_ISUID | S_ISGID | S_ISVTX)) ? 1 : 0)) { /* We did not call chmod so far, and either the mode and the ACL are - separate or special bits are to be set which don't fit into ACLs. */ + separate or special bits are to be set which don't fit into ACLs. */ if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) - { - if (saved_errno == 0) - saved_errno = errno; - } + { + if (saved_errno == 0) + saved_errno = errno; + } } if (saved_errno) @@ -414,60 +414,60 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, for (;;) { count = (source_desc != -1 - ? fgetacl (source_desc, 0, NULL) - : getacl (src_name, 0, NULL)); + ? fgetacl (source_desc, 0, NULL) + : getacl (src_name, 0, NULL)); if (count < 0) - { - if (errno == ENOSYS || errno == EOPNOTSUPP) - { - count = 0; - break; - } - else - return -2; - } + { + if (errno == ENOSYS || errno == EOPNOTSUPP) + { + count = 0; + break; + } + else + return -2; + } if (count == 0) - break; + break; if (count > NACLENTRIES) - /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */ - abort (); + /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */ + abort (); if ((source_desc != -1 - ? fgetacl (source_desc, count, entries) - : getacl (src_name, count, entries)) - == count) - break; + ? fgetacl (source_desc, count, entries) + : getacl (src_name, count, entries)) + == count) + break; /* Huh? The number of ACL entries changed since the last call. - Repeat. */ + Repeat. */ } if (count == 0) return qset_acl (dst_name, dest_desc, mode); ret = (dest_desc != -1 - ? fsetacl (dest_desc, count, entries) - : setacl (dst_name, count, entries)); + ? fsetacl (dest_desc, count, entries) + : setacl (dst_name, count, entries)); if (ret < 0) { int saved_errno = errno; if (errno == ENOSYS || errno == EOPNOTSUPP) - { - struct stat source_statbuf; - - if ((source_desc != -1 - ? fstat (source_desc, &source_statbuf) - : stat (src_name, &source_statbuf)) == 0) - { - if (!acl_nontrivial (count, entries, &source_statbuf)) - return chmod_or_fchmod (dst_name, dest_desc, mode); - } - else - saved_errno = errno; - } + { + struct stat source_statbuf; + + if ((source_desc != -1 + ? fstat (source_desc, &source_statbuf) + : stat (src_name, &source_statbuf)) == 0) + { + if (!acl_nontrivial (count, entries, &source_statbuf)) + return chmod_or_fchmod (dst_name, dest_desc, mode); + } + else + saved_errno = errno; + } chmod_or_fchmod (dst_name, dest_desc, mode); errno = saved_errno; @@ -477,7 +477,7 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, if (mode & (S_ISUID | S_ISGID | S_ISVTX)) { /* We did not call chmod so far, and either the mode and the ACL are - separate or special bits are to be set which don't fit into ACLs. */ + separate or special bits are to be set which don't fit into ACLs. */ return chmod_or_fchmod (dst_name, dest_desc, mode); } @@ -499,8 +499,8 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, return -2; ret = (dest_desc != -1 - ? fchacl (dest_desc, &u.a, u.a.acl_len) - : chacl (dst_name, &u.a, u.a.acl_len)); + ? fchacl (dest_desc, &u.a, u.a.acl_len) + : chacl (dst_name, &u.a, u.a.acl_len)); if (ret < 0) { int saved_errno = errno; @@ -534,7 +534,7 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, int copy_acl (const char *src_name, int source_desc, const char *dst_name, - int dest_desc, mode_t mode) + int dest_desc, mode_t mode) { int ret = qcopy_acl (src_name, source_desc, dst_name, dest_desc, mode); switch (ret) diff --git a/lib/copy-file.c b/lib/copy-file.c index 939fd0778..66cb3ac2f 100644 --- a/lib/copy-file.c +++ b/lib/copy-file.c @@ -65,26 +65,26 @@ copy_file_preserving (const char *src_filename, const char *dest_filename) src_fd = open (src_filename, O_RDONLY | O_BINARY); if (src_fd < 0 || fstat (src_fd, &statbuf) < 0) error (EXIT_FAILURE, errno, _("error while opening \"%s\" for reading"), - src_filename); + src_filename); mode = statbuf.st_mode & 07777; dest_fd = open (dest_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600); if (dest_fd < 0) error (EXIT_FAILURE, errno, _("cannot open backup file \"%s\" for writing"), - dest_filename); + dest_filename); /* Copy the file contents. */ for (;;) { size_t n_read = safe_read (src_fd, buf, IO_SIZE); if (n_read == SAFE_READ_ERROR) - error (EXIT_FAILURE, errno, _("error reading \"%s\""), src_filename); + error (EXIT_FAILURE, errno, _("error reading \"%s\""), src_filename); if (n_read == 0) - break; + break; if (full_write (dest_fd, buf, n_read) < n_read) - error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename); + error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename); } free (buf); diff --git a/lib/cosl.c b/lib/cosl.c index 20786c147..53df794a1 100644 --- a/lib/cosl.c +++ b/lib/cosl.c @@ -22,22 +22,22 @@ * Return sine function of x. * * kernel function: - * __kernel_sinl ... sine function on [-pi/4,pi/4] - * __kernel_cosl ... cose function on [-pi/4,pi/4] - * __ieee754_rem_pio2l ... argument reduction routine + * __kernel_sinl ... sine function on [-pi/4,pi/4] + * __kernel_cosl ... cose function on [-pi/4,pi/4] + * __ieee754_rem_pio2l ... argument reduction routine * * Method. * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 + * in [-pi/4 , +pi/4], and let n = k mod 4. + * We have * * n sin(x) cos(x) tan(x) * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T + * 0 S C T + * 1 C -S -1/T + * 2 -S -C T + * 3 -C S -1/T * ---------------------------------------------------------- * * Special cases: @@ -46,7 +46,7 @@ * trig(NaN) is that NaN; * * Accuracy: - * TRIG(x) returns trig(x) nearly rounded + * TRIG(x) returns trig(x) nearly rounded */ #include "trigl.h" @@ -57,8 +57,8 @@ long double cosl(long double x) { - long double y[2],z=0.0L; - int n; + long double y[2],z=0.0L; + int n; /* cosl(NaN) is NaN */ if (isnanl (x)) @@ -74,16 +74,16 @@ long double cosl(long double x) return x-x; /* NaN */ /* argument reduction needed */ - else { - n = ieee754_rem_pio2l(x,y); + else { + n = ieee754_rem_pio2l(x,y); switch(n&3) { case 0: return kernel_cosl(y[0],y[1]); case 1: return -kernel_sinl(y[0],y[1],1); case 2: return -kernel_cosl(y[0],y[1]); default: return kernel_sinl(y[0],y[1],1); - } - } + } + } } #if 0 diff --git a/lib/csharpcomp.c b/lib/csharpcomp.c index 1e84f0561..d8ed18c18 100644 --- a/lib/csharpcomp.c +++ b/lib/csharpcomp.c @@ -60,14 +60,14 @@ static int compile_csharp_using_pnet (const char * const *sources, - unsigned int sources_count, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *libraries, - unsigned int libraries_count, - const char *output_file, bool output_is_library, - bool optimize, bool debug, - bool verbose) + unsigned int sources_count, + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *libraries, + unsigned int libraries_count, + const char *output_file, bool output_is_library, + bool optimize, bool debug, + bool verbose) { static bool cscc_tested; static bool cscc_present; @@ -75,7 +75,7 @@ compile_csharp_using_pnet (const char * const *sources, if (!cscc_tested) { /* Test for presence of cscc: - "cscc --version >/dev/null 2>/dev/null" */ + "cscc --version >/dev/null 2>/dev/null" */ char *argv[3]; int exitstatus; @@ -83,7 +83,7 @@ compile_csharp_using_pnet (const char * const *sources, argv[1] = "--version"; argv[2] = NULL; exitstatus = execute ("cscc", "cscc", argv, false, false, true, true, - true, false, NULL); + true, false, NULL); cscc_present = (exitstatus == 0); cscc_tested = true; } @@ -97,65 +97,65 @@ compile_csharp_using_pnet (const char * const *sources, unsigned int i; argc = - 1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count - + 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0) - + sources_count; + 1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count + + 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0) + + sources_count; argv = (char **) xmalloca ((argc + 1) * sizeof (char *)); argp = argv; *argp++ = "cscc"; if (output_is_library) - *argp++ = "-shared"; + *argp++ = "-shared"; *argp++ = "-o"; *argp++ = (char *) output_file; for (i = 0; i < libdirs_count; i++) - { - *argp++ = "-L"; - *argp++ = (char *) libdirs[i]; - } + { + *argp++ = "-L"; + *argp++ = (char *) libdirs[i]; + } for (i = 0; i < libraries_count; i++) - { - *argp++ = "-l"; - *argp++ = (char *) libraries[i]; - } + { + *argp++ = "-l"; + *argp++ = (char *) libraries[i]; + } if (optimize) - *argp++ = "-O"; + *argp++ = "-O"; if (debug) - *argp++ = "-g"; + *argp++ = "-g"; for (i = 0; i < sources_count; i++) - { - const char *source_file = sources[i]; - if (strlen (source_file) >= 10 - && memcmp (source_file + strlen (source_file) - 10, ".resources", - 10) == 0) - { - char *option = (char *) xmalloca (12 + strlen (source_file) + 1); - - memcpy (option, "-fresources=", 12); - strcpy (option + 12, source_file); - *argp++ = option; - } - else - *argp++ = (char *) source_file; - } + { + const char *source_file = sources[i]; + if (strlen (source_file) >= 10 + && memcmp (source_file + strlen (source_file) - 10, ".resources", + 10) == 0) + { + char *option = (char *) xmalloca (12 + strlen (source_file) + 1); + + memcpy (option, "-fresources=", 12); + strcpy (option + 12, source_file); + *argp++ = option; + } + else + *argp++ = (char *) source_file; + } *argp = NULL; /* Ensure argv length was correctly calculated. */ if (argp - argv != argc) - abort (); + abort (); if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } exitstatus = execute ("cscc", "cscc", argv, false, false, false, false, - true, true, NULL); + true, true, NULL); for (i = 0; i < sources_count; i++) - if (argv[argc - sources_count + i] != sources[i]) - freea (argv[argc - sources_count + i]); + if (argv[argc - sources_count + i] != sources[i]) + freea (argv[argc - sources_count + i]); freea (argv); return (exitstatus != 0); @@ -166,14 +166,14 @@ compile_csharp_using_pnet (const char * const *sources, static int compile_csharp_using_mono (const char * const *sources, - unsigned int sources_count, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *libraries, - unsigned int libraries_count, - const char *output_file, bool output_is_library, - bool optimize, bool debug, - bool verbose) + unsigned int sources_count, + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *libraries, + unsigned int libraries_count, + const char *output_file, bool output_is_library, + bool optimize, bool debug, + bool verbose) { static bool mcs_tested; static bool mcs_present; @@ -181,9 +181,9 @@ compile_csharp_using_mono (const char * const *sources, if (!mcs_tested) { /* Test for presence of mcs: - "mcs --version >/dev/null 2>/dev/null" - and (to exclude an unrelated 'mcs' program on QNX 6) - "mcs --version 2>/dev/null | grep Mono >/dev/null" */ + "mcs --version >/dev/null 2>/dev/null" + and (to exclude an unrelated 'mcs' program on QNX 6) + "mcs --version 2>/dev/null | grep Mono >/dev/null" */ char *argv[3]; pid_t child; int fd[1]; @@ -193,36 +193,36 @@ compile_csharp_using_mono (const char * const *sources, argv[1] = "--version"; argv[2] = NULL; child = create_pipe_in ("mcs", "mcs", argv, DEV_NULL, true, true, false, - fd); + fd); mcs_present = false; if (child != -1) - { - /* Read the subprocess output, and test whether it contains the - string "Mono". */ - char c[4]; - size_t count = 0; - - while (safe_read (fd[0], &c[count], 1) > 0) - { - count++; - if (count == 4) - { - if (memcmp (c, "Mono", 4) == 0) - mcs_present = true; - c[0] = c[1]; c[1] = c[2]; c[2] = c[3]; - count--; - } - } - - close (fd[0]); - - /* Remove zombie process from process list, and retrieve exit - status. */ - exitstatus = - wait_subprocess (child, "mcs", false, true, true, false, NULL); - if (exitstatus != 0) - mcs_present = false; - } + { + /* Read the subprocess output, and test whether it contains the + string "Mono". */ + char c[4]; + size_t count = 0; + + while (safe_read (fd[0], &c[count], 1) > 0) + { + count++; + if (count == 4) + { + if (memcmp (c, "Mono", 4) == 0) + mcs_present = true; + c[0] = c[1]; c[1] = c[2]; c[2] = c[3]; + count--; + } + } + + close (fd[0]); + + /* Remove zombie process from process list, and retrieve exit + status. */ + exitstatus = + wait_subprocess (child, "mcs", false, true, true, false, NULL); + if (exitstatus != 0) + mcs_present = false; + } mcs_tested = true; } @@ -242,107 +242,107 @@ compile_csharp_using_mono (const char * const *sources, unsigned int i; argc = - 1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count - + (debug ? 1 : 0) + sources_count; + 1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count + + (debug ? 1 : 0) + sources_count; argv = (char **) xmalloca ((argc + 1) * sizeof (char *)); argp = argv; *argp++ = "mcs"; if (output_is_library) - *argp++ = "-target:library"; + *argp++ = "-target:library"; { - char *option = (char *) xmalloca (5 + strlen (output_file) + 1); - memcpy (option, "-out:", 5); - strcpy (option + 5, output_file); - *argp++ = option; + char *option = (char *) xmalloca (5 + strlen (output_file) + 1); + memcpy (option, "-out:", 5); + strcpy (option + 5, output_file); + *argp++ = option; } for (i = 0; i < libdirs_count; i++) - { - char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1); - memcpy (option, "-lib:", 5); - strcpy (option + 5, libdirs[i]); - *argp++ = option; - } + { + char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1); + memcpy (option, "-lib:", 5); + strcpy (option + 5, libdirs[i]); + *argp++ = option; + } for (i = 0; i < libraries_count; i++) - { - char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1); - memcpy (option, "-reference:", 11); - memcpy (option + 11, libraries[i], strlen (libraries[i])); - strcpy (option + 11 + strlen (libraries[i]), ".dll"); - *argp++ = option; - } + { + char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1); + memcpy (option, "-reference:", 11); + memcpy (option + 11, libraries[i], strlen (libraries[i])); + strcpy (option + 11 + strlen (libraries[i]), ".dll"); + *argp++ = option; + } if (debug) - *argp++ = "-debug"; + *argp++ = "-debug"; for (i = 0; i < sources_count; i++) - { - const char *source_file = sources[i]; - if (strlen (source_file) >= 10 - && memcmp (source_file + strlen (source_file) - 10, ".resources", - 10) == 0) - { - char *option = (char *) xmalloca (10 + strlen (source_file) + 1); - - memcpy (option, "-resource:", 10); - strcpy (option + 10, source_file); - *argp++ = option; - } - else - *argp++ = (char *) source_file; - } + { + const char *source_file = sources[i]; + if (strlen (source_file) >= 10 + && memcmp (source_file + strlen (source_file) - 10, ".resources", + 10) == 0) + { + char *option = (char *) xmalloca (10 + strlen (source_file) + 1); + + memcpy (option, "-resource:", 10); + strcpy (option + 10, source_file); + *argp++ = option; + } + else + *argp++ = (char *) source_file; + } *argp = NULL; /* Ensure argv length was correctly calculated. */ if (argp - argv != argc) - abort (); + abort (); if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } child = create_pipe_in ("mcs", "mcs", argv, NULL, false, true, true, fd); /* Read the subprocess output, copying it to stderr. Drop the last - line if it starts with "Compilation succeeded". */ + line if it starts with "Compilation succeeded". */ fp = fdopen (fd[0], "r"); if (fp == NULL) - error (EXIT_FAILURE, errno, _("fdopen() failed")); + error (EXIT_FAILURE, errno, _("fdopen() failed")); line[0] = NULL; linesize[0] = 0; line[1] = NULL; linesize[1] = 0; l = 0; for (;;) - { - linelen[l] = getline (&line[l], &linesize[l], fp); - if (linelen[l] == (size_t)(-1)) - break; - l = (l + 1) % 2; - if (line[l] != NULL) - fwrite (line[l], 1, linelen[l], stderr); - } + { + linelen[l] = getline (&line[l], &linesize[l], fp); + if (linelen[l] == (size_t)(-1)) + break; + l = (l + 1) % 2; + if (line[l] != NULL) + fwrite (line[l], 1, linelen[l], stderr); + } l = (l + 1) % 2; if (line[l] != NULL - && !(linelen[l] >= 21 - && memcmp (line[l], "Compilation succeeded", 21) == 0)) - fwrite (line[l], 1, linelen[l], stderr); + && !(linelen[l] >= 21 + && memcmp (line[l], "Compilation succeeded", 21) == 0)) + fwrite (line[l], 1, linelen[l], stderr); if (line[0] != NULL) - free (line[0]); + free (line[0]); if (line[1] != NULL) - free (line[1]); + free (line[1]); fclose (fp); /* Remove zombie process from process list, and retrieve exit status. */ exitstatus = - wait_subprocess (child, "mcs", false, false, true, true, NULL); + wait_subprocess (child, "mcs", false, false, true, true, NULL); for (i = 1 + (output_is_library ? 1 : 0); - i < 1 + (output_is_library ? 1 : 0) - + 1 + libdirs_count + libraries_count; - i++) - freea (argv[i]); + i < 1 + (output_is_library ? 1 : 0) + + 1 + libdirs_count + libraries_count; + i++) + freea (argv[i]); for (i = 0; i < sources_count; i++) - if (argv[argc - sources_count + i] != sources[i]) - freea (argv[argc - sources_count + i]); + if (argv[argc - sources_count + i] != sources[i]) + freea (argv[argc - sources_count + i]); freea (argv); return (exitstatus != 0); @@ -353,14 +353,14 @@ compile_csharp_using_mono (const char * const *sources, static int compile_csharp_using_sscli (const char * const *sources, - unsigned int sources_count, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *libraries, - unsigned int libraries_count, - const char *output_file, bool output_is_library, - bool optimize, bool debug, - bool verbose) + unsigned int sources_count, + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *libraries, + unsigned int libraries_count, + const char *output_file, bool output_is_library, + bool optimize, bool debug, + bool verbose) { static bool csc_tested; static bool csc_present; @@ -368,8 +368,8 @@ compile_csharp_using_sscli (const char * const *sources, if (!csc_tested) { /* Test for presence of csc: - "csc -help >/dev/null 2>/dev/null \ - && ! { csc -help 2>/dev/null | grep -i chicken > /dev/null; }" */ + "csc -help >/dev/null 2>/dev/null \ + && ! { csc -help 2>/dev/null | grep -i chicken > /dev/null; }" */ char *argv[3]; pid_t child; int fd[1]; @@ -379,40 +379,40 @@ compile_csharp_using_sscli (const char * const *sources, argv[1] = "-help"; argv[2] = NULL; child = create_pipe_in ("csc", "csc", argv, DEV_NULL, true, true, false, - fd); + fd); csc_present = false; if (child != -1) - { - /* Read the subprocess output, and test whether it contains the - string "chicken". */ - char c[7]; - size_t count = 0; - - csc_present = true; - while (safe_read (fd[0], &c[count], 1) > 0) - { - if (c[count] >= 'A' && c[count] <= 'Z') - c[count] += 'a' - 'A'; - count++; - if (count == 7) - { - if (memcmp (c, "chicken", 7) == 0) - csc_present = false; - c[0] = c[1]; c[1] = c[2]; c[2] = c[3]; - c[3] = c[4]; c[4] = c[5]; c[5] = c[6]; - count--; - } - } - - close (fd[0]); - - /* Remove zombie process from process list, and retrieve exit - status. */ - exitstatus = - wait_subprocess (child, "csc", false, true, true, false, NULL); - if (exitstatus != 0) - csc_present = false; - } + { + /* Read the subprocess output, and test whether it contains the + string "chicken". */ + char c[7]; + size_t count = 0; + + csc_present = true; + while (safe_read (fd[0], &c[count], 1) > 0) + { + if (c[count] >= 'A' && c[count] <= 'Z') + c[count] += 'a' - 'A'; + count++; + if (count == 7) + { + if (memcmp (c, "chicken", 7) == 0) + csc_present = false; + c[0] = c[1]; c[1] = c[2]; c[2] = c[3]; + c[3] = c[4]; c[4] = c[5]; c[5] = c[6]; + count--; + } + } + + close (fd[0]); + + /* Remove zombie process from process list, and retrieve exit + status. */ + exitstatus = + wait_subprocess (child, "csc", false, true, true, false, NULL); + if (exitstatus != 0) + csc_present = false; + } csc_tested = true; } @@ -425,75 +425,75 @@ compile_csharp_using_sscli (const char * const *sources, unsigned int i; argc = - 1 + 1 + 1 + libdirs_count + libraries_count - + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count; + 1 + 1 + 1 + libdirs_count + libraries_count + + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count; argv = (char **) xmalloca ((argc + 1) * sizeof (char *)); argp = argv; *argp++ = "csc"; *argp++ = - (char *) (output_is_library ? "-target:library" : "-target:exe"); + (char *) (output_is_library ? "-target:library" : "-target:exe"); { - char *option = (char *) xmalloca (5 + strlen (output_file) + 1); - memcpy (option, "-out:", 5); - strcpy (option + 5, output_file); - *argp++ = option; + char *option = (char *) xmalloca (5 + strlen (output_file) + 1); + memcpy (option, "-out:", 5); + strcpy (option + 5, output_file); + *argp++ = option; } for (i = 0; i < libdirs_count; i++) - { - char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1); - memcpy (option, "-lib:", 5); - strcpy (option + 5, libdirs[i]); - *argp++ = option; - } + { + char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1); + memcpy (option, "-lib:", 5); + strcpy (option + 5, libdirs[i]); + *argp++ = option; + } for (i = 0; i < libraries_count; i++) - { - char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1); - memcpy (option, "-reference:", 11); - memcpy (option + 11, libraries[i], strlen (libraries[i])); - strcpy (option + 11 + strlen (libraries[i]), ".dll"); - *argp++ = option; - } + { + char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1); + memcpy (option, "-reference:", 11); + memcpy (option + 11, libraries[i], strlen (libraries[i])); + strcpy (option + 11 + strlen (libraries[i]), ".dll"); + *argp++ = option; + } if (optimize) - *argp++ = "-optimize+"; + *argp++ = "-optimize+"; if (debug) - *argp++ = "-debug+"; + *argp++ = "-debug+"; for (i = 0; i < sources_count; i++) - { - const char *source_file = sources[i]; - if (strlen (source_file) >= 10 - && memcmp (source_file + strlen (source_file) - 10, ".resources", - 10) == 0) - { - char *option = (char *) xmalloca (10 + strlen (source_file) + 1); - - memcpy (option, "-resource:", 10); - strcpy (option + 10, source_file); - *argp++ = option; - } - else - *argp++ = (char *) source_file; - } + { + const char *source_file = sources[i]; + if (strlen (source_file) >= 10 + && memcmp (source_file + strlen (source_file) - 10, ".resources", + 10) == 0) + { + char *option = (char *) xmalloca (10 + strlen (source_file) + 1); + + memcpy (option, "-resource:", 10); + strcpy (option + 10, source_file); + *argp++ = option; + } + else + *argp++ = (char *) source_file; + } *argp = NULL; /* Ensure argv length was correctly calculated. */ if (argp - argv != argc) - abort (); + abort (); if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } exitstatus = execute ("csc", "csc", argv, false, false, false, false, - true, true, NULL); + true, true, NULL); for (i = 2; i < 3 + libdirs_count + libraries_count; i++) - freea (argv[i]); + freea (argv[i]); for (i = 0; i < sources_count; i++) - if (argv[argc - sources_count + i] != sources[i]) - freea (argv[argc - sources_count + i]); + if (argv[argc - sources_count + i] != sources[i]) + freea (argv[argc - sources_count + i]); freea (argv); return (exitstatus != 0); @@ -504,14 +504,14 @@ compile_csharp_using_sscli (const char * const *sources, bool compile_csharp_class (const char * const *sources, - unsigned int sources_count, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *libraries, - unsigned int libraries_count, - const char *output_file, - bool optimize, bool debug, - bool verbose) + unsigned int sources_count, + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *libraries, + unsigned int libraries_count, + const char *output_file, + bool optimize, bool debug, + bool verbose) { bool output_is_library = (strlen (output_file) >= 4 @@ -521,20 +521,20 @@ compile_csharp_class (const char * const *sources, /* First try the C# implementation specified through --enable-csharp. */ #if CSHARP_CHOICE_PNET result = compile_csharp_using_pnet (sources, sources_count, - libdirs, libdirs_count, - libraries, libraries_count, - output_file, output_is_library, - optimize, debug, verbose); + libdirs, libdirs_count, + libraries, libraries_count, + output_file, output_is_library, + optimize, debug, verbose); if (result >= 0) return (bool) result; #endif #if CSHARP_CHOICE_MONO result = compile_csharp_using_mono (sources, sources_count, - libdirs, libdirs_count, - libraries, libraries_count, - output_file, output_is_library, - optimize, debug, verbose); + libdirs, libdirs_count, + libraries, libraries_count, + output_file, output_is_library, + optimize, debug, verbose); if (result >= 0) return (bool) result; #endif @@ -542,29 +542,29 @@ compile_csharp_class (const char * const *sources, /* Then try the remaining C# implementations in our standard order. */ #if !CSHARP_CHOICE_PNET result = compile_csharp_using_pnet (sources, sources_count, - libdirs, libdirs_count, - libraries, libraries_count, - output_file, output_is_library, - optimize, debug, verbose); + libdirs, libdirs_count, + libraries, libraries_count, + output_file, output_is_library, + optimize, debug, verbose); if (result >= 0) return (bool) result; #endif #if !CSHARP_CHOICE_MONO result = compile_csharp_using_mono (sources, sources_count, - libdirs, libdirs_count, - libraries, libraries_count, - output_file, output_is_library, - optimize, debug, verbose); + libdirs, libdirs_count, + libraries, libraries_count, + output_file, output_is_library, + optimize, debug, verbose); if (result >= 0) return (bool) result; #endif result = compile_csharp_using_sscli (sources, sources_count, - libdirs, libdirs_count, - libraries, libraries_count, - output_file, output_is_library, - optimize, debug, verbose); + libdirs, libdirs_count, + libraries, libraries_count, + output_file, output_is_library, + optimize, debug, verbose); if (result >= 0) return (bool) result; diff --git a/lib/csharpcomp.h b/lib/csharpcomp.h index 46c319f8a..c884e4ed4 100644 --- a/lib/csharpcomp.h +++ b/lib/csharpcomp.h @@ -28,13 +28,13 @@ If verbose, the command to be executed will be printed. Return false if OK, true on error. */ extern bool compile_csharp_class (const char * const *sources, - unsigned int sources_count, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *libraries, - unsigned int libraries_count, - const char *output_file, - bool optimize, bool debug, - bool verbose); + unsigned int sources_count, + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *libraries, + unsigned int libraries_count, + const char *output_file, + bool optimize, bool debug, + bool verbose); #endif /* _CSHARPCOMP_H */ diff --git a/lib/csharpexec.c b/lib/csharpexec.c index c1fc27ab6..1a1a43856 100644 --- a/lib/csharpexec.c +++ b/lib/csharpexec.c @@ -89,11 +89,11 @@ static int execute_csharp_using_pnet (const char *assembly_path, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *args, unsigned int nargs, - bool verbose, bool quiet, - execute_fn *executer, void *private_data) + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *args, unsigned int nargs, + bool verbose, bool quiet, + execute_fn *executer, void *private_data) { static bool ilrun_tested; static bool ilrun_present; @@ -101,7 +101,7 @@ execute_csharp_using_pnet (const char *assembly_path, if (!ilrun_tested) { /* Test for presence of ilrun: - "ilrun --version >/dev/null 2>/dev/null" */ + "ilrun --version >/dev/null 2>/dev/null" */ char *argv[3]; int exitstatus; @@ -109,7 +109,7 @@ execute_csharp_using_pnet (const char *assembly_path, argv[1] = "--version"; argv[2] = NULL; exitstatus = execute ("ilrun", "ilrun", argv, false, false, true, true, - true, false, NULL); + true, false, NULL); ilrun_present = (exitstatus == 0); ilrun_tested = true; } @@ -128,24 +128,24 @@ execute_csharp_using_pnet (const char *assembly_path, argp = argv; *argp++ = "ilrun"; for (i = 0; i < libdirs_count; i++) - { - *argp++ = "-L"; - *argp++ = (char *) libdirs[i]; - } + { + *argp++ = "-L"; + *argp++ = (char *) libdirs[i]; + } *argp++ = (char *) assembly_path; for (i = 0; i < nargs; i++) - *argp++ = (char *) args[i]; + *argp++ = (char *) args[i]; *argp = NULL; /* Ensure argv length was correctly calculated. */ if (argp - argv != argc) - abort (); + abort (); if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } err = executer ("ilrun", "ilrun", argv, private_data); @@ -159,11 +159,11 @@ execute_csharp_using_pnet (const char *assembly_path, static int execute_csharp_using_mono (const char *assembly_path, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *args, unsigned int nargs, - bool verbose, bool quiet, - execute_fn *executer, void *private_data) + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *args, unsigned int nargs, + bool verbose, bool quiet, + execute_fn *executer, void *private_data) { static bool mono_tested; static bool mono_present; @@ -171,7 +171,7 @@ execute_csharp_using_mono (const char *assembly_path, if (!mono_tested) { /* Test for presence of mono: - "mono --version >/dev/null 2>/dev/null" */ + "mono --version >/dev/null 2>/dev/null" */ char *argv[3]; int exitstatus; @@ -179,7 +179,7 @@ execute_csharp_using_mono (const char *assembly_path, argv[1] = "--version"; argv[2] = NULL; exitstatus = execute ("mono", "mono", argv, false, false, true, true, - true, false, NULL); + true, false, NULL); mono_present = (exitstatus == 0); mono_tested = true; } @@ -197,14 +197,14 @@ execute_csharp_using_mono (const char *assembly_path, argv[0] = "mono"; argv[1] = (char *) assembly_path; for (i = 0; i <= nargs; i++) - argv[2 + i] = (char *) args[i]; + argv[2 + i] = (char *) args[i]; if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } err = executer ("mono", "mono", argv, private_data); @@ -221,11 +221,11 @@ execute_csharp_using_mono (const char *assembly_path, static int execute_csharp_using_sscli (const char *assembly_path, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *args, unsigned int nargs, - bool verbose, bool quiet, - execute_fn *executer, void *private_data) + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *args, unsigned int nargs, + bool verbose, bool quiet, + execute_fn *executer, void *private_data) { static bool clix_tested; static bool clix_present; @@ -233,14 +233,14 @@ execute_csharp_using_sscli (const char *assembly_path, if (!clix_tested) { /* Test for presence of clix: - "clix >/dev/null 2>/dev/null ; test $? = 1" */ + "clix >/dev/null 2>/dev/null ; test $? = 1" */ char *argv[2]; int exitstatus; argv[0] = "clix"; argv[1] = NULL; exitstatus = execute ("clix", "clix", argv, false, false, true, true, - true, false, NULL); + true, false, NULL); clix_present = (exitstatus == 0 || exitstatus == 1); clix_tested = true; } @@ -258,14 +258,14 @@ execute_csharp_using_sscli (const char *assembly_path, argv[0] = "clix"; argv[1] = (char *) assembly_path; for (i = 0; i <= nargs; i++) - argv[2 + i] = (char *) args[i]; + argv[2 + i] = (char *) args[i]; if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } err = executer ("clix", "clix", argv, private_data); @@ -282,11 +282,11 @@ execute_csharp_using_sscli (const char *assembly_path, bool execute_csharp_program (const char *assembly_path, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *args, - bool verbose, bool quiet, - execute_fn *executer, void *private_data) + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *args, + bool verbose, bool quiet, + execute_fn *executer, void *private_data) { unsigned int nargs; int result; @@ -302,16 +302,16 @@ execute_csharp_program (const char *assembly_path, /* First try the C# implementation specified through --enable-csharp. */ #if CSHARP_CHOICE_PNET result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count, - args, nargs, verbose, quiet, - executer, private_data); + args, nargs, verbose, quiet, + executer, private_data); if (result >= 0) return (bool) result; #endif #if CSHARP_CHOICE_MONO result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count, - args, nargs, verbose, quiet, - executer, private_data); + args, nargs, verbose, quiet, + executer, private_data); if (result >= 0) return (bool) result; #endif @@ -319,23 +319,23 @@ execute_csharp_program (const char *assembly_path, /* Then try the remaining C# implementations in our standard order. */ #if !CSHARP_CHOICE_PNET result = execute_csharp_using_pnet (assembly_path, libdirs, libdirs_count, - args, nargs, verbose, quiet, - executer, private_data); + args, nargs, verbose, quiet, + executer, private_data); if (result >= 0) return (bool) result; #endif #if !CSHARP_CHOICE_MONO result = execute_csharp_using_mono (assembly_path, libdirs, libdirs_count, - args, nargs, verbose, quiet, - executer, private_data); + args, nargs, verbose, quiet, + executer, private_data); if (result >= 0) return (bool) result; #endif result = execute_csharp_using_sscli (assembly_path, libdirs, libdirs_count, - args, nargs, verbose, quiet, - executer, private_data); + args, nargs, verbose, quiet, + executer, private_data); if (result >= 0) return (bool) result; diff --git a/lib/csharpexec.h b/lib/csharpexec.h index 34a164ee1..7e3ec2407 100644 --- a/lib/csharpexec.h +++ b/lib/csharpexec.h @@ -21,8 +21,8 @@ #include typedef bool execute_fn (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data); + const char *prog_path, char **prog_argv, + void *private_data); /* Execute a C# program. assembly_path is the assembly's pathname (= program name with .exe). @@ -34,10 +34,10 @@ typedef bool execute_fn (const char *progname, Return false if OK, true on error. If quiet, error messages will not be printed. */ extern bool execute_csharp_program (const char *assembly_path, - const char * const *libdirs, - unsigned int libdirs_count, - const char * const *args, - bool verbose, bool quiet, - execute_fn *executer, void *private_data); + const char * const *libdirs, + unsigned int libdirs_count, + const char * const *args, + bool verbose, bool quiet, + execute_fn *executer, void *private_data); #endif /* _CSHARPEXEC_H */ diff --git a/lib/cycle-check.c b/lib/cycle-check.c index e120460e6..875c26116 100644 --- a/lib/cycle-check.c +++ b/lib/cycle-check.c @@ -70,12 +70,12 @@ cycle_check (struct cycle_check_state *state, struct stat const *sb) if (is_zero_or_power_of_two (++(state->chdir_counter))) { /* On all architectures that we know about, if the counter - overflows then there is a directory cycle here somewhere, - even if we haven't detected it yet. Typically this happens - only after the counter is incremented 2**64 times, so it's a - fairly theoretical point. */ + overflows then there is a directory cycle here somewhere, + even if we haven't detected it yet. Typically this happens + only after the counter is incremented 2**64 times, so it's a + fairly theoretical point. */ if (state->chdir_counter == 0) - return true; + return true; state->dev_ino.st_dev = sb->st_dev; state->dev_ino.st_ino = sb->st_ino; diff --git a/lib/cycle-check.h b/lib/cycle-check.h index ee3bf214b..65c311773 100644 --- a/lib/cycle-check.h +++ b/lib/cycle-check.h @@ -35,18 +35,18 @@ struct cycle_check_state void cycle_check_init (struct cycle_check_state *state); bool cycle_check (struct cycle_check_state *state, struct stat const *sb); -# define CYCLE_CHECK_REFLECT_CHDIR_UP(State, SB_dir, SB_subdir) \ - do \ - { \ +# define CYCLE_CHECK_REFLECT_CHDIR_UP(State, SB_dir, SB_subdir) \ + do \ + { \ /* You must call cycle_check at least once before using this macro. */ \ - if ((State)->chdir_counter == 0) \ - abort (); \ - if (SAME_INODE ((State)->dev_ino, SB_subdir)) \ - { \ - (State)->dev_ino.st_dev = (SB_dir).st_dev; \ - (State)->dev_ino.st_ino = (SB_dir).st_ino; \ - } \ - } \ + if ((State)->chdir_counter == 0) \ + abort (); \ + if (SAME_INODE ((State)->dev_ino, SB_subdir)) \ + { \ + (State)->dev_ino.st_dev = (SB_dir).st_dev; \ + (State)->dev_ino.st_ino = (SB_dir).st_ino; \ + } \ + } \ while (0) #endif diff --git a/lib/des.c b/lib/des.c index e2c798609..f6aa64fb0 100644 --- a/lib/des.c +++ b/lib/des.c @@ -99,7 +99,7 @@ #include "des.h" #include -#include /* memcpy, memcmp */ +#include /* memcpy, memcmp */ /* * The s-box values are permuted according to the 'primitive function P' @@ -253,70 +253,70 @@ static const unsigned char encrypt_rotate_tab[16] = { * bits cleared. */ static const unsigned char weak_keys[64][8] = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*w */ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*w */ {0x00, 0x00, 0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e}, {0x00, 0x00, 0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0}, {0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe}, - {0x00, 0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e}, /*sw */ + {0x00, 0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e}, /*sw */ {0x00, 0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e, 0x00}, {0x00, 0x1e, 0xe0, 0xfe, 0x00, 0x0e, 0xf0, 0xfe}, {0x00, 0x1e, 0xfe, 0xe0, 0x00, 0x0e, 0xfe, 0xf0}, - {0x00, 0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0}, /*sw */ + {0x00, 0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0}, /*sw */ {0x00, 0xe0, 0x1e, 0xfe, 0x00, 0xf0, 0x0e, 0xfe}, {0x00, 0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0, 0x00}, {0x00, 0xe0, 0xfe, 0x1e, 0x00, 0xf0, 0xfe, 0x0e}, - {0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe}, /*sw */ + {0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe}, /*sw */ {0x00, 0xfe, 0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0}, {0x00, 0xfe, 0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e}, {0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00}, {0x1e, 0x00, 0x00, 0x1e, 0x0e, 0x00, 0x00, 0x0e}, - {0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e, 0x00}, /*sw */ + {0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e, 0x00}, /*sw */ {0x1e, 0x00, 0xe0, 0xfe, 0x0e, 0x00, 0xf0, 0xfe}, {0x1e, 0x00, 0xfe, 0xe0, 0x0e, 0x00, 0xfe, 0xf0}, {0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e, 0x00, 0x00}, - {0x1e, 0x1e, 0x1e, 0x1e, 0x0e, 0x0e, 0x0e, 0x0e}, /*w */ + {0x1e, 0x1e, 0x1e, 0x1e, 0x0e, 0x0e, 0x0e, 0x0e}, /*w */ {0x1e, 0x1e, 0xe0, 0xe0, 0x0e, 0x0e, 0xf0, 0xf0}, {0x1e, 0x1e, 0xfe, 0xfe, 0x0e, 0x0e, 0xfe, 0xfe}, {0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0, 0x00, 0xfe}, - {0x1e, 0xe0, 0x1e, 0xe0, 0x0e, 0xf0, 0x0e, 0xf0}, /*sw */ + {0x1e, 0xe0, 0x1e, 0xe0, 0x0e, 0xf0, 0x0e, 0xf0}, /*sw */ {0x1e, 0xe0, 0xe0, 0x1e, 0x0e, 0xf0, 0xf0, 0x0e}, {0x1e, 0xe0, 0xfe, 0x00, 0x0e, 0xf0, 0xfe, 0x00}, {0x1e, 0xfe, 0x00, 0xe0, 0x0e, 0xfe, 0x00, 0xf0}, - {0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e, 0xfe}, /*sw */ + {0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e, 0xfe}, /*sw */ {0x1e, 0xfe, 0xe0, 0x00, 0x0e, 0xfe, 0xf0, 0x00}, {0x1e, 0xfe, 0xfe, 0x1e, 0x0e, 0xfe, 0xfe, 0x0e}, {0xe0, 0x00, 0x00, 0xe0, 0xf0, 0x00, 0x00, 0xf0}, {0xe0, 0x00, 0x1e, 0xfe, 0xf0, 0x00, 0x0e, 0xfe}, - {0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0, 0x00}, /*sw */ + {0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0, 0x00}, /*sw */ {0xe0, 0x00, 0xfe, 0x1e, 0xf0, 0x00, 0xfe, 0x0e}, {0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e, 0x00, 0xfe}, {0xe0, 0x1e, 0x1e, 0xe0, 0xf0, 0x0e, 0x0e, 0xf0}, - {0xe0, 0x1e, 0xe0, 0x1e, 0xf0, 0x0e, 0xf0, 0x0e}, /*sw */ + {0xe0, 0x1e, 0xe0, 0x1e, 0xf0, 0x0e, 0xf0, 0x0e}, /*sw */ {0xe0, 0x1e, 0xfe, 0x00, 0xf0, 0x0e, 0xfe, 0x00}, {0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0, 0x00, 0x00}, {0xe0, 0xe0, 0x1e, 0x1e, 0xf0, 0xf0, 0x0e, 0x0e}, - {0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf0, 0xf0}, /*w */ + {0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf0, 0xf0}, /*w */ {0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0, 0xfe, 0xfe}, {0xe0, 0xfe, 0x00, 0x1e, 0xf0, 0xfe, 0x00, 0x0e}, {0xe0, 0xfe, 0x1e, 0x00, 0xf0, 0xfe, 0x0e, 0x00}, - {0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0, 0xfe}, /*sw */ + {0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0, 0xfe}, /*sw */ {0xe0, 0xfe, 0xfe, 0xe0, 0xf0, 0xfe, 0xfe, 0xf0}, {0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe}, {0xfe, 0x00, 0x1e, 0xe0, 0xfe, 0x00, 0x0e, 0xf0}, {0xfe, 0x00, 0xe0, 0x1e, 0xfe, 0x00, 0xf0, 0x0e}, - {0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00}, /*sw */ + {0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00}, /*sw */ {0xfe, 0x1e, 0x00, 0xe0, 0xfe, 0x0e, 0x00, 0xf0}, {0xfe, 0x1e, 0x1e, 0xfe, 0xfe, 0x0e, 0x0e, 0xfe}, {0xfe, 0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0, 0x00}, - {0xfe, 0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e}, /*sw */ + {0xfe, 0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e}, /*sw */ {0xfe, 0xe0, 0x00, 0x1e, 0xfe, 0xf0, 0x00, 0x0e}, {0xfe, 0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e, 0x00}, {0xfe, 0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0, 0xfe}, - {0xfe, 0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0}, /*sw */ + {0xfe, 0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0}, /*sw */ {0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00}, {0xfe, 0xfe, 0x1e, 0x1e, 0xfe, 0xfe, 0x0e, 0x0e}, {0xfe, 0xfe, 0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0}, - {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe} /*w */ + {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe} /*w */ }; bool @@ -337,12 +337,12 @@ gl_des_is_weak_key (const char * key) middle = (left + right) / 2; if (!(cmp_result = memcmp (work, weak_keys[middle], 8))) - return -1; + return -1; if (cmp_result > 0) - left = middle + 1; + left = middle + 1; else - right = middle - 1; + right = middle - 1; } return 0; @@ -351,9 +351,9 @@ gl_des_is_weak_key (const char * key) /* * Macro to swap bits across two words. */ -#define DO_PERMUTATION(a, temp, b, offset, mask) \ - temp = ((a>>offset) ^ b) & mask; \ - b ^= temp; \ +#define DO_PERMUTATION(a, temp, b, offset, mask) \ + temp = ((a>>offset) ^ b) & mask; \ + b ^= temp; \ a ^= temp<> 31); \ - temp = (left ^ right) & 0xaaaaaaaa; \ - right ^= temp; \ - left ^= temp; \ +#define INITIAL_PERMUTATION(left, temp, right) \ + DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \ + DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ + DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ + DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ + right = (right << 1) | (right >> 31); \ + temp = (left ^ right) & 0xaaaaaaaa; \ + right ^= temp; \ + left ^= temp; \ left = (left << 1) | (left >> 31); /* * The 'inverse initial permutation'. */ -#define FINAL_PERMUTATION(left, temp, right) \ - left = (left << 31) | (left >> 1); \ - temp = (left ^ right) & 0xaaaaaaaa; \ - left ^= temp; \ - right ^= temp; \ - right = (right << 31) | (right >> 1); \ - DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ - DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ - DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ +#define FINAL_PERMUTATION(left, temp, right) \ + left = (left << 31) | (left >> 1); \ + temp = (left ^ right) & 0xaaaaaaaa; \ + left ^= temp; \ + right ^= temp; \ + right = (right << 31) | (right >> 1); \ + DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ + DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ + DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) @@ -394,40 +394,40 @@ gl_des_is_weak_key (const char * key) * Please note: The data in 'from' and 'to' is already rotated one bit to * the left, done in the initial permutation. */ -#define DES_ROUND(from, to, work, subkey) \ - work = from ^ *subkey++; \ - to ^= sbox8[ work & 0x3f ]; \ - to ^= sbox6[ (work>>8) & 0x3f ]; \ - to ^= sbox4[ (work>>16) & 0x3f ]; \ - to ^= sbox2[ (work>>24) & 0x3f ]; \ - work = ((from << 28) | (from >> 4)) ^ *subkey++; \ - to ^= sbox7[ work & 0x3f ]; \ - to ^= sbox5[ (work>>8) & 0x3f ]; \ - to ^= sbox3[ (work>>16) & 0x3f ]; \ +#define DES_ROUND(from, to, work, subkey) \ + work = from ^ *subkey++; \ + to ^= sbox8[ work & 0x3f ]; \ + to ^= sbox6[ (work>>8) & 0x3f ]; \ + to ^= sbox4[ (work>>16) & 0x3f ]; \ + to ^= sbox2[ (work>>24) & 0x3f ]; \ + work = ((from << 28) | (from >> 4)) ^ *subkey++; \ + to ^= sbox7[ work & 0x3f ]; \ + to ^= sbox5[ (work>>8) & 0x3f ]; \ + to ^= sbox3[ (work>>16) & 0x3f ]; \ to ^= sbox1[ (work>>24) & 0x3f ]; /* * Macros to convert 8 bytes from/to 32bit words. */ -#define READ_64BIT_DATA(data, left, right) \ +#define READ_64BIT_DATA(data, left, right) \ left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \ right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7]; -#define WRITE_64BIT_DATA(data, left, right) \ - data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \ - data[2] = (left >> 8) &0xff; data[3] = left &0xff; \ - data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \ +#define WRITE_64BIT_DATA(data, left, right) \ + data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \ + data[2] = (left >> 8) &0xff; data[3] = left &0xff; \ + data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \ data[6] = (right >> 8) &0xff; data[7] = right &0xff; /* - * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for - * 16 encryption rounds. - * To calculate subkeys for decryption the caller - * have to reorder the generated subkeys. + * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for + * 16 encryption rounds. + * To calculate subkeys for decryption the caller + * have to reorder the generated subkeys. * - * rawkey: 8 Bytes of key data - * subkey: Array of at least 32 uint32_ts. Will be filled - * with calculated subkeys. + * rawkey: 8 Bytes of key data + * subkey: Array of at least 32 uint32_ts. Will be filled + * with calculated subkeys. * */ static void @@ -441,79 +441,79 @@ des_key_schedule (const char * _rawkey, uint32_t * subkey) DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f) DO_PERMUTATION (right, work, left, 0, 0x10101010) left = ((leftkey_swap[(left >> 0) & 0xf] << 3) - | (leftkey_swap[(left >> 8) & 0xf] << 2) - | (leftkey_swap[(left >> 16) & 0xf] << 1) - | (leftkey_swap[(left >> 24) & 0xf]) - | (leftkey_swap[(left >> 5) & 0xf] << 7) - | (leftkey_swap[(left >> 13) & 0xf] << 6) - | (leftkey_swap[(left >> 21) & 0xf] << 5) - | (leftkey_swap[(left >> 29) & 0xf] << 4)); + | (leftkey_swap[(left >> 8) & 0xf] << 2) + | (leftkey_swap[(left >> 16) & 0xf] << 1) + | (leftkey_swap[(left >> 24) & 0xf]) + | (leftkey_swap[(left >> 5) & 0xf] << 7) + | (leftkey_swap[(left >> 13) & 0xf] << 6) + | (leftkey_swap[(left >> 21) & 0xf] << 5) + | (leftkey_swap[(left >> 29) & 0xf] << 4)); left &= 0x0fffffff; right = ((rightkey_swap[(right >> 1) & 0xf] << 3) - | (rightkey_swap[(right >> 9) & 0xf] << 2) - | (rightkey_swap[(right >> 17) & 0xf] << 1) - | (rightkey_swap[(right >> 25) & 0xf]) - | (rightkey_swap[(right >> 4) & 0xf] << 7) - | (rightkey_swap[(right >> 12) & 0xf] << 6) - | (rightkey_swap[(right >> 20) & 0xf] << 5) - | (rightkey_swap[(right >> 28) & 0xf] << 4)); + | (rightkey_swap[(right >> 9) & 0xf] << 2) + | (rightkey_swap[(right >> 17) & 0xf] << 1) + | (rightkey_swap[(right >> 25) & 0xf]) + | (rightkey_swap[(right >> 4) & 0xf] << 7) + | (rightkey_swap[(right >> 12) & 0xf] << 6) + | (rightkey_swap[(right >> 20) & 0xf] << 5) + | (rightkey_swap[(right >> 28) & 0xf] << 4)); right &= 0x0fffffff; for (round = 0; round < 16; ++round) { left = ((left << encrypt_rotate_tab[round]) - | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; + | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; right = ((right << encrypt_rotate_tab[round]) - | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; + | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; *subkey++ = (((left << 4) & 0x24000000) - | ((left << 28) & 0x10000000) - | ((left << 14) & 0x08000000) - | ((left << 18) & 0x02080000) - | ((left << 6) & 0x01000000) - | ((left << 9) & 0x00200000) - | ((left >> 1) & 0x00100000) - | ((left << 10) & 0x00040000) - | ((left << 2) & 0x00020000) - | ((left >> 10) & 0x00010000) - | ((right >> 13) & 0x00002000) - | ((right >> 4) & 0x00001000) - | ((right << 6) & 0x00000800) - | ((right >> 1) & 0x00000400) - | ((right >> 14) & 0x00000200) - | (right & 0x00000100) - | ((right >> 5) & 0x00000020) - | ((right >> 10) & 0x00000010) - | ((right >> 3) & 0x00000008) - | ((right >> 18) & 0x00000004) - | ((right >> 26) & 0x00000002) - | ((right >> 24) & 0x00000001)); + | ((left << 28) & 0x10000000) + | ((left << 14) & 0x08000000) + | ((left << 18) & 0x02080000) + | ((left << 6) & 0x01000000) + | ((left << 9) & 0x00200000) + | ((left >> 1) & 0x00100000) + | ((left << 10) & 0x00040000) + | ((left << 2) & 0x00020000) + | ((left >> 10) & 0x00010000) + | ((right >> 13) & 0x00002000) + | ((right >> 4) & 0x00001000) + | ((right << 6) & 0x00000800) + | ((right >> 1) & 0x00000400) + | ((right >> 14) & 0x00000200) + | (right & 0x00000100) + | ((right >> 5) & 0x00000020) + | ((right >> 10) & 0x00000010) + | ((right >> 3) & 0x00000008) + | ((right >> 18) & 0x00000004) + | ((right >> 26) & 0x00000002) + | ((right >> 24) & 0x00000001)); *subkey++ = (((left << 15) & 0x20000000) - | ((left << 17) & 0x10000000) - | ((left << 10) & 0x08000000) - | ((left << 22) & 0x04000000) - | ((left >> 2) & 0x02000000) - | ((left << 1) & 0x01000000) - | ((left << 16) & 0x00200000) - | ((left << 11) & 0x00100000) - | ((left << 3) & 0x00080000) - | ((left >> 6) & 0x00040000) - | ((left << 15) & 0x00020000) - | ((left >> 4) & 0x00010000) - | ((right >> 2) & 0x00002000) - | ((right << 8) & 0x00001000) - | ((right >> 14) & 0x00000808) - | ((right >> 9) & 0x00000400) - | ((right) & 0x00000200) - | ((right << 7) & 0x00000100) - | ((right >> 7) & 0x00000020) - | ((right >> 3) & 0x00000011) - | ((right << 2) & 0x00000004) - | ((right >> 21) & 0x00000002)); + | ((left << 17) & 0x10000000) + | ((left << 10) & 0x08000000) + | ((left << 22) & 0x04000000) + | ((left >> 2) & 0x02000000) + | ((left << 1) & 0x01000000) + | ((left << 16) & 0x00200000) + | ((left << 11) & 0x00100000) + | ((left << 3) & 0x00080000) + | ((left >> 6) & 0x00040000) + | ((left << 15) & 0x00020000) + | ((left >> 4) & 0x00010000) + | ((right >> 2) & 0x00002000) + | ((right << 8) & 0x00001000) + | ((right >> 14) & 0x00000808) + | ((right >> 9) & 0x00000400) + | ((right) & 0x00000200) + | ((right << 7) & 0x00000100) + | ((right >> 7) & 0x00000020) + | ((right >> 3) & 0x00000011) + | ((right << 2) & 0x00000004) + | ((right >> 21) & 0x00000002)); } } @@ -592,7 +592,7 @@ gl_3des_set2keys (gl_3des_ctx *ctx, const char * key1, const char * key2) void gl_3des_set3keys (gl_3des_ctx *ctx, const char * key1, - const char * key2, const char * key3) + const char * key2, const char * key3) { int i; @@ -615,8 +615,8 @@ gl_3des_set3keys (gl_3des_ctx *ctx, const char * key1, void gl_3des_ecb_crypt (gl_3des_ctx *ctx, - const char * _from, - char * _to, int mode) + const char * _from, + char * _to, int mode) { const unsigned char *from = (const unsigned char *) _from; unsigned char *to = (unsigned char *) _to; @@ -664,6 +664,6 @@ gl_3des_makekey (gl_3des_ctx *ctx, const char * key, size_t keylen) gl_3des_set3keys (ctx, key, key + 8, key + 16); return !(gl_des_is_weak_key (key) - || gl_des_is_weak_key (key + 8) - || gl_des_is_weak_key (key + 16)); + || gl_des_is_weak_key (key + 8) + || gl_des_is_weak_key (key + 16)); } diff --git a/lib/des.h b/lib/des.h index 9ada75277..3ff51c058 100644 --- a/lib/des.h +++ b/lib/des.h @@ -84,8 +84,8 @@ gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from, char * to, int mode); * keys, but simply ignore them. Does not check for weak keys. */ extern void gl_3des_set2keys (gl_3des_ctx *ctx, - const char * key1, - const char * key2); + const char * key1, + const char * key2); /* * Fill a Triple-DES context CTX with subkeys calculated from three @@ -94,26 +94,26 @@ gl_3des_set2keys (gl_3des_ctx *ctx, * keys. */ extern void gl_3des_set3keys (gl_3des_ctx *ctx, - const char * key1, - const char * key2, - const char * key3); + const char * key1, + const char * key2, + const char * key3); /* Fill a Triple-DES context CTX with subkeys calculated from three * concatenated 64bit keys in KEY, with weak key checking. Does not * check the parity bits of the keys, but simply ignore them. */ extern bool gl_3des_makekey (gl_3des_ctx *ctx, - const char * key, - size_t keylen); + const char * key, + size_t keylen); /* Electronic Codebook Mode Triple-DES encryption/decryption of data * according to 'mode'. Sometimes this mode is named 'EDE' mode * (Encryption-Decryption-Encryption). */ extern void gl_3des_ecb_crypt (gl_3des_ctx *ctx, - const char * from, - char * to, - int mode); + const char * from, + char * to, + int mode); #define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0) #define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1) diff --git a/lib/diacrit.c b/lib/diacrit.c index 7fe3a81f8..7a2cd13fe 100644 --- a/lib/diacrit.c +++ b/lib/diacrit.c @@ -29,7 +29,7 @@ /*--------------------------------------------------------------------. | For each alphabetic character, returns what it would be without its | -| possible diacritic symbol. | +| possible diacritic symbol. | `--------------------------------------------------------------------*/ const char diacrit_base[256] = @@ -95,9 +95,9 @@ const char diacrit_base[256] = /*------------------------------------------------------------------------. | For each alphabetic character, returns a code of what its diacritic is, | | according to the following codes: 1 (eE) over aA for latin diphtongs; 2 | -| (') acute accent; 3 (`) grave accent; 4 (^) circumflex accent; 5 (") | +| (') acute accent; 3 (`) grave accent; 4 (^) circumflex accent; 5 (") | | umlaut or diaraesis; 6 (~) tilda; 7 (,) cedilla; 8 (o) covering degree | -| symbol; 9 (|) slashed character. | +| symbol; 9 (|) slashed character. | `------------------------------------------------------------------------*/ const char diacrit_diac[256] = diff --git a/lib/diffseq.h b/lib/diffseq.h index 9d2b198dc..69af61d61 100644 --- a/lib/diffseq.h +++ b/lib/diffseq.h @@ -168,252 +168,252 @@ static void diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal, struct partition *part, struct context *ctxt) { - OFFSET *const fd = ctxt->fdiag; /* Give the compiler a chance. */ - OFFSET *const bd = ctxt->bdiag; /* Additional help for the compiler. */ - ELEMENT const *const xv = ctxt->xvec; /* Still more help for the compiler. */ - ELEMENT const *const yv = ctxt->yvec; /* And more and more . . . */ - const OFFSET dmin = xoff - ylim; /* Minimum valid diagonal. */ - const OFFSET dmax = xlim - yoff; /* Maximum valid diagonal. */ - const OFFSET fmid = xoff - yoff; /* Center diagonal of top-down search. */ - const OFFSET bmid = xlim - ylim; /* Center diagonal of bottom-up search. */ + OFFSET *const fd = ctxt->fdiag; /* Give the compiler a chance. */ + OFFSET *const bd = ctxt->bdiag; /* Additional help for the compiler. */ + ELEMENT const *const xv = ctxt->xvec; /* Still more help for the compiler. */ + ELEMENT const *const yv = ctxt->yvec; /* And more and more . . . */ + const OFFSET dmin = xoff - ylim; /* Minimum valid diagonal. */ + const OFFSET dmax = xlim - yoff; /* Maximum valid diagonal. */ + const OFFSET fmid = xoff - yoff; /* Center diagonal of top-down search. */ + const OFFSET bmid = xlim - ylim; /* Center diagonal of bottom-up search. */ OFFSET fmin = fmid; - OFFSET fmax = fmid; /* Limits of top-down search. */ + OFFSET fmax = fmid; /* Limits of top-down search. */ OFFSET bmin = bmid; - OFFSET bmax = bmid; /* Limits of bottom-up search. */ - OFFSET c; /* Cost. */ - bool odd = (fmid - bmid) & 1; /* True if southeast corner is on an odd - diagonal with respect to the northwest. */ + OFFSET bmax = bmid; /* Limits of bottom-up search. */ + OFFSET c; /* Cost. */ + bool odd = (fmid - bmid) & 1; /* True if southeast corner is on an odd + diagonal with respect to the northwest. */ fd[fmid] = xoff; bd[bmid] = xlim; for (c = 1;; ++c) { - OFFSET d; /* Active diagonal. */ + OFFSET d; /* Active diagonal. */ bool big_snake = false; /* Extend the top-down search by an edit step in each diagonal. */ if (fmin > dmin) - fd[--fmin - 1] = -1; + fd[--fmin - 1] = -1; else - ++fmin; + ++fmin; if (fmax < dmax) - fd[++fmax + 1] = -1; + fd[++fmax + 1] = -1; else - --fmax; + --fmax; for (d = fmax; d >= fmin; d -= 2) - { - OFFSET x; - OFFSET y; - OFFSET tlo = fd[d - 1]; - OFFSET thi = fd[d + 1]; - OFFSET x0 = tlo < thi ? thi : tlo + 1; - - for (x = x0, y = x0 - d; - x < xlim && y < ylim && EQUAL (xv[x], yv[y]); - x++, y++) - continue; - if (x - x0 > SNAKE_LIMIT) - big_snake = true; - fd[d] = x; - if (odd && bmin <= d && d <= bmax && bd[d] <= x) - { - part->xmid = x; - part->ymid = y; - part->lo_minimal = part->hi_minimal = true; - return; - } - } + { + OFFSET x; + OFFSET y; + OFFSET tlo = fd[d - 1]; + OFFSET thi = fd[d + 1]; + OFFSET x0 = tlo < thi ? thi : tlo + 1; + + for (x = x0, y = x0 - d; + x < xlim && y < ylim && EQUAL (xv[x], yv[y]); + x++, y++) + continue; + if (x - x0 > SNAKE_LIMIT) + big_snake = true; + fd[d] = x; + if (odd && bmin <= d && d <= bmax && bd[d] <= x) + { + part->xmid = x; + part->ymid = y; + part->lo_minimal = part->hi_minimal = true; + return; + } + } /* Similarly extend the bottom-up search. */ if (bmin > dmin) - bd[--bmin - 1] = OFFSET_MAX; + bd[--bmin - 1] = OFFSET_MAX; else - ++bmin; + ++bmin; if (bmax < dmax) - bd[++bmax + 1] = OFFSET_MAX; + bd[++bmax + 1] = OFFSET_MAX; else - --bmax; + --bmax; for (d = bmax; d >= bmin; d -= 2) - { - OFFSET x; - OFFSET y; - OFFSET tlo = bd[d - 1]; - OFFSET thi = bd[d + 1]; - OFFSET x0 = tlo < thi ? tlo : thi - 1; - - for (x = x0, y = x0 - d; - xoff < x && yoff < y && EQUAL (xv[x - 1], yv[y - 1]); - x--, y--) - continue; - if (x0 - x > SNAKE_LIMIT) - big_snake = true; - bd[d] = x; - if (!odd && fmin <= d && d <= fmax && x <= fd[d]) - { - part->xmid = x; - part->ymid = y; - part->lo_minimal = part->hi_minimal = true; - return; - } - } + { + OFFSET x; + OFFSET y; + OFFSET tlo = bd[d - 1]; + OFFSET thi = bd[d + 1]; + OFFSET x0 = tlo < thi ? tlo : thi - 1; + + for (x = x0, y = x0 - d; + xoff < x && yoff < y && EQUAL (xv[x - 1], yv[y - 1]); + x--, y--) + continue; + if (x0 - x > SNAKE_LIMIT) + big_snake = true; + bd[d] = x; + if (!odd && fmin <= d && d <= fmax && x <= fd[d]) + { + part->xmid = x; + part->ymid = y; + part->lo_minimal = part->hi_minimal = true; + return; + } + } if (find_minimal) - continue; + continue; #ifdef USE_HEURISTIC /* Heuristic: check occasionally for a diagonal that has made lots - of progress compared with the edit distance. If we have any - such, find the one that has made the most progress and return it - as if it had succeeded. + of progress compared with the edit distance. If we have any + such, find the one that has made the most progress and return it + as if it had succeeded. - With this heuristic, for vectors with a constant small density - of changes, the algorithm is linear in the vector size. */ + With this heuristic, for vectors with a constant small density + of changes, the algorithm is linear in the vector size. */ if (200 < c && big_snake && ctxt->heuristic) - { - { - OFFSET best = 0; - - for (d = fmax; d >= fmin; d -= 2) - { - OFFSET dd = d - fmid; - OFFSET x = fd[d]; - OFFSET y = x - d; - OFFSET v = (x - xoff) * 2 - dd; - - if (v > 12 * (c + (dd < 0 ? -dd : dd))) - { - if (v > best - && xoff + SNAKE_LIMIT <= x && x < xlim - && yoff + SNAKE_LIMIT <= y && y < ylim) - { - /* We have a good enough best diagonal; now insist - that it end with a significant snake. */ - int k; - - for (k = 1; EQUAL (xv[x - k], yv[y - k]); k++) - if (k == SNAKE_LIMIT) - { - best = v; - part->xmid = x; - part->ymid = y; - break; - } - } - } - } - if (best > 0) - { - part->lo_minimal = true; - part->hi_minimal = false; - return; - } - } - - { - OFFSET best = 0; - - for (d = bmax; d >= bmin; d -= 2) - { - OFFSET dd = d - bmid; - OFFSET x = bd[d]; - OFFSET y = x - d; - OFFSET v = (xlim - x) * 2 + dd; - - if (v > 12 * (c + (dd < 0 ? -dd : dd))) - { - if (v > best - && xoff < x && x <= xlim - SNAKE_LIMIT - && yoff < y && y <= ylim - SNAKE_LIMIT) - { - /* We have a good enough best diagonal; now insist - that it end with a significant snake. */ - int k; - - for (k = 0; EQUAL (xv[x + k], yv[y + k]); k++) - if (k == SNAKE_LIMIT - 1) - { - best = v; - part->xmid = x; - part->ymid = y; - break; - } - } - } - } - if (best > 0) - { - part->lo_minimal = false; - part->hi_minimal = true; - return; - } - } - } + { + { + OFFSET best = 0; + + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET dd = d - fmid; + OFFSET x = fd[d]; + OFFSET y = x - d; + OFFSET v = (x - xoff) * 2 - dd; + + if (v > 12 * (c + (dd < 0 ? -dd : dd))) + { + if (v > best + && xoff + SNAKE_LIMIT <= x && x < xlim + && yoff + SNAKE_LIMIT <= y && y < ylim) + { + /* We have a good enough best diagonal; now insist + that it end with a significant snake. */ + int k; + + for (k = 1; EQUAL (xv[x - k], yv[y - k]); k++) + if (k == SNAKE_LIMIT) + { + best = v; + part->xmid = x; + part->ymid = y; + break; + } + } + } + } + if (best > 0) + { + part->lo_minimal = true; + part->hi_minimal = false; + return; + } + } + + { + OFFSET best = 0; + + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET dd = d - bmid; + OFFSET x = bd[d]; + OFFSET y = x - d; + OFFSET v = (xlim - x) * 2 + dd; + + if (v > 12 * (c + (dd < 0 ? -dd : dd))) + { + if (v > best + && xoff < x && x <= xlim - SNAKE_LIMIT + && yoff < y && y <= ylim - SNAKE_LIMIT) + { + /* We have a good enough best diagonal; now insist + that it end with a significant snake. */ + int k; + + for (k = 0; EQUAL (xv[x + k], yv[y + k]); k++) + if (k == SNAKE_LIMIT - 1) + { + best = v; + part->xmid = x; + part->ymid = y; + break; + } + } + } + } + if (best > 0) + { + part->lo_minimal = false; + part->hi_minimal = true; + return; + } + } + } #endif /* USE_HEURISTIC */ /* Heuristic: if we've gone well beyond the call of duty, give up - and report halfway between our best results so far. */ + and report halfway between our best results so far. */ if (c >= ctxt->too_expensive) - { - OFFSET fxybest; - OFFSET fxbest IF_LINT (= 0); - OFFSET bxybest; - OFFSET bxbest IF_LINT (= 0); - - /* Find forward diagonal that maximizes X + Y. */ - fxybest = -1; - for (d = fmax; d >= fmin; d -= 2) - { - OFFSET x = MIN (fd[d], xlim); - OFFSET y = x - d; - if (ylim < y) - { - x = ylim + d; - y = ylim; - } - if (fxybest < x + y) - { - fxybest = x + y; - fxbest = x; - } - } - - /* Find backward diagonal that minimizes X + Y. */ - bxybest = OFFSET_MAX; - for (d = bmax; d >= bmin; d -= 2) - { - OFFSET x = MAX (xoff, bd[d]); - OFFSET y = x - d; - if (y < yoff) - { - x = yoff + d; - y = yoff; - } - if (x + y < bxybest) - { - bxybest = x + y; - bxbest = x; - } - } - - /* Use the better of the two diagonals. */ - if ((xlim + ylim) - bxybest < fxybest - (xoff + yoff)) - { - part->xmid = fxbest; - part->ymid = fxybest - fxbest; - part->lo_minimal = true; - part->hi_minimal = false; - } - else - { - part->xmid = bxbest; - part->ymid = bxybest - bxbest; - part->lo_minimal = false; - part->hi_minimal = true; - } - return; - } + { + OFFSET fxybest; + OFFSET fxbest IF_LINT (= 0); + OFFSET bxybest; + OFFSET bxbest IF_LINT (= 0); + + /* Find forward diagonal that maximizes X + Y. */ + fxybest = -1; + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET x = MIN (fd[d], xlim); + OFFSET y = x - d; + if (ylim < y) + { + x = ylim + d; + y = ylim; + } + if (fxybest < x + y) + { + fxybest = x + y; + fxbest = x; + } + } + + /* Find backward diagonal that minimizes X + Y. */ + bxybest = OFFSET_MAX; + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET x = MAX (xoff, bd[d]); + OFFSET y = x - d; + if (y < yoff) + { + x = yoff + d; + y = yoff; + } + if (x + y < bxybest) + { + bxybest = x + y; + bxbest = x; + } + } + + /* Use the better of the two diagonals. */ + if ((xlim + ylim) - bxybest < fxybest - (xoff + yoff)) + { + part->xmid = fxbest; + part->ymid = fxybest - fxbest; + part->lo_minimal = true; + part->hi_minimal = false; + } + else + { + part->xmid = bxbest; + part->ymid = bxybest - bxbest; + part->lo_minimal = false; + part->hi_minimal = true; + } + return; + } } } @@ -436,7 +436,7 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal, static bool compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, - bool find_minimal, struct context *ctxt) + bool find_minimal, struct context *ctxt) { ELEMENT const *xv = ctxt->xvec; /* Help the compiler. */ ELEMENT const *yv = ctxt->yvec; @@ -459,18 +459,18 @@ compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, if (xoff == xlim) while (yoff < ylim) { - NOTE_INSERT (ctxt, yoff); - if (EARLY_ABORT (ctxt)) - return true; - yoff++; + NOTE_INSERT (ctxt, yoff); + if (EARLY_ABORT (ctxt)) + return true; + yoff++; } else if (yoff == ylim) while (xoff < xlim) { - NOTE_DELETE (ctxt, xoff); - if (EARLY_ABORT (ctxt)) - return true; - xoff++; + NOTE_DELETE (ctxt, xoff); + if (EARLY_ABORT (ctxt)) + return true; + xoff++; } else { @@ -481,9 +481,9 @@ compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, /* Use the partitions to split this problem into subproblems. */ if (compareseq (xoff, part.xmid, yoff, part.ymid, part.lo_minimal, ctxt)) - return true; + return true; if (compareseq (part.xmid, xlim, part.ymid, ylim, part.hi_minimal, ctxt)) - return true; + return true; } return false; diff --git a/lib/dirchownmod.c b/lib/dirchownmod.c index 3b21a758a..eee0692a1 100644 --- a/lib/dirchownmod.c +++ b/lib/dirchownmod.c @@ -59,8 +59,8 @@ int dirchownmod (int fd, char const *dir, mode_t mkdir_mode, - uid_t owner, gid_t group, - mode_t mode, mode_t mode_bits) + uid_t owner, gid_t group, + mode_t mode, mode_t mode_bits) { struct stat st; int result = (fd < 0 ? stat (dir, &st) : fstat (fd, &st)); @@ -70,71 +70,71 @@ dirchownmod (int fd, char const *dir, mode_t mkdir_mode, mode_t dir_mode = st.st_mode; /* Check whether DIR is a directory. If FD is nonnegative, this - check avoids changing the ownership and mode bits of the - wrong file in many cases. This doesn't fix all the race - conditions, but it is better than nothing. */ + check avoids changing the ownership and mode bits of the + wrong file in many cases. This doesn't fix all the race + conditions, but it is better than nothing. */ if (! S_ISDIR (dir_mode)) - { - errno = ENOTDIR; - result = -1; - } + { + errno = ENOTDIR; + result = -1; + } else - { - /* If at least one of the S_IXUGO bits are set, chown might - clear the S_ISUID and S_SGID bits. Keep track of any - file mode bits whose values are indeterminate due to this - issue. */ - mode_t indeterminate = 0; - - /* On some systems, chown clears S_ISUID and S_ISGID, so do - chown before chmod. On older System V hosts, ordinary - users can give their files away via chown; don't worry - about that here, since users shouldn't do that. */ - - if ((owner != (uid_t) -1 && owner != st.st_uid) - || (group != (gid_t) -1 && group != st.st_gid)) - { - result = (0 <= fd - ? fchown (fd, owner, group) - : mkdir_mode != (mode_t) -1 - ? lchown (dir, owner, group) - : chown (dir, owner, group)); - - /* Either the user cares about an indeterminate bit and - it'll be set properly by chmod below, or the user - doesn't care and it's OK to use the bit's pre-chown - value. So there's no need to re-stat DIR here. */ - - if (result == 0 && (dir_mode & S_IXUGO)) - indeterminate = dir_mode & (S_ISUID | S_ISGID); - } - - /* If the file mode bits might not be right, use chmod to - change them. Don't change bits the user doesn't care - about. */ - if (result == 0 && (((dir_mode ^ mode) | indeterminate) & mode_bits)) - { - mode_t chmod_mode = - mode | (dir_mode & CHMOD_MODE_BITS & ~mode_bits); - result = (HAVE_FCHMOD && 0 <= fd - ? fchmod (fd, chmod_mode) - : mkdir_mode != (mode_t) -1 - ? lchmod (dir, chmod_mode) - : chmod (dir, chmod_mode)); - } - } + { + /* If at least one of the S_IXUGO bits are set, chown might + clear the S_ISUID and S_SGID bits. Keep track of any + file mode bits whose values are indeterminate due to this + issue. */ + mode_t indeterminate = 0; + + /* On some systems, chown clears S_ISUID and S_ISGID, so do + chown before chmod. On older System V hosts, ordinary + users can give their files away via chown; don't worry + about that here, since users shouldn't do that. */ + + if ((owner != (uid_t) -1 && owner != st.st_uid) + || (group != (gid_t) -1 && group != st.st_gid)) + { + result = (0 <= fd + ? fchown (fd, owner, group) + : mkdir_mode != (mode_t) -1 + ? lchown (dir, owner, group) + : chown (dir, owner, group)); + + /* Either the user cares about an indeterminate bit and + it'll be set properly by chmod below, or the user + doesn't care and it's OK to use the bit's pre-chown + value. So there's no need to re-stat DIR here. */ + + if (result == 0 && (dir_mode & S_IXUGO)) + indeterminate = dir_mode & (S_ISUID | S_ISGID); + } + + /* If the file mode bits might not be right, use chmod to + change them. Don't change bits the user doesn't care + about. */ + if (result == 0 && (((dir_mode ^ mode) | indeterminate) & mode_bits)) + { + mode_t chmod_mode = + mode | (dir_mode & CHMOD_MODE_BITS & ~mode_bits); + result = (HAVE_FCHMOD && 0 <= fd + ? fchmod (fd, chmod_mode) + : mkdir_mode != (mode_t) -1 + ? lchmod (dir, chmod_mode) + : chmod (dir, chmod_mode)); + } + } } if (0 <= fd) { if (result == 0) - result = close (fd); + result = close (fd); else - { - int e = errno; - close (fd); - errno = e; - } + { + int e = errno; + close (fd); + errno = e; + } } return result; diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 2885c561f..62b7cfb9b 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -87,8 +87,8 @@ extern DIR * opendir (const char *); *NAMELIST. Returns the number of entries selected, or -1 on error. */ # if !@HAVE_SCANDIR@ extern int scandir (const char *dir, struct dirent ***namelist, - int (*filter) (const struct dirent *), - int (*cmp) (const struct dirent **, const struct dirent **)); + int (*filter) (const struct dirent *), + int (*cmp) (const struct dirent **, const struct dirent **)); # endif #elif defined GNULIB_POSIXCHECK # undef scandir diff --git a/lib/dirname.h b/lib/dirname.h index df12ccaaa..192aa2ba2 100644 --- a/lib/dirname.h +++ b/lib/dirname.h @@ -34,9 +34,9 @@ /* 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') + <= 'z' - 'a') # define FILE_SYSTEM_PREFIX_LEN(Filename) \ - (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) + (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) # else # define FILE_SYSTEM_PREFIX_LEN(Filename) 0 # endif @@ -54,7 +54,7 @@ # define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) # else # define IS_ABSOLUTE_FILE_NAME(F) \ - (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F)) + (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F)) # endif # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) diff --git a/lib/dprintf.c b/lib/dprintf.c index 91e4a9314..70f992f0e 100644 --- a/lib/dprintf.c +++ b/lib/dprintf.c @@ -49,11 +49,11 @@ dprintf (int fd, const char *format, ...) if (full_write (fd, output, len) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/dup3.c b/lib/dup3.c index 879a9074f..c61b9ba4b 100644 --- a/lib/dup3.c +++ b/lib/dup3.c @@ -59,17 +59,17 @@ dup3 (int oldfd, int newfd, int flags) static int have_dup3_really; /* 0 = unknown, 1 = yes, -1 = no */ if (have_dup3_really >= 0) { - int result = dup3 (oldfd, newfd, flags); - if (!(result < 0 && errno == ENOSYS)) - { - have_dup3_really = 1; + int result = dup3 (oldfd, newfd, flags); + if (!(result < 0 && errno == ENOSYS)) + { + have_dup3_really = 1; #if REPLACE_FCHDIR - if (0 <= result) - result = _gl_register_dup (oldfd, newfd); + if (0 <= result) + result = _gl_register_dup (oldfd, newfd); #endif - return result; - } - have_dup3_really = -1; + return result; + } + have_dup3_really = -1; } } #endif @@ -101,9 +101,9 @@ dup3 (int oldfd, int newfd, int flags) if (flags & O_CLOEXEC) { /* Neither dup() nor dup2() can create a file descriptor with - O_CLOEXEC = O_NOINHERIT set. We need to use the low-level function - _open_osfhandle for this. Iterate until all file descriptors less - than newfd are filled up. */ + O_CLOEXEC = O_NOINHERIT set. We need to use the low-level function + _open_osfhandle for this. 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]; @@ -111,82 +111,82 @@ dup3 (int oldfd, int newfd, int flags) int result; if (old_handle == INVALID_HANDLE_VALUE) - { - /* oldfd is not open, or is an unassigned standard file - descriptor. */ - errno = EBADF; - return -1; - } + { + /* oldfd is not open, or is an unassigned standard file + descriptor. */ + errno = EBADF; + return -1; + } close (newfd); 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 */ - FALSE, /* InheritHandle */ - DUPLICATE_SAME_ACCESS)) /* Options */ - { - errno = EBADF; /* arbitrary */ - result = -1; - break; - } - duplicated_fd = _open_osfhandle ((long) new_handle, flags); - if (duplicated_fd < 0) - { - CloseHandle (new_handle); - result = -1; - break; - } - if (duplicated_fd > newfd) - /* Shouldn't happen, since newfd is still closed. */ - abort (); - if (duplicated_fd == newfd) - { - result = newfd; - break; - } - - /* Set the bit duplicated_fd in fds_to_close[]. */ - index = (unsigned int) duplicated_fd / CHAR_BIT; - if (index >= fds_to_close_bound) - { - if (index >= sizeof (fds_to_close)) - /* 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); - } + { + 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 */ + FALSE, /* InheritHandle */ + DUPLICATE_SAME_ACCESS)) /* Options */ + { + errno = EBADF; /* arbitrary */ + result = -1; + break; + } + duplicated_fd = _open_osfhandle ((long) new_handle, flags); + if (duplicated_fd < 0) + { + CloseHandle (new_handle); + result = -1; + break; + } + if (duplicated_fd > newfd) + /* Shouldn't happen, since newfd is still closed. */ + abort (); + if (duplicated_fd == newfd) + { + result = newfd; + break; + } + + /* Set the bit duplicated_fd in fds_to_close[]. */ + index = (unsigned int) duplicated_fd / CHAR_BIT; + if (index >= fds_to_close_bound) + { + if (index >= sizeof (fds_to_close)) + /* 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; + 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 (result == newfd) - result = _gl_register_dup (oldfd, newfd); + result = _gl_register_dup (oldfd, newfd); #endif return result; } @@ -208,13 +208,13 @@ dup3 (int oldfd, int newfd, int flags) int fcntl_flags; if ((fcntl_flags = fcntl (newfd, F_GETFD, 0)) < 0 - || fcntl (newfd, F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) - { - int saved_errno = errno; - close (newfd); - errno = saved_errno; - return -1; - } + || fcntl (newfd, F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) + { + int saved_errno = errno; + close (newfd); + errno = saved_errno; + return -1; + } } #endif diff --git a/lib/duplocale.c b/lib/duplocale.c index 86432f7c3..680eeb1a6 100644 --- a/lib/duplocale.c +++ b/lib/duplocale.c @@ -36,33 +36,33 @@ rpl_duplocale (locale_t locale) if (locale == LC_GLOBAL_LOCALE) { /* Create a copy of the locale by fetching the name of each locale - category, starting with LC_CTYPE. */ + category, starting with LC_CTYPE. */ static struct { int cat; int mask; } categories[] = - { - { LC_NUMERIC, LC_NUMERIC_MASK }, - { LC_TIME, LC_TIME_MASK }, - { LC_COLLATE, LC_COLLATE_MASK }, - { LC_MONETARY, LC_MONETARY_MASK }, - { LC_MESSAGES, LC_MESSAGES_MASK } + { + { LC_NUMERIC, LC_NUMERIC_MASK }, + { LC_TIME, LC_TIME_MASK }, + { LC_COLLATE, LC_COLLATE_MASK }, + { LC_MONETARY, LC_MONETARY_MASK }, + { LC_MESSAGES, LC_MESSAGES_MASK } #ifdef LC_PAPER - , { LC_PAPER, LC_PAPER_MASK } + , { LC_PAPER, LC_PAPER_MASK } #endif #ifdef LC_NAME - , { LC_NAME, LC_NAME_MASK } + , { LC_NAME, LC_NAME_MASK } #endif #ifdef LC_ADDRESS - , { LC_ADDRESS, LC_ADDRESS_MASK } + , { LC_ADDRESS, LC_ADDRESS_MASK } #endif #ifdef LC_TELEPHONE - , { LC_TELEPHONE, LC_TELEPHONE_MASK } + , { LC_TELEPHONE, LC_TELEPHONE_MASK } #endif #ifdef LC_MEASUREMENT - , { LC_MEASUREMENT, LC_MEASUREMENT_MASK } + , { LC_MEASUREMENT, LC_MEASUREMENT_MASK } #endif #ifdef LC_IDENTIFICATION - , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK } + , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK } #endif - }; + }; const char *base_name; locale_t base_copy; unsigned int i; @@ -70,28 +70,28 @@ rpl_duplocale (locale_t locale) base_name = setlocale (LC_CTYPE, NULL); base_copy = newlocale (LC_ALL_MASK, base_name, NULL); if (base_copy == NULL) - return NULL; + return NULL; for (i = 0; i < SIZEOF (categories); i++) - { - int category = categories[i].cat; - int category_mask = categories[i].mask; - const char *name = setlocale (category, NULL); - if (strcmp (name, base_name) != 0) - { - locale_t copy = newlocale (category_mask, name, base_copy); - if (copy == NULL) - { - int saved_errno = errno; - freelocale (base_copy); - errno = saved_errno; - return NULL; - } - /* No need to call freelocale (base_copy) if copy != base_copy; - the newlocale function already takes care of doing it. */ - base_copy = copy; - } - } + { + int category = categories[i].cat; + int category_mask = categories[i].mask; + const char *name = setlocale (category, NULL); + if (strcmp (name, base_name) != 0) + { + locale_t copy = newlocale (category_mask, name, base_copy); + if (copy == NULL) + { + int saved_errno = errno; + freelocale (base_copy); + errno = saved_errno; + return NULL; + } + /* No need to call freelocale (base_copy) if copy != base_copy; + the newlocale function already takes care of doing it. */ + base_copy = copy; + } + } return base_copy; } diff --git a/lib/error.c b/lib/error.c index 1d63d571f..71963ce78 100644 --- a/lib/error.c +++ b/lib/error.c @@ -70,8 +70,8 @@ unsigned int error_message_count; 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, - ...) + unsigned int line_number, const char *message, + ...) __attribute__ ((__format__ (__printf__, 5, 6)));; # define error __error # define error_at_line __error_at_line @@ -101,8 +101,8 @@ 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 */ +# endif /* HAVE_STRERROR_R || defined strerror_r */ +#endif /* not _LIBC */ static inline void flush_stdout (void) @@ -175,58 +175,58 @@ error_tail (int status, int errnum, const char *message, va_list args) 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 (__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"???"; - } + { + /* 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); + free (wmessage); } else #endif @@ -261,7 +261,7 @@ error (int status, int errnum, const char *message, ...) cancellation. Therefore disable cancellation for now. */ int state = PTHREAD_CANCEL_ENABLE; __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), - 0); + 0); #endif flush_stdout (); @@ -296,7 +296,7 @@ int error_one_per_line; void error_at_line (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, ...) + unsigned int line_number, const char *message, ...) { va_list args; @@ -306,10 +306,10 @@ error_at_line (int status, int errnum, const char *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; + && (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; @@ -320,7 +320,7 @@ error_at_line (int status, int errnum, const char *file_name, cancellation. Therefore disable cancellation for now. */ int state = PTHREAD_CANCEL_ENABLE; __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), - 0); + 0); #endif flush_stdout (); @@ -340,10 +340,10 @@ error_at_line (int status, int errnum, const char *file_name, #if _LIBC __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", - file_name, line_number); + file_name, line_number); #else fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", - file_name, line_number); + file_name, line_number); #endif va_start (args, message); diff --git a/lib/error.h b/lib/error.h index 6d4968114..1c7da3a06 100644 --- a/lib/error.h +++ b/lib/error.h @@ -31,7 +31,7 @@ # endif #endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -43,7 +43,7 @@ extern void error (int __status, int __errnum, const char *__format, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern void error_at_line (int __status, int __errnum, const char *__fname, - unsigned int __lineno, const char *__format, ...) + unsigned int __lineno, const char *__format, ...) __attribute__ ((__format__ (__printf__, 5, 6))); /* If NULL, error will flush stdout, then print on stderr the program @@ -58,7 +58,7 @@ extern unsigned int error_message_count; variable controls whether this mode is selected or not. */ extern int error_one_per_line; -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/lib/euidaccess.c b/lib/euidaccess.c index dcb6e3a93..e23e4a9f1 100644 --- a/lib/euidaccess.c +++ b/lib/euidaccess.c @@ -111,18 +111,18 @@ euidaccess (const char *file, int mode) int saved_errno; if (uid != euid) - setreuid (euid, uid); + setreuid (euid, uid); if (gid != egid) - setregid (egid, gid); + setregid (egid, gid); result = access (file, mode); saved_errno = errno; /* Restore them. */ if (uid != euid) - setreuid (uid, euid); + setreuid (uid, euid); if (gid != egid) - setregid (gid, egid); + setregid (gid, egid); errno = saved_errno; return result; @@ -145,7 +145,7 @@ euidaccess (const char *file, int mode) /* The super-user can read and write any file, and execute any file that anyone can execute. */ if (euid == 0 && ((mode & X_OK) == 0 - || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))) + || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))) return 0; /* Convert the mode to traditional form, clearing any bogus bits. */ @@ -153,11 +153,11 @@ euidaccess (const char *file, int mode) mode &= 7; else mode = ((mode & R_OK ? 4 : 0) - + (mode & W_OK ? 2 : 0) - + (mode & X_OK ? 1 : 0)); + + (mode & W_OK ? 2 : 0) + + (mode & X_OK ? 1 : 0)); if (mode == 0) - return 0; /* The file exists. */ + return 0; /* The file exists. */ /* Convert the file's permission bits to traditional form. */ if (S_IRUSR == (4 << 6) && S_IWUSR == (2 << 6) && S_IXUSR == (1 << 6) @@ -166,14 +166,14 @@ euidaccess (const char *file, int mode) granted = stats.st_mode; else granted = ((stats.st_mode & S_IRUSR ? 4 << 6 : 0) - + (stats.st_mode & S_IWUSR ? 2 << 6 : 0) - + (stats.st_mode & S_IXUSR ? 1 << 6 : 0) - + (stats.st_mode & S_IRGRP ? 4 << 3 : 0) - + (stats.st_mode & S_IWGRP ? 2 << 3 : 0) - + (stats.st_mode & S_IXGRP ? 1 << 3 : 0) - + (stats.st_mode & S_IROTH ? 4 << 0 : 0) - + (stats.st_mode & S_IWOTH ? 2 << 0 : 0) - + (stats.st_mode & S_IXOTH ? 1 << 0 : 0)); + + (stats.st_mode & S_IWUSR ? 2 << 6 : 0) + + (stats.st_mode & S_IXUSR ? 1 << 6 : 0) + + (stats.st_mode & S_IRGRP ? 4 << 3 : 0) + + (stats.st_mode & S_IWGRP ? 2 << 3 : 0) + + (stats.st_mode & S_IXGRP ? 1 << 3 : 0) + + (stats.st_mode & S_IROTH ? 4 << 0 : 0) + + (stats.st_mode & S_IWOTH ? 2 << 0 : 0) + + (stats.st_mode & S_IXOTH ? 1 << 0 : 0)); if (euid == stats.st_uid) granted >>= 6; diff --git a/lib/exclude.c b/lib/exclude.c index d1b421d47..e32fca923 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -56,9 +56,9 @@ #endif verify (((EXCLUDE_ANCHORED | EXCLUDE_INCLUDE | EXCLUDE_WILDCARDS) - & (FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD | FNM_LEADING_DIR - | FNM_CASEFOLD | FNM_EXTMATCH)) - == 0); + & (FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD | FNM_LEADING_DIR + | FNM_CASEFOLD | FNM_EXTMATCH)) + == 0); /* Exclusion patterns are grouped into a singly-linked list of @@ -121,15 +121,15 @@ fnmatch_pattern_has_wildcards (const char *str, int options) { size_t n = strcspn (str, cset); if (str[n] == 0) - break; + break; else if (str[n] == '\\') - { - str += n + 1; - if (*str) - str++; - } + { + str += n + 1; + if (*str) + str++; + } else - return true; + return true; } return false; } @@ -164,9 +164,9 @@ string_hasher_ci (void const *data, size_t n_buckets) wchar_t wc; if (m.wc_valid) - wc = towlower (m.wc); + wc = towlower (m.wc); else - wc = *m.ptr; + wc = *m.ptr; value = (value * 31 + wc) % n_buckets; } @@ -213,13 +213,13 @@ new_exclude_segment (struct exclude *ex, enum exclude_type type, int options) case exclude_hash: sp->v.table = hash_initialize (0, NULL, - (options & FNM_CASEFOLD) ? - string_hasher_ci - : string_hasher, - (options & FNM_CASEFOLD) ? - string_compare_ci - : string_compare, - string_free); + (options & FNM_CASEFOLD) ? + string_hasher_ci + : string_hasher, + (options & FNM_CASEFOLD) ? + string_compare_ci + : string_compare, + string_free); break; } if (ex->tail) @@ -269,41 +269,41 @@ fnmatch_no_wildcards (char const *pattern, char const *f, int options) { if (! (options & FNM_LEADING_DIR)) return ((options & FNM_CASEFOLD) - ? mbscasecmp (pattern, f) - : strcmp (pattern, f)); + ? mbscasecmp (pattern, f) + : strcmp (pattern, f)); else if (! (options & FNM_CASEFOLD)) { size_t patlen = strlen (pattern); int r = strncmp (pattern, f, patlen); if (! r) - { - r = f[patlen]; - if (r == '/') - r = 0; - } + { + r = f[patlen]; + if (r == '/') + r = 0; + } return r; } else { /* Walk through a copy of F, seeing whether P matches any prefix - of F. + of F. - FIXME: This is an O(N**2) algorithm; it should be O(N). - Also, the copy should not be necessary. However, fixing this - will probably involve a change to the mbs* API. */ + FIXME: This is an O(N**2) algorithm; it should be O(N). + Also, the copy should not be necessary. However, fixing this + will probably involve a change to the mbs* API. */ char *fcopy = xstrdup (f); char *p; int r; for (p = fcopy; ; *p++ = '/') - { - p = strchr (p, '/'); - if (p) - *p = '\0'; - r = mbscasecmp (pattern, fcopy); - if (!p || r <= 0) - break; - } + { + p = strchr (p, '/'); + if (p) + *p = '\0'; + r = mbscasecmp (pattern, fcopy); + if (!p || r <= 0) + break; + } free (fcopy); return r; } @@ -322,7 +322,7 @@ exclude_fnmatch (char const *pattern, char const *f, int options) if (! (options & EXCLUDE_ANCHORED)) for (p = f; *p && ! matched; p++) if (*p == '/' && p[1] != '/') - matched = ((*matcher) (pattern, p + 1, options) == 0); + matched = ((*matcher) (pattern, p + 1, options) == 0); return matched; } @@ -343,7 +343,7 @@ excluded_file_pattern_p (struct exclude_segment const *seg, char const *f) char const *pattern = exclude[i].pattern; int options = exclude[i].options; if (excluded != exclude_fnmatch (pattern, f, options)) - return !excluded; + return !excluded; } return excluded; } @@ -353,7 +353,7 @@ excluded_file_pattern_p (struct exclude_segment const *seg, char const *f) terminator included) */ static bool excluded_file_name_p (struct exclude_segment const *seg, char const *f, - char *buffer) + char *buffer) { int options = seg->options; bool excluded = !! (options & EXCLUDE_INCLUDE); @@ -365,29 +365,29 @@ excluded_file_name_p (struct exclude_segment const *seg, char const *f, strcpy (buffer, f); while (1) - { - if (hash_lookup (table, buffer)) - return !excluded; - if (options & FNM_LEADING_DIR) - { - char *p = strrchr (buffer, '/'); - if (p) - { - *p = 0; - continue; - } - } - break; - } + { + if (hash_lookup (table, buffer)) + return !excluded; + if (options & FNM_LEADING_DIR) + { + char *p = strrchr (buffer, '/'); + if (p) + { + *p = 0; + continue; + } + } + break; + } if (!(options & EXCLUDE_ANCHORED)) - { - f = strchr (f, '/'); - if (f) - f++; - } + { + f = strchr (f, '/'); + if (f) + f++; + } else - break; + break; } while (f); return excluded; @@ -415,25 +415,25 @@ excluded_file_name (struct exclude const *ex, char const *f) bool rc; switch (seg->type) - { - case exclude_pattern: - rc = excluded_file_pattern_p (seg, f); - break; - - case exclude_hash: - if (!filename) - filename = xmalloc (strlen (f) + 1); - rc = excluded_file_name_p (seg, f, filename); - break; - - default: - abort (); - } + { + case exclude_pattern: + rc = excluded_file_pattern_p (seg, f); + break; + + case exclude_hash: + if (!filename) + filename = xmalloc (strlen (f) + 1); + rc = excluded_file_name_p (seg, f, filename); + break; + + default: + abort (); + } if (rc != excluded) - { - excluded = rc; - break; - } + { + excluded = rc; + break; + } } free (filename); return excluded; @@ -453,16 +453,16 @@ add_exclude (struct exclude *ex, char const *pattern, int options) struct patopts *patopts; if (ex->tail && ex->tail->type == exclude_pattern - && ((ex->tail->options & EXCLUDE_INCLUDE) == - (options & EXCLUDE_INCLUDE))) - seg = ex->tail; + && ((ex->tail->options & EXCLUDE_INCLUDE) == + (options & EXCLUDE_INCLUDE))) + seg = ex->tail; else - seg = new_exclude_segment (ex, exclude_pattern, options); + seg = new_exclude_segment (ex, exclude_pattern, options); pat = &seg->v.pat; if (pat->exclude_count == pat->exclude_alloc) - pat->exclude = x2nrealloc (pat->exclude, &pat->exclude_alloc, - sizeof *pat->exclude); + pat->exclude = x2nrealloc (pat->exclude, &pat->exclude_alloc, + sizeof *pat->exclude); patopts = &pat->exclude[pat->exclude_count++]; patopts->pattern = pattern; patopts->options = options; @@ -471,18 +471,18 @@ add_exclude (struct exclude *ex, char const *pattern, int options) { char *str, *p; #define EXCLUDE_HASH_FLAGS (EXCLUDE_INCLUDE|EXCLUDE_ANCHORED|\ - FNM_LEADING_DIR|FNM_CASEFOLD) + FNM_LEADING_DIR|FNM_CASEFOLD) if (ex->tail && ex->tail->type == exclude_hash - && ((ex->tail->options & EXCLUDE_HASH_FLAGS) == - (options & EXCLUDE_HASH_FLAGS))) - seg = ex->tail; + && ((ex->tail->options & EXCLUDE_HASH_FLAGS) == + (options & EXCLUDE_HASH_FLAGS))) + seg = ex->tail; else - seg = new_exclude_segment (ex, exclude_hash, options); + seg = new_exclude_segment (ex, exclude_hash, options); str = xstrdup (pattern); p = hash_insert (seg->v.table, str); if (p != str) - free (str); + free (str); } } @@ -493,8 +493,8 @@ add_exclude (struct exclude *ex, char const *pattern, int options) int add_exclude_file (void (*add_func) (struct exclude *, char const *, int), - struct exclude *ex, char const *file_name, int options, - char line_end) + struct exclude *ex, char const *file_name, int options, + char line_end) { bool use_stdin = file_name[0] == '-' && !file_name[1]; FILE *in; @@ -515,7 +515,7 @@ add_exclude_file (void (*add_func) (struct exclude *, char const *, int), while ((c = getc (in)) != EOF) { if (buf_count == buf_alloc) - buf = x2realloc (buf, &buf_alloc); + buf = x2realloc (buf, &buf_alloc); buf[buf_count++] = c; } @@ -533,22 +533,22 @@ add_exclude_file (void (*add_func) (struct exclude *, char const *, int), for (p = buf; p < lim; p++) if (*p == line_end) { - char *pattern_end = p; + char *pattern_end = p; - if (isspace ((unsigned char) line_end)) - { - for (; ; pattern_end--) - if (pattern_end == pattern) - goto next_pattern; - else if (! isspace ((unsigned char) pattern_end[-1])) - break; - } + if (isspace ((unsigned char) line_end)) + { + for (; ; pattern_end--) + if (pattern_end == pattern) + goto next_pattern; + else if (! isspace ((unsigned char) pattern_end[-1])) + break; + } - *pattern_end = '\0'; - (*add_func) (ex, pattern, options); + *pattern_end = '\0'; + (*add_func) (ex, pattern, options); next_pattern: - pattern = p + 1; + pattern = p + 1; } errno = e; diff --git a/lib/exclude.h b/lib/exclude.h index fa5b12087..a2094cf6e 100644 --- a/lib/exclude.h +++ b/lib/exclude.h @@ -45,7 +45,7 @@ struct exclude *new_exclude (void); void free_exclude (struct exclude *); void add_exclude (struct exclude *, char const *, int); int add_exclude_file (void (*) (struct exclude *, char const *, int), - struct exclude *, char const *, int, char); + struct exclude *, char const *, int, char); bool excluded_file_name (struct exclude const *, char const *); bool exclude_fnmatch (char const *pattern, char const *f, int options); diff --git a/lib/execute.c b/lib/execute.c index 253b5a670..7e7132b6c 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -98,11 +98,11 @@ nonintr_open (const char *pathname, int oflag, mode_t mode) 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) + 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__ @@ -131,20 +131,20 @@ execute (const char *progname, nulloutfd = -1; if ((!null_stdin || ((nullinfd = open ("NUL", O_RDONLY, 0)) >= 0 - && (nullinfd == STDIN_FILENO - || (dup2 (nullinfd, STDIN_FILENO) >= 0 - && close (nullinfd) >= 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)))) + || ((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 @@ -155,16 +155,16 @@ execute (const char *progname, [un]setenv(). */ { exitcode = spawnvpe (P_WAIT, prog_path, (const char **) prog_argv, - (const char **) environ); + (const char **) environ); if (exitcode < 0 && errno == ENOEXEC) - { - /* prog is not an 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); - } + { + /* prog is not an 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); @@ -185,8 +185,8 @@ execute (const char *progname, if (exitcode == -1) { if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, errno, - _("%s subprocess failed"), progname); + error (exit_on_error ? EXIT_FAILURE : 0, errno, + _("%s subprocess failed"), progname); return 127; } @@ -217,49 +217,49 @@ execute (const char *progname, 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)) + (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); + posix_spawn_file_actions_destroy (&actions); if (attrs_allocated) - posix_spawnattr_destroy (&attrs); + posix_spawnattr_destroy (&attrs); if (slave_process) - unblock_fatal_signals (); + unblock_fatal_signals (); if (termsigp != NULL) - *termsigp = 0; + *termsigp = 0; if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, err, - _("%s subprocess failed"), progname); + error (exit_on_error ? EXIT_FAILURE : 0, err, + _("%s subprocess failed"), progname); return 127; } posix_spawn_file_actions_destroy (&actions); @@ -272,7 +272,7 @@ execute (const char *progname, } return wait_subprocess (child, progname, ignore_sigpipe, null_stderr, - slave_process, exit_on_error, termsigp); + slave_process, exit_on_error, termsigp); #endif } diff --git a/lib/execute.h b/lib/execute.h index b456aaf20..53c2e25ae 100644 --- a/lib/execute.h +++ b/lib/execute.h @@ -35,10 +35,10 @@ 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); + 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/lib/expl.c b/lib/expl.c index 202d35952..231f4cb9c 100644 --- a/lib/expl.c +++ b/lib/expl.c @@ -72,16 +72,16 @@ expl (long double x) x -= exponent / 8.0L; if (x > 0.0625) - { - exponent++; - x -= 0.125L; - } + { + exponent++; + x -= 0.125L; + } if (exponent < 0) { t = 0.8824969025845954028648921432290507362220L; /* e^-0.25 */ - exponent = -exponent; - } + exponent = -exponent; + } else t = 1.1331484530668263168290072278117938725655L; /* e^0.25 */ @@ -97,8 +97,8 @@ expl (long double x) } /* Approximate (e^x - 1)/x, using a seventh-degree polynomial, - with maximum error in [-2^-16-2^-53,2^-16+2^-53] - less than 4.8e-39. */ + with maximum error in [-2^-16-2^-53,2^-16+2^-53] + less than 4.8e-39. */ x22 = x + x*x*(P1+x*(P2+x*(P3+x*(P4+x*(P5+x*P6))))); return result + result * x22; @@ -107,11 +107,11 @@ expl (long double x) else if (x < himark) { if (x + x == x) - /* e^-inf == 0, with no error. */ - return 0; + /* e^-inf == 0, with no error. */ + return 0; else - /* Underflow */ - return TINY * TINY; + /* Underflow */ + return TINY * TINY; } else /* Return x, if x is a NaN or Inf; or overflow, otherwise. */ diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index df9e0116b..6e649e3b4 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -91,13 +91,13 @@ init_fatal_signals (void) size_t i; for (i = 0; i < num_fatal_signals; i++) - { - struct sigaction action; + { + struct sigaction action; - if (sigaction (fatal_signals[i], NULL, &action) >= 0 - && get_handler (&action) == SIG_IGN) - fatal_signals[i] = -1; - } + if (sigaction (fatal_signals[i], NULL, &action) >= 0 + && get_handler (&action) == SIG_IGN) + fatal_signals[i] = -1; + } fatal_signals_initialized = true; } @@ -139,10 +139,10 @@ uninstall_handlers () 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); + 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); } } @@ -157,7 +157,7 @@ fatal_signal_handler (int sig) action_t action; size_t n = actions_count; if (n == 0) - break; + break; n--; actions_count = n; action = actions[n].action; @@ -191,11 +191,11 @@ install_handlers () for (i = 0; i < num_fatal_signals; i++) if (fatal_signals[i] >= 0) { - int sig = fatal_signals[i]; + int sig = fatal_signals[i]; - if (!(sig < sizeof (saved_sigactions) / sizeof (saved_sigactions[0]))) - abort (); - sigaction (sig, &action, &saved_sigactions[sig]); + if (!(sig < sizeof (saved_sigactions) / sizeof (saved_sigactions[0]))) + abort (); + sigaction (sig, &action, &saved_sigactions[sig]); } } @@ -216,25 +216,25 @@ at_fatal_signal (action_t action) 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. */ + 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); + 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. */ + 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]; + 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); + 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 @@ -262,8 +262,8 @@ init_fatal_signal_set () sigemptyset (&fatal_signal_set); for (i = 0; i < num_fatal_signals; i++) - if (fatal_signals[i] >= 0) - sigaddset (&fatal_signal_set, fatal_signals[i]); + if (fatal_signals[i] >= 0) + sigaddset (&fatal_signal_set, fatal_signals[i]); fatal_signal_set_initialized = true; } diff --git a/lib/fdopendir.c b/lib/fdopendir.c index c36430663..adf39fb50 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -80,21 +80,21 @@ fdopendir (int fd) # else /* !REPLACE_FCHDIR */ struct saved_cwd saved_cwd; if (save_cwd (&saved_cwd) != 0) - openat_save_fail (errno); + openat_save_fail (errno); if (fchdir (fd) != 0) - { - dir = NULL; - saved_errno = errno; - } + { + dir = NULL; + saved_errno = errno; + } else - { - dir = opendir ("."); - saved_errno = errno; + { + dir = opendir ("."); + saved_errno = errno; - if (restore_cwd (&saved_cwd) != 0) - openat_restore_fail (errno); - } + if (restore_cwd (&saved_cwd) != 0) + openat_restore_fail (errno); + } free_cwd (&saved_cwd); # endif /* !REPLACE_FCHDIR */ diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c index 4dda3ade2..eb442d89d 100644 --- a/lib/file-has-acl.c +++ b/lib/file-has-acl.c @@ -50,7 +50,7 @@ acl_access_nontrivial (acl_t acl) /* acl is non-trivial if it has some entries other than for "user::", "group::", and "other::". Normally these three should be present at least, allowing us to write - return (3 < acl_entries (acl)); + return (3 < acl_entries (acl)); but the following code is more robust. */ # if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD */ @@ -63,9 +63,9 @@ acl_access_nontrivial (acl_t acl) { acl_tag_t tag; if (acl_get_tag_type (ace, &tag) < 0) - return -1; + return -1; if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER)) - return 1; + return 1; } return got_one; @@ -82,8 +82,8 @@ acl_access_nontrivial (acl_t acl) acl_tag_t tag = ace->ae_tag; if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ - || tag == ACL_OTHER_OBJ)) - return 1; + || tag == ACL_OTHER_OBJ)) + return 1; } return 0; @@ -101,13 +101,13 @@ acl_access_nontrivial (acl_t acl) tag = ace->entry->acl_type; if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER)) - return 1; + return 1; perm = ace->entry->acl_perm; /* On Tru64, perm can also contain non-standard bits such as - PERM_INSERT, PERM_DELETE, PERM_MODIFY, PERM_LOOKUP, ... */ + PERM_INSERT, PERM_DELETE, PERM_MODIFY, PERM_LOOKUP, ... */ if ((perm & ~(ACL_READ | ACL_WRITE | ACL_EXECUTE)) != 0) - return 1; + return 1; } return 0; @@ -135,15 +135,15 @@ acl_nontrivial (int count, aclent_t *entries) aclent_t *ace = &entries[i]; /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat(). - If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat(). - We don't need to check ace->a_id in these cases. */ + If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat(). + We don't need to check ace->a_id in these cases. */ if (!(ace->a_type == USER_OBJ - || ace->a_type == GROUP_OBJ - || ace->a_type == OTHER_OBJ - /* Note: Cygwin does not return a CLASS_OBJ ("mask:") entry - sometimes. */ - || ace->a_type == CLASS_OBJ)) - return 1; + || ace->a_type == GROUP_OBJ + || ace->a_type == OTHER_OBJ + /* Note: Cygwin does not return a CLASS_OBJ ("mask:") entry + sometimes. */ + || ace->a_type == CLASS_OBJ)) + return 1; } return 0; } @@ -169,41 +169,41 @@ acl_ace_nontrivial (int count, ace_t *entries) for (i = 0; i < count; i++) if (entries[i].a_flags & (ACE_OWNER | ACE_GROUP | ACE_OTHER)) { - old_convention = 1; - break; + old_convention = 1; + break; } if (old_convention) /* Running on Solaris 10. */ for (i = 0; i < count; i++) { - ace_t *ace = &entries[i]; - - /* Note: - If ace->a_flags = ACE_OWNER, ace->a_who is the st_uid from stat(). - If ace->a_flags = ACE_GROUP, ace->a_who is the st_gid from stat(). - We don't need to check ace->a_who in these cases. */ - if (!(ace->a_type == ALLOW - && (ace->a_flags == ACE_OWNER - || ace->a_flags == ACE_GROUP - || ace->a_flags == ACE_OTHER))) - return 1; + ace_t *ace = &entries[i]; + + /* Note: + If ace->a_flags = ACE_OWNER, ace->a_who is the st_uid from stat(). + If ace->a_flags = ACE_GROUP, ace->a_who is the st_gid from stat(). + We don't need to check ace->a_who in these cases. */ + if (!(ace->a_type == ALLOW + && (ace->a_flags == ACE_OWNER + || ace->a_flags == ACE_GROUP + || ace->a_flags == ACE_OTHER))) + return 1; } else /* Running on Solaris 10 (newer version) or Solaris 11. */ for (i = 0; i < count; i++) { - ace_t *ace = &entries[i]; - - if (!(ace->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE - && (ace->a_flags == NEW_ACE_OWNER - || ace->a_flags - == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP) - || ace->a_flags == ACE_EVERYONE) - && (ace->a_access_mask - & ~(NEW_ACE_READ_DATA | NEW_ACE_WRITE_DATA | NEW_ACE_EXECUTE)) - == 0)) - return 1; + ace_t *ace = &entries[i]; + + if (!(ace->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE + && (ace->a_flags == NEW_ACE_OWNER + || ace->a_flags + == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP) + || ace->a_flags == ACE_EVERYONE) + && (ace->a_access_mask + & ~(NEW_ACE_READ_DATA | NEW_ACE_WRITE_DATA | NEW_ACE_EXECUTE)) + == 0)) + return 1; } return 0; @@ -227,9 +227,9 @@ acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb) struct acl_entry *ace = &entries[i]; if (!((ace->uid == sb->st_uid && ace->gid == ACL_NSGROUP) - || (ace->uid == ACL_NSUSER && ace->gid == sb->st_gid) - || (ace->uid == ACL_NSUSER && ace->gid == ACL_NSGROUP))) - return 1; + || (ace->uid == ACL_NSUSER && ace->gid == sb->st_gid) + || (ace->uid == ACL_NSUSER && ace->gid == ACL_NSGROUP))) + return 1; } return 0; } @@ -278,15 +278,15 @@ acl_nfs4_nontrivial (nfs4_acl_int_t *a) nfs4_ace_int_t *ace = &a->aclEntry[i]; if (!((ace->flags & ACE4_ID_SPECIAL) != 0 - && (ace->aceWho.special_whoid == ACE4_WHO_OWNER - || ace->aceWho.special_whoid == ACE4_WHO_GROUP - || ace->aceWho.special_whoid == ACE4_WHO_EVERYONE) - && ace->aceType == ACE4_ACCESS_ALLOWED_ACE_TYPE - && ace->aceFlags == 0 - && (ace->aceMask & ~(ACE4_READ_DATA | ACE4_LIST_DIRECTORY - | ACE4_WRITE_DATA | ACE4_ADD_FILE - | ACE4_EXECUTE)) == 0)) - return 1; + && (ace->aceWho.special_whoid == ACE4_WHO_OWNER + || ace->aceWho.special_whoid == ACE4_WHO_GROUP + || ace->aceWho.special_whoid == ACE4_WHO_EVERYONE) + && ace->aceType == ACE4_ACCESS_ALLOWED_ACE_TYPE + && ace->aceFlags == 0 + && (ace->aceMask & ~(ACE4_READ_DATA | ACE4_LIST_DIRECTORY + | ACE4_WRITE_DATA | ACE4_ADD_FILE + | ACE4_EXECUTE)) == 0)) + return 1; } return 0; # endif @@ -314,67 +314,67 @@ file_has_acl (char const *name, struct stat const *sb) int ret; if (HAVE_ACL_EXTENDED_FILE) /* Linux */ - { - /* On Linux, acl_extended_file is an optimized function: It only - makes two calls to getxattr(), one for ACL_TYPE_ACCESS, one for - ACL_TYPE_DEFAULT. */ - ret = acl_extended_file (name); - } + { + /* On Linux, acl_extended_file is an optimized function: It only + makes two calls to getxattr(), one for ACL_TYPE_ACCESS, one for + ACL_TYPE_DEFAULT. */ + ret = acl_extended_file (name); + } else /* FreeBSD, MacOS X, IRIX, Tru64 */ - { + { # if HAVE_ACL_TYPE_EXTENDED /* MacOS X */ - /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS) - and acl_get_file (name, ACL_TYPE_DEFAULT) - always return NULL / EINVAL. There is no point in making - these two useless calls. The real ACL is retrieved through - acl_get_file (name, ACL_TYPE_EXTENDED). */ - acl_t acl = acl_get_file (name, ACL_TYPE_EXTENDED); - if (acl) - { - ret = acl_extended_nontrivial (acl); - acl_free (acl); - } - else - ret = -1; + /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS) + and acl_get_file (name, ACL_TYPE_DEFAULT) + always return NULL / EINVAL. There is no point in making + these two useless calls. The real ACL is retrieved through + acl_get_file (name, ACL_TYPE_EXTENDED). */ + acl_t acl = acl_get_file (name, ACL_TYPE_EXTENDED); + if (acl) + { + ret = acl_extended_nontrivial (acl); + acl_free (acl); + } + else + ret = -1; # else /* FreeBSD, IRIX, Tru64 */ - acl_t acl = acl_get_file (name, ACL_TYPE_ACCESS); - if (acl) - { - int saved_errno; - - ret = acl_access_nontrivial (acl); - saved_errno = errno; - acl_free (acl); - errno = saved_errno; + acl_t acl = acl_get_file (name, ACL_TYPE_ACCESS); + if (acl) + { + int saved_errno; + + ret = acl_access_nontrivial (acl); + saved_errno = errno; + acl_free (acl); + errno = saved_errno; # if HAVE_ACL_FREE_TEXT /* Tru64 */ - /* On OSF/1, acl_get_file (name, ACL_TYPE_DEFAULT) always - returns NULL with errno not set. There is no point in - making this call. */ + /* On OSF/1, acl_get_file (name, ACL_TYPE_DEFAULT) always + returns NULL with errno not set. There is no point in + making this call. */ # else /* FreeBSD, IRIX */ - /* On Linux, FreeBSD, IRIX, acl_get_file (name, ACL_TYPE_ACCESS) - and acl_get_file (name, ACL_TYPE_DEFAULT) on a directory - either both succeed or both fail; it depends on the - file system. Therefore there is no point in making the second - call if the first one already failed. */ - if (ret == 0 && S_ISDIR (sb->st_mode)) - { - acl = acl_get_file (name, ACL_TYPE_DEFAULT); - if (acl) - { - ret = (0 < acl_entries (acl)); - acl_free (acl); - } - else - ret = -1; - } + /* On Linux, FreeBSD, IRIX, acl_get_file (name, ACL_TYPE_ACCESS) + and acl_get_file (name, ACL_TYPE_DEFAULT) on a directory + either both succeed or both fail; it depends on the + file system. Therefore there is no point in making the second + call if the first one already failed. */ + if (ret == 0 && S_ISDIR (sb->st_mode)) + { + acl = acl_get_file (name, ACL_TYPE_DEFAULT); + if (acl) + { + ret = (0 < acl_entries (acl)); + acl_free (acl); + } + else + ret = -1; + } # endif - } - else - ret = -1; + } + else + ret = -1; # endif - } + } if (ret < 0) - return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1; + return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1; return ret; # elif HAVE_ACL && defined GETACLCNT /* Solaris, Cygwin, not HP-UX */ @@ -382,109 +382,109 @@ file_has_acl (char const *name, struct stat const *sb) # if defined ACL_NO_TRIVIAL /* Solaris 10 (newer version), which has additional API declared in - (acl_t) and implemented in libsec (acl_set, acl_trivial, - acl_fromtext, ...). */ + (acl_t) and implemented in libsec (acl_set, acl_trivial, + acl_fromtext, ...). */ return acl_trivial (name); # else /* Solaris, Cygwin, general case */ /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions - of Unixware. The acl() call returns the access and default ACL both - at once. */ + of Unixware. The acl() call returns the access and default ACL both + at once. */ int count; { - aclent_t *entries; - - for (;;) - { - count = acl (name, GETACLCNT, 0, NULL); - - if (count < 0) - { - if (errno == ENOSYS || errno == ENOTSUP) - break; - else - return -1; - } - - if (count == 0) - break; - - /* Don't use MIN_ACL_ENTRIES: It's set to 4 on Cygwin, but Cygwin - returns only 3 entries for files with no ACL. But this is safe: - If there are more than 4 entries, there cannot be only the - "user::", "group::", "other:", and "mask:" entries. */ - if (count > 4) - return 1; - - entries = (aclent_t *) malloc (count * sizeof (aclent_t)); - if (entries == NULL) - { - errno = ENOMEM; - return -1; - } - if (acl (name, GETACL, count, entries) == count) - { - if (acl_nontrivial (count, entries)) - { - free (entries); - return 1; - } - free (entries); - break; - } - /* Huh? The number of ACL entries changed since the last call. - Repeat. */ - free (entries); - } + aclent_t *entries; + + for (;;) + { + count = acl (name, GETACLCNT, 0, NULL); + + if (count < 0) + { + if (errno == ENOSYS || errno == ENOTSUP) + break; + else + return -1; + } + + if (count == 0) + break; + + /* Don't use MIN_ACL_ENTRIES: It's set to 4 on Cygwin, but Cygwin + returns only 3 entries for files with no ACL. But this is safe: + If there are more than 4 entries, there cannot be only the + "user::", "group::", "other:", and "mask:" entries. */ + if (count > 4) + return 1; + + entries = (aclent_t *) malloc (count * sizeof (aclent_t)); + if (entries == NULL) + { + errno = ENOMEM; + return -1; + } + if (acl (name, GETACL, count, entries) == count) + { + if (acl_nontrivial (count, entries)) + { + free (entries); + return 1; + } + free (entries); + break; + } + /* Huh? The number of ACL entries changed since the last call. + Repeat. */ + free (entries); + } } # ifdef ACE_GETACL /* Solaris also has a different variant of ACLs, used in ZFS and NFSv4 - file systems (whereas the other ones are used in UFS file systems). */ + file systems (whereas the other ones are used in UFS file systems). */ { - ace_t *entries; - - for (;;) - { - count = acl (name, ACE_GETACLCNT, 0, NULL); - - if (count < 0) - { - if (errno == ENOSYS || errno == EINVAL) - break; - else - return -1; - } - - if (count == 0) - break; - - /* If there are more than 3 entries, there cannot be only the - ACE_OWNER, ACE_GROUP, ACE_OTHER entries. */ - if (count > 3) - return 1; - - entries = (ace_t *) malloc (count * sizeof (ace_t)); - if (entries == NULL) - { - errno = ENOMEM; - return -1; - } - if (acl (name, ACE_GETACL, count, entries) == count) - { - if (acl_ace_nontrivial (count, entries)) - { - free (entries); - return 1; - } - free (entries); - break; - } - /* Huh? The number of ACL entries changed since the last call. - Repeat. */ - free (entries); - } + ace_t *entries; + + for (;;) + { + count = acl (name, ACE_GETACLCNT, 0, NULL); + + if (count < 0) + { + if (errno == ENOSYS || errno == EINVAL) + break; + else + return -1; + } + + if (count == 0) + break; + + /* If there are more than 3 entries, there cannot be only the + ACE_OWNER, ACE_GROUP, ACE_OTHER entries. */ + if (count > 3) + return 1; + + entries = (ace_t *) malloc (count * sizeof (ace_t)); + if (entries == NULL) + { + errno = ENOMEM; + return -1; + } + if (acl (name, ACE_GETACL, count, entries) == count) + { + if (acl_ace_nontrivial (count, entries)) + { + free (entries); + return 1; + } + free (entries); + break; + } + /* Huh? The number of ACL entries changed since the last call. + Repeat. */ + free (entries); + } } # endif @@ -497,37 +497,37 @@ file_has_acl (char const *name, struct stat const *sb) struct acl_entry entries[NACLENTRIES]; for (;;) - { - count = getacl (name, 0, NULL); + { + count = getacl (name, 0, NULL); - if (count < 0) - return (errno == ENOSYS || errno == EOPNOTSUPP ? 0 : -1); + if (count < 0) + return (errno == ENOSYS || errno == EOPNOTSUPP ? 0 : -1); - if (count == 0) - return 0; + if (count == 0) + return 0; - if (count > NACLENTRIES) - /* If NACLENTRIES cannot be trusted, use dynamic memory - allocation. */ - abort (); + if (count > NACLENTRIES) + /* If NACLENTRIES cannot be trusted, use dynamic memory + allocation. */ + abort (); - /* If there are more than 3 entries, there cannot be only the - (uid,%), (%,gid), (%,%) entries. */ - if (count > 3) - return 1; + /* If there are more than 3 entries, there cannot be only the + (uid,%), (%,gid), (%,%) entries. */ + if (count > 3) + return 1; - if (getacl (name, count, entries) == count) - { - struct stat statbuf; + if (getacl (name, count, entries) == count) + { + struct stat statbuf; - if (stat (name, &statbuf) < 0) - return -1; + if (stat (name, &statbuf) < 0) + return -1; - return acl_nontrivial (count, entries, &statbuf); - } - /* Huh? The number of ACL entries changed since the last call. - Repeat. */ - } + return acl_nontrivial (count, entries, &statbuf); + } + /* Huh? The number of ACL entries changed since the last call. + Repeat. */ + } # elif HAVE_ACLX_GET && defined ACL_AIX_WIP /* AIX */ @@ -538,63 +538,63 @@ file_has_acl (char const *name, struct stat const *sb) mode_t mode; for (;;) - { - /* The docs say that type being 0 is equivalent to ACL_ANY, but it - is not true, in AIX 5.3. */ - type.u64 = ACL_ANY; - if (aclx_get (name, 0, &type, aclbuf, &aclsize, &mode) >= 0) - break; - if (errno != ENOSPC) - { - if (acl != aclbuf) - { - int saved_errno = errno; - free (acl); - errno = saved_errno; - } - return -1; - } - aclsize = 2 * aclsize; - if (acl != aclbuf) - free (acl); - acl = malloc (aclsize); - if (acl == NULL) - { - errno = ENOMEM; - return -1; - } - } + { + /* The docs say that type being 0 is equivalent to ACL_ANY, but it + is not true, in AIX 5.3. */ + type.u64 = ACL_ANY; + if (aclx_get (name, 0, &type, aclbuf, &aclsize, &mode) >= 0) + break; + if (errno != ENOSPC) + { + if (acl != aclbuf) + { + int saved_errno = errno; + free (acl); + errno = saved_errno; + } + return -1; + } + aclsize = 2 * aclsize; + if (acl != aclbuf) + free (acl); + acl = malloc (aclsize); + if (acl == NULL) + { + errno = ENOMEM; + return -1; + } + } if (type.u64 == ACL_AIXC) - { - int result = acl_nontrivial ((struct acl *) acl); - if (acl != aclbuf) - free (acl); - return result; - } + { + int result = acl_nontrivial ((struct acl *) acl); + if (acl != aclbuf) + free (acl); + return result; + } else if (type.u64 == ACL_NFS4) - { - int result = acl_nfs4_nontrivial ((nfs4_acl_int_t *) acl); - if (acl != aclbuf) - free (acl); - return result; - } + { + int result = acl_nfs4_nontrivial ((nfs4_acl_int_t *) acl); + if (acl != aclbuf) + free (acl); + return result; + } else - { - /* A newer type of ACL has been introduced in the system. - We should better support it. */ - if (acl != aclbuf) - free (acl); - errno = EINVAL; - return -1; - } + { + /* A newer type of ACL has been introduced in the system. + We should better support it. */ + if (acl != aclbuf) + free (acl); + errno = EINVAL; + return -1; + } # elif HAVE_STATACL /* older AIX */ union { struct acl a; char room[4096]; } u; if (statacl (name, STX_NORMAL, &u.a, sizeof (u)) < 0) - return -1; + return -1; return acl_nontrivial (&u.a); diff --git a/lib/file-set.c b/lib/file-set.c index 46dcf5fbb..98b4b8605 100644 --- a/lib/file-set.c +++ b/lib/file-set.c @@ -42,15 +42,15 @@ record_file (Hash_table *ht, char const *file, struct stat const *stats) struct F_triple *ent_from_table = hash_insert (ht, ent); if (ent_from_table == NULL) { - /* Insertion failed due to lack of memory. */ - xalloc_die (); + /* Insertion failed due to lack of memory. */ + xalloc_die (); } if (ent_from_table != ent) { - /* There was alread a matching entry in the table, so ENT was - not inserted. Free it. */ - triple_free (ent); + /* There was alread a matching entry in the table, so ENT was + not inserted. Free it. */ + triple_free (ent); } } } @@ -59,7 +59,7 @@ record_file (Hash_table *ht, char const *file, struct stat const *stats) for the file described by FILE and STATS. */ bool seen_file (Hash_table const *ht, char const *file, - struct stat const *stats) + struct stat const *stats) { struct F_triple new_ent; diff --git a/lib/file-set.h b/lib/file-set.h index a5a159e94..1e9365f87 100644 --- a/lib/file-set.h +++ b/lib/file-set.h @@ -5,8 +5,8 @@ #include "hash.h" extern void record_file (Hash_table *ht, char const *file, - struct stat const *stats) + struct stat const *stats) __attribute__((nonnull(2, 3))); extern bool seen_file (Hash_table const *ht, char const *file, - struct stat const *stats); + struct stat const *stats); diff --git a/lib/fileblocks.c b/lib/fileblocks.c index 822935af9..f2c8d0e66 100644 --- a/lib/fileblocks.c +++ b/lib/fileblocks.c @@ -42,7 +42,7 @@ typedef long daddr_t; /* for disk address */ # endif /* !NINDIR */ /* Number of direct block addresses in an inode. */ -# define NDIR 10 +# define NDIR 10 /* Return the number of 512-byte blocks in a file of SIZE bytes. */ @@ -57,12 +57,12 @@ st_blocks (off_t size) indrblks = (datablks - NDIR - 1) / NINDIR + 1; if (datablks > NDIR + NINDIR) - { - indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1; + { + indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1; - if (datablks > NDIR + NINDIR + NINDIR * NINDIR) - indrblks++; - } + if (datablks > NDIR + NINDIR + NINDIR * NINDIR) + indrblks++; + } } return datablks + indrblks; diff --git a/lib/filemode.c b/lib/filemode.c index ac62bfc6e..d2086258a 100644 --- a/lib/filemode.c +++ b/lib/filemode.c @@ -99,18 +99,18 @@ strmode (mode_t mode, char *str) str[1] = mode & S_IRUSR ? 'r' : '-'; str[2] = mode & S_IWUSR ? 'w' : '-'; str[3] = (mode & S_ISUID - ? (mode & S_IXUSR ? 's' : 'S') - : (mode & S_IXUSR ? 'x' : '-')); + ? (mode & S_IXUSR ? 's' : 'S') + : (mode & S_IXUSR ? 'x' : '-')); str[4] = mode & S_IRGRP ? 'r' : '-'; str[5] = mode & S_IWGRP ? 'w' : '-'; str[6] = (mode & S_ISGID - ? (mode & S_IXGRP ? 's' : 'S') - : (mode & S_IXGRP ? 'x' : '-')); + ? (mode & S_IXGRP ? 's' : 'S') + : (mode & S_IXGRP ? 'x' : '-')); str[7] = mode & S_IROTH ? 'r' : '-'; str[8] = mode & S_IWOTH ? 'w' : '-'; str[9] = (mode & S_ISVTX - ? (mode & S_IXOTH ? 't' : 'T') - : (mode & S_IXOTH ? 'x' : '-')); + ? (mode & S_IXOTH ? 't' : 'T') + : (mode & S_IXOTH ? 'x' : '-')); str[10] = ' '; str[11] = '\0'; } @@ -122,43 +122,43 @@ strmode (mode_t mode, char *str) 12 characters are stored in STR. The characters stored in STR are: - 0 File type, as in ftypelet above, except that other letters are used + 0 File type, as in ftypelet above, except that other letters are used for files whose type cannot be determined solely from st_mode: - 'F' semaphore - 'M' migrated file (Cray DMF) - 'Q' message queue - 'S' shared memory object - 'T' typed memory object + 'F' semaphore + 'M' migrated file (Cray DMF) + 'Q' message queue + 'S' shared memory object + 'T' typed memory object - 1 'r' if the owner may read, '-' otherwise. + 1 'r' if the owner may read, '-' otherwise. - 2 'w' if the owner may write, '-' otherwise. + 2 'w' if the owner may write, '-' otherwise. - 3 'x' if the owner may execute, 's' if the file is - set-user-id, '-' otherwise. - 'S' if the file is set-user-id, but the execute - bit isn't set. + 3 'x' if the owner may execute, 's' if the file is + set-user-id, '-' otherwise. + 'S' if the file is set-user-id, but the execute + bit isn't set. - 4 'r' if group members may read, '-' otherwise. + 4 'r' if group members may read, '-' otherwise. - 5 'w' if group members may write, '-' otherwise. + 5 'w' if group members may write, '-' otherwise. - 6 'x' if group members may execute, 's' if the file is - set-group-id, '-' otherwise. - 'S' if it is set-group-id but not executable. + 6 'x' if group members may execute, 's' if the file is + set-group-id, '-' otherwise. + 'S' if it is set-group-id but not executable. - 7 'r' if any user may read, '-' otherwise. + 7 'r' if any user may read, '-' otherwise. - 8 'w' if any user may write, '-' otherwise. + 8 'w' if any user may write, '-' otherwise. - 9 'x' if any user may execute, 't' if the file is "sticky" - (will be retained in swap space after execution), '-' - otherwise. - 'T' if the file is sticky but not executable. + 9 'x' if any user may execute, 't' if the file is "sticky" + (will be retained in swap space after execution), '-' + otherwise. + 'T' if the file is sticky but not executable. 10 ' ' for compatibility with 4.4BSD strmode, - since this interface does not support ACLs. + since this interface does not support ACLs. 11 '\0'. */ diff --git a/lib/filenamecat.h b/lib/filenamecat.h index df5360b18..287429162 100644 --- a/lib/filenamecat.h +++ b/lib/filenamecat.h @@ -20,8 +20,8 @@ #if GNULIB_FILENAMECAT char *file_name_concat (char const *dir, char const *base, - char **base_in_result); + char **base_in_result); #endif char *mfile_name_concat (char const *dir, char const *base, - char **base_in_result); + char **base_in_result); diff --git a/lib/filevercmp.c b/lib/filevercmp.c index 20522d1c4..f8cb09c1c 100644 --- a/lib/filevercmp.c +++ b/lib/filevercmp.c @@ -89,32 +89,32 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len) { int first_diff = 0; while ((s1_pos < s1_len && !c_isdigit (s1[s1_pos])) - || (s2_pos < s2_len && !c_isdigit (s2[s2_pos]))) - { - int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]); - int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]); - if (s1_c != s2_c) - return s1_c - s2_c; - s1_pos++; - s2_pos++; - } + || (s2_pos < s2_len && !c_isdigit (s2[s2_pos]))) + { + int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]); + int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]); + if (s1_c != s2_c) + return s1_c - s2_c; + s1_pos++; + s2_pos++; + } while (s1[s1_pos] == '0') - s1_pos++; + s1_pos++; while (s2[s2_pos] == '0') - s2_pos++; + s2_pos++; while (c_isdigit (s1[s1_pos]) && c_isdigit (s2[s2_pos])) - { - if (!first_diff) - first_diff = s1[s1_pos] - s2[s2_pos]; - s1_pos++; - s2_pos++; - } + { + if (!first_diff) + first_diff = s1[s1_pos] - s2[s2_pos]; + s1_pos++; + s2_pos++; + } if (c_isdigit (s1[s1_pos])) - return 1; + return 1; if (c_isdigit (s2[s2_pos])) - return -1; + return -1; if (first_diff) - return first_diff; + return first_diff; } return 0; } diff --git a/lib/findprog.c b/lib/findprog.c index b064245a3..1ecfc8ade 100644 --- a/lib/findprog.c +++ b/lib/findprog.c @@ -78,13 +78,13 @@ find_in_path (const char *progname) /* Extract next directory in PATH. */ dir = path_rest; for (cp = path_rest; *cp != '\0' && *cp != ':'; cp++) - ; + ; last = (*cp == '\0'); *cp = '\0'; /* Empty PATH components designate the current directory. */ if (dir == cp) - dir = "."; + dir = "."; /* Concatenate dir and progname. */ # if !IN_FINDPROG_LGPL @@ -92,41 +92,41 @@ find_in_path (const char *progname) # else progpathname = concatenated_filename (dir, progname, NULL); if (progpathname == NULL) - { - /* Out of memory. */ - free (path); - return progname; - } + { + /* Out of memory. */ + free (path); + return progname; + } # endif /* On systems which have the eaccess() system call, let's use it. - On other systems, let's hope that this program is not installed - setuid or setgid, so that it is ok to call access() despite its - design flaw. */ + On other systems, let's hope that this program is not installed + setuid or setgid, so that it is ok to call access() despite its + design flaw. */ if (eaccess (progpathname, X_OK) == 0) - { - /* Found! */ - if (strcmp (progpathname, progname) == 0) - { - free (progpathname); - - /* Add the "./" prefix for real, that xconcatenated_filename() - optimized away. This avoids a second PATH search when the - caller uses execlp/execvp. */ - progpathname = XNMALLOC (2 + strlen (progname) + 1, char); - progpathname[0] = '.'; - progpathname[1] = '/'; - memcpy (progpathname + 2, progname, strlen (progname) + 1); - } - - free (path); - return progpathname; - } + { + /* Found! */ + if (strcmp (progpathname, progname) == 0) + { + free (progpathname); + + /* Add the "./" prefix for real, that xconcatenated_filename() + optimized away. This avoids a second PATH search when the + caller uses execlp/execvp. */ + progpathname = XNMALLOC (2 + strlen (progname) + 1, char); + progpathname[0] = '.'; + progpathname[1] = '/'; + memcpy (progpathname + 2, progname, strlen (progname) + 1); + } + + free (path); + return progpathname; + } free (progpathname); if (last) - break; + break; } /* Not found in PATH. An error will be signalled at the first call. */ diff --git a/lib/flock.c b/lib/flock.c index 01bfd17aa..fdaf6dde7 100644 --- a/lib/flock.c +++ b/lib/flock.c @@ -130,27 +130,27 @@ flock (int fd, int operation) { DWORD err = GetLastError (); switch (err) - { - /* This means someone else is holding a lock. */ - case ERROR_LOCK_VIOLATION: - errno = EAGAIN; - break; - - /* Out of memory. */ - case ERROR_NOT_ENOUGH_MEMORY: - errno = ENOMEM; - break; - - case ERROR_BAD_COMMAND: - errno = EINVAL; - break; - - /* Unlikely to be other errors, but at least don't lose the - * error code. - */ - default: - errno = err; - } + { + /* This means someone else is holding a lock. */ + case ERROR_LOCK_VIOLATION: + errno = EAGAIN; + break; + + /* Out of memory. */ + case ERROR_NOT_ENOUGH_MEMORY: + errno = ENOMEM; + break; + + case ERROR_BAD_COMMAND: + errno = EINVAL; + break; + + /* Unlikely to be other errors, but at least don't lose the + * error code. + */ + default: + errno = err; + } return -1; } diff --git a/lib/floor.c b/lib/floor.c index 05a6591a4..7016ed476 100644 --- a/lib/floor.c +++ b/lib/floor.c @@ -67,27 +67,27 @@ FUNC (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } return z; } diff --git a/lib/fnmatch.c b/lib/fnmatch.c index a0356aca2..bef5702aa 100644 --- a/lib/fnmatch.c +++ b/lib/fnmatch.c @@ -1,5 +1,5 @@ /* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2009 - Free Software Foundation, Inc. + Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ /* Enable GNU extensions in fnmatch.h. */ #ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 +# define _GNU_SOURCE 1 #endif #if ! defined __builtin_expect && __GNUC__ < 3 @@ -109,25 +109,25 @@ extern int fnmatch (const char *pattern, const char *string, int flags); # endif # ifdef _LIBC -# define ISWCTYPE(WC, WT) __iswctype (WC, WT) +# define ISWCTYPE(WC, WT) __iswctype (WC, WT) # else -# define ISWCTYPE(WC, WT) iswctype (WC, WT) +# define ISWCTYPE(WC, WT) iswctype (WC, WT) # endif # if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC /* In this case we are implementing the multibyte character handling. */ -# define HANDLE_MULTIBYTE 1 +# define HANDLE_MULTIBYTE 1 # endif # else # define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ -# define IS_CHAR_CLASS(string) \ - (STREQ (string, "alpha") || STREQ (string, "upper") \ - || STREQ (string, "lower") || STREQ (string, "digit") \ - || STREQ (string, "alnum") || STREQ (string, "xdigit") \ - || STREQ (string, "space") || STREQ (string, "print") \ - || STREQ (string, "punct") || STREQ (string, "graph") \ +# define IS_CHAR_CLASS(string) \ + (STREQ (string, "alpha") || STREQ (string, "upper") \ + || STREQ (string, "lower") || STREQ (string, "digit") \ + || STREQ (string, "alnum") || STREQ (string, "xdigit") \ + || STREQ (string, "space") || STREQ (string, "print") \ + || STREQ (string, "punct") || STREQ (string, "graph") \ || STREQ (string, "cntrl") || STREQ (string, "blank")) # endif @@ -145,17 +145,17 @@ static int posixly_correct; /* Note that this evaluates C many times. */ # define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c)) -# define CHAR char -# define UCHAR unsigned char -# define INT int -# define FCT internal_fnmatch -# define EXT ext_match -# define END end_pattern -# define L_(CS) CS +# define CHAR char +# define UCHAR unsigned char +# define INT int +# define FCT internal_fnmatch +# define EXT ext_match +# define END end_pattern +# define L_(CS) CS # ifdef _LIBC -# define BTOWC(C) __btowc (C) +# define BTOWC(C) __btowc (C) # else -# define BTOWC(C) btowc (C) +# define BTOWC(C) btowc (C) # endif # define STRLEN(S) strlen (S) # define STRCAT(D, S) strcat (D, S) @@ -175,14 +175,14 @@ static int posixly_correct; # if HANDLE_MULTIBYTE # define FOLD(c) ((flags & FNM_CASEFOLD) ? towlower (c) : (c)) -# define CHAR wchar_t -# define UCHAR wint_t -# define INT wint_t -# define FCT internal_fnwmatch -# define EXT ext_wmatch -# define END end_wpattern -# define L_(CS) L##CS -# define BTOWC(C) (C) +# define CHAR wchar_t +# define UCHAR wint_t +# define INT wint_t +# define FCT internal_fnwmatch +# define EXT ext_wmatch +# define END end_wpattern +# define L_(CS) L##CS +# define BTOWC(C) (C) # ifdef _LIBC # define STRLEN(S) __wcslen (S) # define STRCAT(D, S) __wcscat (D, S) @@ -218,40 +218,40 @@ is_char_class (const wchar_t *wcs) /* Test for a printable character from the portable character set. */ # ifdef _LIBC if (*wcs < 0x20 || *wcs > 0x7e - || *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60) - return (wctype_t) 0; + || *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60) + return (wctype_t) 0; # else switch (*wcs) - { - case L' ': case L'!': case L'"': case L'#': case L'%': - case L'&': case L'\'': case L'(': case L')': case L'*': - case L'+': case L',': case L'-': case L'.': case L'/': - case L'0': case L'1': case L'2': case L'3': case L'4': - case L'5': case L'6': case L'7': case L'8': case L'9': - case L':': case L';': case L'<': case L'=': case L'>': - case L'?': - case L'A': case L'B': case L'C': case L'D': case L'E': - case L'F': case L'G': case L'H': case L'I': case L'J': - case L'K': case L'L': case L'M': case L'N': case L'O': - case L'P': case L'Q': case L'R': case L'S': case L'T': - case L'U': case L'V': case L'W': case L'X': case L'Y': - case L'Z': - case L'[': case L'\\': case L']': case L'^': case L'_': - case L'a': case L'b': case L'c': case L'd': case L'e': - case L'f': case L'g': case L'h': case L'i': case L'j': - case L'k': case L'l': case L'm': case L'n': case L'o': - case L'p': case L'q': case L'r': case L's': case L't': - case L'u': case L'v': case L'w': case L'x': case L'y': - case L'z': case L'{': case L'|': case L'}': case L'~': - break; - default: - return (wctype_t) 0; - } + { + case L' ': case L'!': case L'"': case L'#': case L'%': + case L'&': case L'\'': case L'(': case L')': case L'*': + case L'+': case L',': case L'-': case L'.': case L'/': + case L'0': case L'1': case L'2': case L'3': case L'4': + case L'5': case L'6': case L'7': case L'8': case L'9': + case L':': case L';': case L'<': case L'=': case L'>': + case L'?': + case L'A': case L'B': case L'C': case L'D': case L'E': + case L'F': case L'G': case L'H': case L'I': case L'J': + case L'K': case L'L': case L'M': case L'N': case L'O': + case L'P': case L'Q': case L'R': case L'S': case L'T': + case L'U': case L'V': case L'W': case L'X': case L'Y': + case L'Z': + case L'[': case L'\\': case L']': case L'^': case L'_': + case L'a': case L'b': case L'c': case L'd': case L'e': + case L'f': case L'g': case L'h': case L'i': case L'j': + case L'k': case L'l': case L'm': case L'n': case L'o': + case L'p': case L'q': case L'r': case L's': case L't': + case L'u': case L'v': case L'w': case L'x': case L'y': + case L'z': case L'{': case L'|': case L'}': case L'~': + break; + default: + return (wctype_t) 0; + } # endif /* Avoid overrunning the buffer. */ if (cp == s + CHAR_CLASS_MAX_LENGTH) - return (wctype_t) 0; + return (wctype_t) 0; *cp++ = (char) *wcs++; } @@ -287,58 +287,58 @@ fnmatch (const char *pattern, const char *string, int flags) int res; /* Calculate the size needed to convert the strings to - wide characters. */ + wide characters. */ memset (&ps, '\0', sizeof (ps)); patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; if (__builtin_expect (patsize != 0, 1)) - { - assert (mbsinit (&ps)); - strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; - if (__builtin_expect (strsize != 0, 1)) - { - assert (mbsinit (&ps)); - totsize = patsize + strsize; - if (__builtin_expect (! (patsize <= totsize - && totsize <= SIZE_MAX / sizeof (wchar_t)), - 0)) - { - errno = ENOMEM; - return -1; - } - - /* Allocate room for the wide characters. */ - if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) - wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); - else - { - wpattern = malloc (totsize * sizeof (wchar_t)); - if (__builtin_expect (! wpattern, 0)) - { - errno = ENOMEM; - return -1; - } - } - wstring = wpattern + patsize; - - /* Convert the strings into wide characters. */ - mbsrtowcs (wpattern, &pattern, patsize, &ps); - assert (mbsinit (&ps)); - mbsrtowcs (wstring, &string, strsize, &ps); - - res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, - flags & FNM_PERIOD, flags); - - if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) - free (wpattern); - return res; - } - } + { + assert (mbsinit (&ps)); + strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; + if (__builtin_expect (strsize != 0, 1)) + { + assert (mbsinit (&ps)); + totsize = patsize + strsize; + if (__builtin_expect (! (patsize <= totsize + && totsize <= SIZE_MAX / sizeof (wchar_t)), + 0)) + { + errno = ENOMEM; + return -1; + } + + /* Allocate room for the wide characters. */ + if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) + wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); + else + { + wpattern = malloc (totsize * sizeof (wchar_t)); + if (__builtin_expect (! wpattern, 0)) + { + errno = ENOMEM; + return -1; + } + } + wstring = wpattern + patsize; + + /* Convert the strings into wide characters. */ + mbsrtowcs (wpattern, &pattern, patsize, &ps); + assert (mbsinit (&ps)); + mbsrtowcs (wstring, &string, strsize, &ps); + + res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, + flags & FNM_PERIOD, flags); + + if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) + free (wpattern); + return res; + } + } } # endif /* HANDLE_MULTIBYTE */ return internal_fnmatch (pattern, string, string + strlen (string), - flags & FNM_PERIOD, flags); + flags & FNM_PERIOD, flags); } # ifdef _LIBC @@ -351,4 +351,4 @@ compat_symbol (libc, __fnmatch_old, fnmatch, GLIBC_2_0); libc_hidden_ver (__fnmatch, fnmatch) # endif -#endif /* _LIBC or not __GNU_LIBRARY__. */ +#endif /* _LIBC or not __GNU_LIBRARY__. */ diff --git a/lib/fnmatch.in.h b/lib/fnmatch.in.h index b086b45aa..cab79797e 100644 --- a/lib/fnmatch.in.h +++ b/lib/fnmatch.in.h @@ -17,8 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef _FNMATCH_H -#define _FNMATCH_H 1 +#ifndef _FNMATCH_H +#define _FNMATCH_H 1 #ifdef __cplusplus extern "C" { @@ -26,37 +26,37 @@ extern "C" { /* We #undef these before defining them because some losing systems (HP-UX A.08.07 for example) define these in . */ -#undef FNM_PATHNAME -#undef FNM_NOESCAPE -#undef FNM_PERIOD +#undef FNM_PATHNAME +#undef FNM_NOESCAPE +#undef FNM_PERIOD /* Bits set in the FLAGS argument to `fnmatch'. */ -#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */ -#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */ -#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */ +#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */ +#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */ +#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */ #if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _GNU_SOURCE -# define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */ -# define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */ -# define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */ -# define FNM_EXTMATCH (1 << 5) /* Use ksh-like extended matching. */ +# define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */ +# define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */ +# define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */ +# define FNM_EXTMATCH (1 << 5) /* Use ksh-like extended matching. */ #endif /* Value returned by `fnmatch' if STRING does not match PATTERN. */ -#define FNM_NOMATCH 1 +#define FNM_NOMATCH 1 /* This value is returned if the implementation does not support `fnmatch'. Since this is not the case here it will never be returned but the conformance test suites still require the symbol to be defined. */ #ifdef _XOPEN_SOURCE -# define FNM_NOSYS (-1) +# define FNM_NOSYS (-1) #endif /* Match NAME against the file name pattern PATTERN, returning zero if it matches, FNM_NOMATCH if not. */ extern int fnmatch (const char *__pattern, const char *__name, - int __flags); + int __flags); #ifdef __cplusplus } diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c index ad58bb266..f89d7486c 100644 --- a/lib/fnmatch_loop.c +++ b/lib/fnmatch_loop.c @@ -19,7 +19,7 @@ /* Match STRING against the file name pattern PATTERN, returning zero if it matches, nonzero if not. */ static int EXT (INT opt, const CHAR *pattern, const CHAR *string, - const CHAR *string_end, bool no_leading_period, int flags) + const CHAR *string_end, bool no_leading_period, int flags) internal_function; static const CHAR *END (const CHAR *patternp) internal_function; @@ -46,310 +46,310 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, c = FOLD (c); switch (c) - { - case L_('?'): - if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') - { - int res; - - res = EXT (c, p, n, string_end, no_leading_period, - flags); - if (res != -1) - return res; - } - - if (n == string_end) - return FNM_NOMATCH; - else if (*n == L_('/') && (flags & FNM_FILE_NAME)) - return FNM_NOMATCH; - else if (*n == L_('.') && no_leading_period) - return FNM_NOMATCH; - break; - - case L_('\\'): - if (!(flags & FNM_NOESCAPE)) - { - c = *p++; - if (c == L_('\0')) - /* Trailing \ loses. */ - return FNM_NOMATCH; - c = FOLD (c); - } - if (n == string_end || FOLD ((UCHAR) *n) != c) - return FNM_NOMATCH; - break; - - case L_('*'): - if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') - { - int res; - - res = EXT (c, p, n, string_end, no_leading_period, - flags); - if (res != -1) - return res; - } - - if (n != string_end && *n == L_('.') && no_leading_period) - return FNM_NOMATCH; - - for (c = *p++; c == L_('?') || c == L_('*'); c = *p++) - { - if (*p == L_('(') && (flags & FNM_EXTMATCH) != 0) - { - const CHAR *endp = END (p); - if (endp != p) - { - /* This is a pattern. Skip over it. */ - p = endp; - continue; - } - } - - if (c == L_('?')) - { - /* A ? needs to match one character. */ - if (n == string_end) - /* There isn't another character; no match. */ - return FNM_NOMATCH; - else if (*n == L_('/') - && __builtin_expect (flags & FNM_FILE_NAME, 0)) - /* A slash does not match a wildcard under - FNM_FILE_NAME. */ - return FNM_NOMATCH; - else - /* One character of the string is consumed in matching - this ? wildcard, so *??? won't match if there are - less than three characters. */ - ++n; - } - } - - if (c == L_('\0')) - /* The wildcard(s) is/are the last element of the pattern. - If the name is a file name and contains another slash - this means it cannot match, unless the FNM_LEADING_DIR - flag is set. */ - { - int result = (flags & FNM_FILE_NAME) == 0 ? 0 : FNM_NOMATCH; - - if (flags & FNM_FILE_NAME) - { - if (flags & FNM_LEADING_DIR) - result = 0; - else - { - if (MEMCHR (n, L_('/'), string_end - n) == NULL) - result = 0; - } - } - - return result; - } - else - { - const CHAR *endp; - - endp = MEMCHR (n, (flags & FNM_FILE_NAME) ? L_('/') : L_('\0'), - string_end - n); - if (endp == NULL) - endp = string_end; - - if (c == L_('[') - || (__builtin_expect (flags & FNM_EXTMATCH, 0) != 0 - && (c == L_('@') || c == L_('+') || c == L_('!')) - && *p == L_('('))) - { - int flags2 = ((flags & FNM_FILE_NAME) - ? flags : (flags & ~FNM_PERIOD)); - bool no_leading_period2 = no_leading_period; - - for (--p; n < endp; ++n, no_leading_period2 = false) - if (FCT (p, n, string_end, no_leading_period2, flags2) - == 0) - return 0; - } - else if (c == L_('/') && (flags & FNM_FILE_NAME)) - { - while (n < string_end && *n != L_('/')) - ++n; - if (n < string_end && *n == L_('/') - && (FCT (p, n + 1, string_end, flags & FNM_PERIOD, flags) - == 0)) - return 0; - } - else - { - int flags2 = ((flags & FNM_FILE_NAME) - ? flags : (flags & ~FNM_PERIOD)); - int no_leading_period2 = no_leading_period; - - if (c == L_('\\') && !(flags & FNM_NOESCAPE)) - c = *p; - c = FOLD (c); - for (--p; n < endp; ++n, no_leading_period2 = false) - if (FOLD ((UCHAR) *n) == c - && (FCT (p, n, string_end, no_leading_period2, flags2) - == 0)) - return 0; - } - } - - /* If we come here no match is possible with the wildcard. */ - return FNM_NOMATCH; - - case L_('['): - { - /* Nonzero if the sense of the character class is inverted. */ - register bool not; - CHAR cold; - UCHAR fn; - - if (posixly_correct == 0) - posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; - - if (n == string_end) - return FNM_NOMATCH; - - if (*n == L_('.') && no_leading_period) - return FNM_NOMATCH; - - if (*n == L_('/') && (flags & FNM_FILE_NAME)) - /* `/' cannot be matched. */ - return FNM_NOMATCH; - - not = (*p == L_('!') || (posixly_correct < 0 && *p == L_('^'))); - if (not) - ++p; - - fn = FOLD ((UCHAR) *n); - - c = *p++; - for (;;) - { - if (!(flags & FNM_NOESCAPE) && c == L_('\\')) - { - if (*p == L_('\0')) - return FNM_NOMATCH; - c = FOLD ((UCHAR) *p); - ++p; - - goto normal_bracket; - } - else if (c == L_('[') && *p == L_(':')) - { - /* Leave room for the null. */ - CHAR str[CHAR_CLASS_MAX_LENGTH + 1]; - size_t c1 = 0; + { + case L_('?'): + if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') + { + int res; + + res = EXT (c, p, n, string_end, no_leading_period, + flags); + if (res != -1) + return res; + } + + if (n == string_end) + return FNM_NOMATCH; + else if (*n == L_('/') && (flags & FNM_FILE_NAME)) + return FNM_NOMATCH; + else if (*n == L_('.') && no_leading_period) + return FNM_NOMATCH; + break; + + case L_('\\'): + if (!(flags & FNM_NOESCAPE)) + { + c = *p++; + if (c == L_('\0')) + /* Trailing \ loses. */ + return FNM_NOMATCH; + c = FOLD (c); + } + if (n == string_end || FOLD ((UCHAR) *n) != c) + return FNM_NOMATCH; + break; + + case L_('*'): + if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') + { + int res; + + res = EXT (c, p, n, string_end, no_leading_period, + flags); + if (res != -1) + return res; + } + + if (n != string_end && *n == L_('.') && no_leading_period) + return FNM_NOMATCH; + + for (c = *p++; c == L_('?') || c == L_('*'); c = *p++) + { + if (*p == L_('(') && (flags & FNM_EXTMATCH) != 0) + { + const CHAR *endp = END (p); + if (endp != p) + { + /* This is a pattern. Skip over it. */ + p = endp; + continue; + } + } + + if (c == L_('?')) + { + /* A ? needs to match one character. */ + if (n == string_end) + /* There isn't another character; no match. */ + return FNM_NOMATCH; + else if (*n == L_('/') + && __builtin_expect (flags & FNM_FILE_NAME, 0)) + /* A slash does not match a wildcard under + FNM_FILE_NAME. */ + return FNM_NOMATCH; + else + /* One character of the string is consumed in matching + this ? wildcard, so *??? won't match if there are + less than three characters. */ + ++n; + } + } + + if (c == L_('\0')) + /* The wildcard(s) is/are the last element of the pattern. + If the name is a file name and contains another slash + this means it cannot match, unless the FNM_LEADING_DIR + flag is set. */ + { + int result = (flags & FNM_FILE_NAME) == 0 ? 0 : FNM_NOMATCH; + + if (flags & FNM_FILE_NAME) + { + if (flags & FNM_LEADING_DIR) + result = 0; + else + { + if (MEMCHR (n, L_('/'), string_end - n) == NULL) + result = 0; + } + } + + return result; + } + else + { + const CHAR *endp; + + endp = MEMCHR (n, (flags & FNM_FILE_NAME) ? L_('/') : L_('\0'), + string_end - n); + if (endp == NULL) + endp = string_end; + + if (c == L_('[') + || (__builtin_expect (flags & FNM_EXTMATCH, 0) != 0 + && (c == L_('@') || c == L_('+') || c == L_('!')) + && *p == L_('('))) + { + int flags2 = ((flags & FNM_FILE_NAME) + ? flags : (flags & ~FNM_PERIOD)); + bool no_leading_period2 = no_leading_period; + + for (--p; n < endp; ++n, no_leading_period2 = false) + if (FCT (p, n, string_end, no_leading_period2, flags2) + == 0) + return 0; + } + else if (c == L_('/') && (flags & FNM_FILE_NAME)) + { + while (n < string_end && *n != L_('/')) + ++n; + if (n < string_end && *n == L_('/') + && (FCT (p, n + 1, string_end, flags & FNM_PERIOD, flags) + == 0)) + return 0; + } + else + { + int flags2 = ((flags & FNM_FILE_NAME) + ? flags : (flags & ~FNM_PERIOD)); + int no_leading_period2 = no_leading_period; + + if (c == L_('\\') && !(flags & FNM_NOESCAPE)) + c = *p; + c = FOLD (c); + for (--p; n < endp; ++n, no_leading_period2 = false) + if (FOLD ((UCHAR) *n) == c + && (FCT (p, n, string_end, no_leading_period2, flags2) + == 0)) + return 0; + } + } + + /* If we come here no match is possible with the wildcard. */ + return FNM_NOMATCH; + + case L_('['): + { + /* Nonzero if the sense of the character class is inverted. */ + register bool not; + CHAR cold; + UCHAR fn; + + if (posixly_correct == 0) + posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; + + if (n == string_end) + return FNM_NOMATCH; + + if (*n == L_('.') && no_leading_period) + return FNM_NOMATCH; + + if (*n == L_('/') && (flags & FNM_FILE_NAME)) + /* `/' cannot be matched. */ + return FNM_NOMATCH; + + not = (*p == L_('!') || (posixly_correct < 0 && *p == L_('^'))); + if (not) + ++p; + + fn = FOLD ((UCHAR) *n); + + c = *p++; + for (;;) + { + if (!(flags & FNM_NOESCAPE) && c == L_('\\')) + { + if (*p == L_('\0')) + return FNM_NOMATCH; + c = FOLD ((UCHAR) *p); + ++p; + + goto normal_bracket; + } + else if (c == L_('[') && *p == L_(':')) + { + /* Leave room for the null. */ + CHAR str[CHAR_CLASS_MAX_LENGTH + 1]; + size_t c1 = 0; #if defined _LIBC || WIDE_CHAR_SUPPORT - wctype_t wt; + wctype_t wt; #endif - const CHAR *startp = p; - - for (;;) - { - if (c1 == CHAR_CLASS_MAX_LENGTH) - /* The name is too long and therefore the pattern - is ill-formed. */ - return FNM_NOMATCH; - - c = *++p; - if (c == L_(':') && p[1] == L_(']')) - { - p += 2; - break; - } - if (c < L_('a') || c >= L_('z')) - { - /* This cannot possibly be a character class name. - Match it as a normal range. */ - p = startp; - c = L_('['); - goto normal_bracket; - } - str[c1++] = c; - } - str[c1] = L_('\0'); + const CHAR *startp = p; + + for (;;) + { + if (c1 == CHAR_CLASS_MAX_LENGTH) + /* The name is too long and therefore the pattern + is ill-formed. */ + return FNM_NOMATCH; + + c = *++p; + if (c == L_(':') && p[1] == L_(']')) + { + p += 2; + break; + } + if (c < L_('a') || c >= L_('z')) + { + /* This cannot possibly be a character class name. + Match it as a normal range. */ + p = startp; + c = L_('['); + goto normal_bracket; + } + str[c1++] = c; + } + str[c1] = L_('\0'); #if defined _LIBC || WIDE_CHAR_SUPPORT - wt = IS_CHAR_CLASS (str); - if (wt == 0) - /* Invalid character class name. */ - return FNM_NOMATCH; + wt = IS_CHAR_CLASS (str); + if (wt == 0) + /* Invalid character class name. */ + return FNM_NOMATCH; # if defined _LIBC && ! WIDE_CHAR_VERSION - /* The following code is glibc specific but does - there a good job in speeding up the code since - we can avoid the btowc() call. */ - if (_ISCTYPE ((UCHAR) *n, wt)) - goto matched; + /* The following code is glibc specific but does + there a good job in speeding up the code since + we can avoid the btowc() call. */ + if (_ISCTYPE ((UCHAR) *n, wt)) + goto matched; # else - if (ISWCTYPE (BTOWC ((UCHAR) *n), wt)) - goto matched; + if (ISWCTYPE (BTOWC ((UCHAR) *n), wt)) + goto matched; # endif #else - if ((STREQ (str, L_("alnum")) && isalnum ((UCHAR) *n)) - || (STREQ (str, L_("alpha")) && isalpha ((UCHAR) *n)) - || (STREQ (str, L_("blank")) && isblank ((UCHAR) *n)) - || (STREQ (str, L_("cntrl")) && iscntrl ((UCHAR) *n)) - || (STREQ (str, L_("digit")) && isdigit ((UCHAR) *n)) - || (STREQ (str, L_("graph")) && isgraph ((UCHAR) *n)) - || (STREQ (str, L_("lower")) && islower ((UCHAR) *n)) - || (STREQ (str, L_("print")) && isprint ((UCHAR) *n)) - || (STREQ (str, L_("punct")) && ispunct ((UCHAR) *n)) - || (STREQ (str, L_("space")) && isspace ((UCHAR) *n)) - || (STREQ (str, L_("upper")) && isupper ((UCHAR) *n)) - || (STREQ (str, L_("xdigit")) && isxdigit ((UCHAR) *n))) - goto matched; + if ((STREQ (str, L_("alnum")) && isalnum ((UCHAR) *n)) + || (STREQ (str, L_("alpha")) && isalpha ((UCHAR) *n)) + || (STREQ (str, L_("blank")) && isblank ((UCHAR) *n)) + || (STREQ (str, L_("cntrl")) && iscntrl ((UCHAR) *n)) + || (STREQ (str, L_("digit")) && isdigit ((UCHAR) *n)) + || (STREQ (str, L_("graph")) && isgraph ((UCHAR) *n)) + || (STREQ (str, L_("lower")) && islower ((UCHAR) *n)) + || (STREQ (str, L_("print")) && isprint ((UCHAR) *n)) + || (STREQ (str, L_("punct")) && ispunct ((UCHAR) *n)) + || (STREQ (str, L_("space")) && isspace ((UCHAR) *n)) + || (STREQ (str, L_("upper")) && isupper ((UCHAR) *n)) + || (STREQ (str, L_("xdigit")) && isxdigit ((UCHAR) *n))) + goto matched; #endif - c = *p++; - } + c = *p++; + } #ifdef _LIBC - else if (c == L_('[') && *p == L_('=')) - { - UCHAR str[1]; - uint32_t nrules = - _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); - const CHAR *startp = p; - - c = *++p; - if (c == L_('\0')) - { - p = startp; - c = L_('['); - goto normal_bracket; - } - str[0] = c; - - c = *++p; - if (c != L_('=') || p[1] != L_(']')) - { - p = startp; - c = L_('['); - goto normal_bracket; - } - p += 2; - - if (nrules == 0) - { - if ((UCHAR) *n == str[0]) - goto matched; - } - else - { - const int32_t *table; + else if (c == L_('[') && *p == L_('=')) + { + UCHAR str[1]; + uint32_t nrules = + _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + const CHAR *startp = p; + + c = *++p; + if (c == L_('\0')) + { + p = startp; + c = L_('['); + goto normal_bracket; + } + str[0] = c; + + c = *++p; + if (c != L_('=') || p[1] != L_(']')) + { + p = startp; + c = L_('['); + goto normal_bracket; + } + p += 2; + + if (nrules == 0) + { + if ((UCHAR) *n == str[0]) + goto matched; + } + else + { + const int32_t *table; # if WIDE_CHAR_VERSION - const int32_t *weights; - const int32_t *extra; + const int32_t *weights; + const int32_t *extra; # else - const unsigned char *weights; - const unsigned char *extra; + const unsigned char *weights; + const unsigned char *extra; # endif - const int32_t *indirect; - int32_t idx; - const UCHAR *cp = (const UCHAR *) str; + const int32_t *indirect; + int32_t idx; + const UCHAR *cp = (const UCHAR *) str; - /* This #include defines a local function! */ + /* This #include defines a local function! */ # if WIDE_CHAR_VERSION # include # else @@ -357,605 +357,605 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, # endif # if WIDE_CHAR_VERSION - table = (const int32_t *) - _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEWC); - weights = (const int32_t *) - _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTWC); - extra = (const int32_t *) - _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAWC); - indirect = (const int32_t *) - _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTWC); + table = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEWC); + weights = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTWC); + extra = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAWC); + indirect = (const int32_t *) + _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTWC); # else - 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); + 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); # endif - idx = findidx (&cp); - if (idx != 0) - { - /* We found a table entry. Now see whether the - character we are currently at has the same - equivalance class value. */ - int len = weights[idx]; - int32_t idx2; - const UCHAR *np = (const UCHAR *) n; - - idx2 = findidx (&np); - if (idx2 != 0 && len == weights[idx2]) - { - int cnt = 0; - - while (cnt < len - && (weights[idx + 1 + cnt] - == weights[idx2 + 1 + cnt])) - ++cnt; - - if (cnt == len) - goto matched; - } - } - } - - c = *p++; - } + idx = findidx (&cp); + if (idx != 0) + { + /* We found a table entry. Now see whether the + character we are currently at has the same + equivalance class value. */ + int len = weights[idx]; + int32_t idx2; + const UCHAR *np = (const UCHAR *) n; + + idx2 = findidx (&np); + if (idx2 != 0 && len == weights[idx2]) + { + int cnt = 0; + + while (cnt < len + && (weights[idx + 1 + cnt] + == weights[idx2 + 1 + cnt])) + ++cnt; + + if (cnt == len) + goto matched; + } + } + } + + c = *p++; + } #endif - else if (c == L_('\0')) - /* [ (unterminated) loses. */ - return FNM_NOMATCH; - else - { - bool is_range = false; + else if (c == L_('\0')) + /* [ (unterminated) loses. */ + return FNM_NOMATCH; + else + { + bool is_range = false; #ifdef _LIBC - bool is_seqval = false; - - if (c == L_('[') && *p == L_('.')) - { - uint32_t nrules = - _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); - const CHAR *startp = p; - size_t c1 = 0; - - while (1) - { - c = *++p; - if (c == L_('.') && p[1] == L_(']')) - { - p += 2; - break; - } - if (c == '\0') - return FNM_NOMATCH; - ++c1; - } - - /* We have to handling the symbols differently in - ranges since then the collation sequence is - important. */ - is_range = *p == L_('-') && p[1] != L_('\0'); - - if (nrules == 0) - { - /* There are no names defined in the collation - data. Therefore we only accept the trivial - names consisting of the character itself. */ - if (c1 != 1) - return FNM_NOMATCH; - - if (!is_range && *n == startp[1]) - goto matched; - - cold = startp[1]; - c = *p++; - } - else - { - int32_t table_size; - const int32_t *symb_table; + bool is_seqval = false; + + if (c == L_('[') && *p == L_('.')) + { + uint32_t nrules = + _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); + const CHAR *startp = p; + size_t c1 = 0; + + while (1) + { + c = *++p; + if (c == L_('.') && p[1] == L_(']')) + { + p += 2; + break; + } + if (c == '\0') + return FNM_NOMATCH; + ++c1; + } + + /* We have to handling the symbols differently in + ranges since then the collation sequence is + important. */ + is_range = *p == L_('-') && p[1] != L_('\0'); + + if (nrules == 0) + { + /* There are no names defined in the collation + data. Therefore we only accept the trivial + names consisting of the character itself. */ + if (c1 != 1) + return FNM_NOMATCH; + + if (!is_range && *n == startp[1]) + goto matched; + + cold = startp[1]; + c = *p++; + } + else + { + int32_t table_size; + const int32_t *symb_table; # ifdef WIDE_CHAR_VERSION - char str[c1]; - size_t strcnt; + char str[c1]; + size_t strcnt; # else # define str (startp + 1) # endif - const unsigned char *extra; - int32_t idx; - int32_t elem; - int32_t second; - int32_t hash; + const unsigned char *extra; + int32_t idx; + int32_t elem; + int32_t second; + int32_t hash; # ifdef WIDE_CHAR_VERSION - /* We have to convert the name to a single-byte - string. This is possible since the names - consist of ASCII characters and the internal - representation is UCS4. */ - for (strcnt = 0; strcnt < c1; ++strcnt) - str[strcnt] = startp[1 + strcnt]; + /* We have to convert the name to a single-byte + string. This is possible since the names + consist of ASCII characters and the internal + representation is UCS4. */ + for (strcnt = 0; strcnt < c1; ++strcnt) + str[strcnt] = startp[1 + strcnt]; # endif - 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); - - /* Locate the character in the hashing table. */ - hash = elem_hash (str, c1); - - idx = 0; - elem = hash % table_size; - if (symb_table[2 * elem] != 0) - { - second = hash % (table_size - 2) + 1; - - do - { - /* First compare the hashing value. */ - if (symb_table[2 * elem] == hash - && (c1 - == extra[symb_table[2 * elem + 1]]) - && memcmp (str, - &extra[symb_table[2 * elem - + 1] - + 1], c1) == 0) - { - /* Yep, this is the entry. */ - idx = symb_table[2 * elem + 1]; - idx += 1 + extra[idx]; - break; - } - - /* Next entry. */ - elem += second; - } - while (symb_table[2 * elem] != 0); - } - - if (symb_table[2 * elem] != 0) - { - /* Compare the byte sequence but only if - this is not part of a range. */ + 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); + + /* Locate the character in the hashing table. */ + hash = elem_hash (str, c1); + + idx = 0; + elem = hash % table_size; + if (symb_table[2 * elem] != 0) + { + second = hash % (table_size - 2) + 1; + + do + { + /* First compare the hashing value. */ + if (symb_table[2 * elem] == hash + && (c1 + == extra[symb_table[2 * elem + 1]]) + && memcmp (str, + &extra[symb_table[2 * elem + + 1] + + 1], c1) == 0) + { + /* Yep, this is the entry. */ + idx = symb_table[2 * elem + 1]; + idx += 1 + extra[idx]; + break; + } + + /* Next entry. */ + elem += second; + } + while (symb_table[2 * elem] != 0); + } + + if (symb_table[2 * elem] != 0) + { + /* Compare the byte sequence but only if + this is not part of a range. */ # ifdef WIDE_CHAR_VERSION - int32_t *wextra; + int32_t *wextra; - idx += 1 + extra[idx]; - /* Adjust for the alignment. */ - idx = (idx + 3) & ~3; + idx += 1 + extra[idx]; + /* Adjust for the alignment. */ + idx = (idx + 3) & ~3; - wextra = (int32_t *) &extra[idx + 4]; + wextra = (int32_t *) &extra[idx + 4]; # endif - if (! is_range) - { + if (! is_range) + { # ifdef WIDE_CHAR_VERSION - for (c1 = 0; - (int32_t) c1 < wextra[idx]; - ++c1) - if (n[c1] != wextra[1 + c1]) - break; - - if ((int32_t) c1 == wextra[idx]) - goto matched; + for (c1 = 0; + (int32_t) c1 < wextra[idx]; + ++c1) + if (n[c1] != wextra[1 + c1]) + break; + + if ((int32_t) c1 == wextra[idx]) + goto matched; # else - for (c1 = 0; c1 < extra[idx]; ++c1) - if (n[c1] != extra[1 + c1]) - break; + for (c1 = 0; c1 < extra[idx]; ++c1) + if (n[c1] != extra[1 + c1]) + break; - if (c1 == extra[idx]) - goto matched; + if (c1 == extra[idx]) + goto matched; # endif - } + } - /* Get the collation sequence value. */ - is_seqval = true; + /* Get the collation sequence value. */ + is_seqval = true; # ifdef WIDE_CHAR_VERSION - cold = wextra[1 + wextra[idx]]; + cold = wextra[1 + wextra[idx]]; # else - /* Adjust for the alignment. */ - idx += 1 + extra[idx]; - idx = (idx + 3) & ~4; - cold = *((int32_t *) &extra[idx]); + /* Adjust for the alignment. */ + idx += 1 + extra[idx]; + idx = (idx + 3) & ~4; + cold = *((int32_t *) &extra[idx]); # endif - c = *p++; - } - else if (c1 == 1) - { - /* No valid character. Match it as a - single byte. */ - if (!is_range && *n == str[0]) - goto matched; - - cold = str[0]; - c = *p++; - } - else - return FNM_NOMATCH; - } - } - else + c = *p++; + } + else if (c1 == 1) + { + /* No valid character. Match it as a + single byte. */ + if (!is_range && *n == str[0]) + goto matched; + + cold = str[0]; + c = *p++; + } + else + return FNM_NOMATCH; + } + } + else # undef str #endif - { - c = FOLD (c); - normal_bracket: + { + c = FOLD (c); + normal_bracket: - /* We have to handling the symbols differently in - ranges since then the collation sequence is - important. */ - is_range = (*p == L_('-') && p[1] != L_('\0') - && p[1] != L_(']')); + /* We have to handling the symbols differently in + ranges since then the collation sequence is + important. */ + is_range = (*p == L_('-') && p[1] != L_('\0') + && p[1] != L_(']')); - if (!is_range && c == fn) - goto matched; + if (!is_range && c == fn) + goto matched; #if _LIBC - /* This is needed if we goto normal_bracket; from - outside of is_seqval's scope. */ - is_seqval = false; + /* This is needed if we goto normal_bracket; from + outside of is_seqval's scope. */ + is_seqval = false; #endif - cold = c; - c = *p++; - } + cold = c; + c = *p++; + } - if (c == L_('-') && *p != L_(']')) - { + if (c == L_('-') && *p != L_(']')) + { #if _LIBC - /* We have to find the collation sequence - value for C. Collation sequence is nothing - we can regularly access. The sequence - value is defined by the order in which the - definitions of the collation values for the - various characters appear in the source - file. A strange concept, nowhere - documented. */ - uint32_t fcollseq; - uint32_t lcollseq; - UCHAR cend = *p++; + /* We have to find the collation sequence + value for C. Collation sequence is nothing + we can regularly access. The sequence + value is defined by the order in which the + definitions of the collation values for the + various characters appear in the source + file. A strange concept, nowhere + documented. */ + uint32_t fcollseq; + uint32_t lcollseq; + UCHAR cend = *p++; # ifdef WIDE_CHAR_VERSION - /* Search in the `names' array for the characters. */ - fcollseq = __collseq_table_lookup (collseq, fn); - if (fcollseq == ~((uint32_t) 0)) - /* XXX We don't know anything about the character - we are supposed to match. This means we are - failing. */ - goto range_not_matched; - - if (is_seqval) - lcollseq = cold; - else - lcollseq = __collseq_table_lookup (collseq, cold); + /* Search in the `names' array for the characters. */ + fcollseq = __collseq_table_lookup (collseq, fn); + if (fcollseq == ~((uint32_t) 0)) + /* XXX We don't know anything about the character + we are supposed to match. This means we are + failing. */ + goto range_not_matched; + + if (is_seqval) + lcollseq = cold; + else + lcollseq = __collseq_table_lookup (collseq, cold); # else - fcollseq = collseq[fn]; - lcollseq = is_seqval ? cold : collseq[(UCHAR) cold]; + fcollseq = collseq[fn]; + lcollseq = is_seqval ? cold : collseq[(UCHAR) cold]; # endif - is_seqval = false; - if (cend == L_('[') && *p == L_('.')) - { - uint32_t nrules = - _NL_CURRENT_WORD (LC_COLLATE, - _NL_COLLATE_NRULES); - const CHAR *startp = p; - size_t c1 = 0; - - while (1) - { - c = *++p; - if (c == L_('.') && p[1] == L_(']')) - { - p += 2; - break; - } - if (c == '\0') - return FNM_NOMATCH; - ++c1; - } - - if (nrules == 0) - { - /* There are no names defined in the - collation data. Therefore we only - accept the trivial names consisting - of the character itself. */ - if (c1 != 1) - return FNM_NOMATCH; - - cend = startp[1]; - } - else - { - int32_t table_size; - const int32_t *symb_table; + is_seqval = false; + if (cend == L_('[') && *p == L_('.')) + { + uint32_t nrules = + _NL_CURRENT_WORD (LC_COLLATE, + _NL_COLLATE_NRULES); + const CHAR *startp = p; + size_t c1 = 0; + + while (1) + { + c = *++p; + if (c == L_('.') && p[1] == L_(']')) + { + p += 2; + break; + } + if (c == '\0') + return FNM_NOMATCH; + ++c1; + } + + if (nrules == 0) + { + /* There are no names defined in the + collation data. Therefore we only + accept the trivial names consisting + of the character itself. */ + if (c1 != 1) + return FNM_NOMATCH; + + cend = startp[1]; + } + else + { + int32_t table_size; + const int32_t *symb_table; # ifdef WIDE_CHAR_VERSION - char str[c1]; - size_t strcnt; + char str[c1]; + size_t strcnt; # else # define str (startp + 1) # endif - const unsigned char *extra; - int32_t idx; - int32_t elem; - int32_t second; - int32_t hash; + const unsigned char *extra; + int32_t idx; + int32_t elem; + int32_t second; + int32_t hash; # ifdef WIDE_CHAR_VERSION - /* We have to convert the name to a single-byte - string. This is possible since the names - consist of ASCII characters and the internal - representation is UCS4. */ - for (strcnt = 0; strcnt < c1; ++strcnt) - str[strcnt] = startp[1 + strcnt]; + /* We have to convert the name to a single-byte + string. This is possible since the names + consist of ASCII characters and the internal + representation is UCS4. */ + for (strcnt = 0; strcnt < c1; ++strcnt) + str[strcnt] = startp[1 + strcnt]; # endif - 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); - - /* Locate the character in the hashing + 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); + + /* Locate the character in the hashing table. */ - hash = elem_hash (str, c1); - - idx = 0; - elem = hash % table_size; - if (symb_table[2 * elem] != 0) - { - second = hash % (table_size - 2) + 1; - - do - { - /* First compare the hashing value. */ - if (symb_table[2 * elem] == hash - && (c1 - == extra[symb_table[2 * elem + 1]]) - && memcmp (str, - &extra[symb_table[2 * elem + 1] - + 1], c1) == 0) - { - /* Yep, this is the entry. */ - idx = symb_table[2 * elem + 1]; - idx += 1 + extra[idx]; - break; - } - - /* Next entry. */ - elem += second; - } - while (symb_table[2 * elem] != 0); - } - - if (symb_table[2 * elem] != 0) - { - /* Compare the byte sequence but only if - this is not part of a range. */ + hash = elem_hash (str, c1); + + idx = 0; + elem = hash % table_size; + if (symb_table[2 * elem] != 0) + { + second = hash % (table_size - 2) + 1; + + do + { + /* First compare the hashing value. */ + if (symb_table[2 * elem] == hash + && (c1 + == extra[symb_table[2 * elem + 1]]) + && memcmp (str, + &extra[symb_table[2 * elem + 1] + + 1], c1) == 0) + { + /* Yep, this is the entry. */ + idx = symb_table[2 * elem + 1]; + idx += 1 + extra[idx]; + break; + } + + /* Next entry. */ + elem += second; + } + while (symb_table[2 * elem] != 0); + } + + if (symb_table[2 * elem] != 0) + { + /* Compare the byte sequence but only if + this is not part of a range. */ # ifdef WIDE_CHAR_VERSION - int32_t *wextra; + int32_t *wextra; - idx += 1 + extra[idx]; - /* Adjust for the alignment. */ - idx = (idx + 3) & ~4; + idx += 1 + extra[idx]; + /* Adjust for the alignment. */ + idx = (idx + 3) & ~4; - wextra = (int32_t *) &extra[idx + 4]; + wextra = (int32_t *) &extra[idx + 4]; # endif - /* Get the collation sequence value. */ - is_seqval = true; + /* Get the collation sequence value. */ + is_seqval = true; # ifdef WIDE_CHAR_VERSION - cend = wextra[1 + wextra[idx]]; + cend = wextra[1 + wextra[idx]]; # else - /* Adjust for the alignment. */ - idx += 1 + extra[idx]; - idx = (idx + 3) & ~4; - cend = *((int32_t *) &extra[idx]); + /* Adjust for the alignment. */ + idx += 1 + extra[idx]; + idx = (idx + 3) & ~4; + cend = *((int32_t *) &extra[idx]); # endif - } - else if (symb_table[2 * elem] != 0 && c1 == 1) - { - cend = str[0]; - c = *p++; - } - else - return FNM_NOMATCH; - } + } + else if (symb_table[2 * elem] != 0 && c1 == 1) + { + cend = str[0]; + c = *p++; + } + else + return FNM_NOMATCH; + } # undef str - } - else - { - if (!(flags & FNM_NOESCAPE) && cend == L_('\\')) - cend = *p++; - if (cend == L_('\0')) - return FNM_NOMATCH; - cend = FOLD (cend); - } - - /* XXX It is not entirely clear to me how to handle - characters which are not mentioned in the - collation specification. */ - if ( + } + else + { + if (!(flags & FNM_NOESCAPE) && cend == L_('\\')) + cend = *p++; + if (cend == L_('\0')) + return FNM_NOMATCH; + cend = FOLD (cend); + } + + /* XXX It is not entirely clear to me how to handle + characters which are not mentioned in the + collation specification. */ + if ( # ifdef WIDE_CHAR_VERSION - lcollseq == 0xffffffff || + lcollseq == 0xffffffff || # endif - lcollseq <= fcollseq) - { - /* We have to look at the upper bound. */ - uint32_t hcollseq; - - if (is_seqval) - hcollseq = cend; - else - { + lcollseq <= fcollseq) + { + /* We have to look at the upper bound. */ + uint32_t hcollseq; + + if (is_seqval) + hcollseq = cend; + else + { # ifdef WIDE_CHAR_VERSION - hcollseq = - __collseq_table_lookup (collseq, cend); - if (hcollseq == ~((uint32_t) 0)) - { - /* Hum, no information about the upper - bound. The matching succeeds if the - lower bound is matched exactly. */ - if (lcollseq != fcollseq) - goto range_not_matched; - - goto matched; - } + hcollseq = + __collseq_table_lookup (collseq, cend); + if (hcollseq == ~((uint32_t) 0)) + { + /* Hum, no information about the upper + bound. The matching succeeds if the + lower bound is matched exactly. */ + if (lcollseq != fcollseq) + goto range_not_matched; + + goto matched; + } # else - hcollseq = collseq[cend]; + hcollseq = collseq[cend]; # endif - } + } - if (lcollseq <= hcollseq && fcollseq <= hcollseq) - goto matched; - } + if (lcollseq <= hcollseq && fcollseq <= hcollseq) + goto matched; + } # ifdef WIDE_CHAR_VERSION - range_not_matched: + range_not_matched: # endif #else - /* We use a boring value comparison of the character - values. This is better than comparing using - `strcoll' since the latter would have surprising - and sometimes fatal consequences. */ - UCHAR cend = *p++; - - if (!(flags & FNM_NOESCAPE) && cend == L_('\\')) - cend = *p++; - if (cend == L_('\0')) - return FNM_NOMATCH; - - /* It is a range. */ - if (cold <= fn && fn <= cend) - goto matched; + /* We use a boring value comparison of the character + values. This is better than comparing using + `strcoll' since the latter would have surprising + and sometimes fatal consequences. */ + UCHAR cend = *p++; + + if (!(flags & FNM_NOESCAPE) && cend == L_('\\')) + cend = *p++; + if (cend == L_('\0')) + return FNM_NOMATCH; + + /* It is a range. */ + if (cold <= fn && fn <= cend) + goto matched; #endif - c = *p++; - } - } - - if (c == L_(']')) - break; - } - - if (!not) - return FNM_NOMATCH; - break; - - matched: - /* Skip the rest of the [...] that already matched. */ - do - { - ignore_next: - c = *p++; - - if (c == L_('\0')) - /* [... (unterminated) loses. */ - return FNM_NOMATCH; - - if (!(flags & FNM_NOESCAPE) && c == L_('\\')) - { - if (*p == L_('\0')) - return FNM_NOMATCH; - /* XXX 1003.2d11 is unclear if this is right. */ - ++p; - } - else if (c == L_('[') && *p == L_(':')) - { - int c1 = 0; - const CHAR *startp = p; - - while (1) - { - c = *++p; - if (++c1 == CHAR_CLASS_MAX_LENGTH) - return FNM_NOMATCH; - - if (*p == L_(':') && p[1] == L_(']')) - break; - - if (c < L_('a') || c >= L_('z')) - { - p = startp; - goto ignore_next; - } - } - p += 2; - c = *p++; - } - else if (c == L_('[') && *p == L_('=')) - { - c = *++p; - if (c == L_('\0')) - return FNM_NOMATCH; - c = *++p; - if (c != L_('=') || p[1] != L_(']')) - return FNM_NOMATCH; - p += 2; - c = *p++; - } - else if (c == L_('[') && *p == L_('.')) - { - ++p; - while (1) - { - c = *++p; - if (c == '\0') - return FNM_NOMATCH; - - if (*p == L_('.') && p[1] == L_(']')) - break; - } - p += 2; - c = *p++; - } - } - while (c != L_(']')); - if (not) - return FNM_NOMATCH; - } - break; - - case L_('+'): - case L_('@'): - case L_('!'): - if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') - { - int res; - - res = EXT (c, p, n, string_end, no_leading_period, flags); - if (res != -1) - return res; - } - goto normal_match; - - case L_('/'): - if (NO_LEADING_PERIOD (flags)) - { - if (n == string_end || c != (UCHAR) *n) - return FNM_NOMATCH; - - new_no_leading_period = true; - break; - } - /* FALLTHROUGH */ - default: - normal_match: - if (n == string_end || c != FOLD ((UCHAR) *n)) - return FNM_NOMATCH; - } + c = *p++; + } + } + + if (c == L_(']')) + break; + } + + if (!not) + return FNM_NOMATCH; + break; + + matched: + /* Skip the rest of the [...] that already matched. */ + do + { + ignore_next: + c = *p++; + + if (c == L_('\0')) + /* [... (unterminated) loses. */ + return FNM_NOMATCH; + + if (!(flags & FNM_NOESCAPE) && c == L_('\\')) + { + if (*p == L_('\0')) + return FNM_NOMATCH; + /* XXX 1003.2d11 is unclear if this is right. */ + ++p; + } + else if (c == L_('[') && *p == L_(':')) + { + int c1 = 0; + const CHAR *startp = p; + + while (1) + { + c = *++p; + if (++c1 == CHAR_CLASS_MAX_LENGTH) + return FNM_NOMATCH; + + if (*p == L_(':') && p[1] == L_(']')) + break; + + if (c < L_('a') || c >= L_('z')) + { + p = startp; + goto ignore_next; + } + } + p += 2; + c = *p++; + } + else if (c == L_('[') && *p == L_('=')) + { + c = *++p; + if (c == L_('\0')) + return FNM_NOMATCH; + c = *++p; + if (c != L_('=') || p[1] != L_(']')) + return FNM_NOMATCH; + p += 2; + c = *p++; + } + else if (c == L_('[') && *p == L_('.')) + { + ++p; + while (1) + { + c = *++p; + if (c == '\0') + return FNM_NOMATCH; + + if (*p == L_('.') && p[1] == L_(']')) + break; + } + p += 2; + c = *p++; + } + } + while (c != L_(']')); + if (not) + return FNM_NOMATCH; + } + break; + + case L_('+'): + case L_('@'): + case L_('!'): + if (__builtin_expect (flags & FNM_EXTMATCH, 0) && *p == '(') + { + int res; + + res = EXT (c, p, n, string_end, no_leading_period, flags); + if (res != -1) + return res; + } + goto normal_match; + + case L_('/'): + if (NO_LEADING_PERIOD (flags)) + { + if (n == string_end || c != (UCHAR) *n) + return FNM_NOMATCH; + + new_no_leading_period = true; + break; + } + /* FALLTHROUGH */ + default: + normal_match: + if (n == string_end || c != FOLD ((UCHAR) *n)) + return FNM_NOMATCH; + } no_leading_period = new_no_leading_period; ++n; @@ -984,25 +984,25 @@ END (const CHAR *pattern) return pattern; else if (*p == L_('[')) { - /* Handle brackets special. */ - if (posixly_correct == 0) - posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; - - /* Skip the not sign. We have to recognize it because of a possibly - following ']'. */ - if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^'))) - ++p; - /* A leading ']' is recognized as such. */ - if (*p == L_(']')) - ++p; - /* Skip over all characters of the list. */ - while (*p != L_(']')) - if (*p++ == L_('\0')) - /* This is no valid pattern. */ - return pattern; + /* Handle brackets special. */ + if (posixly_correct == 0) + posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; + + /* Skip the not sign. We have to recognize it because of a possibly + following ']'. */ + if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^'))) + ++p; + /* A leading ']' is recognized as such. */ + if (*p == L_(']')) + ++p; + /* Skip over all characters of the list. */ + while (*p != L_(']')) + if (*p++ == L_('\0')) + /* This is no valid pattern. */ + return pattern; } else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@') - || *p == L_('!')) && p[1] == L_('(')) + || *p == L_('!')) && p[1] == L_('(')) p = END (p + 1); else if (*p == L_(')')) break; @@ -1037,63 +1037,63 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, return -1; else if (*p == L_('[')) { - /* Handle brackets special. */ - if (posixly_correct == 0) - posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; - - /* Skip the not sign. We have to recognize it because of a possibly - following ']'. */ - if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^'))) - ++p; - /* A leading ']' is recognized as such. */ - if (*p == L_(']')) - ++p; - /* Skip over all characters of the list. */ - while (*p != L_(']')) - if (*p++ == L_('\0')) - /* This is no valid pattern. */ - return -1; + /* Handle brackets special. */ + if (posixly_correct == 0) + posixly_correct = getenv ("POSIXLY_CORRECT") != NULL ? 1 : -1; + + /* Skip the not sign. We have to recognize it because of a possibly + following ']'. */ + if (*++p == L_('!') || (posixly_correct < 0 && *p == L_('^'))) + ++p; + /* A leading ']' is recognized as such. */ + if (*p == L_(']')) + ++p; + /* Skip over all characters of the list. */ + while (*p != L_(']')) + if (*p++ == L_('\0')) + /* This is no valid pattern. */ + return -1; } else if ((*p == L_('?') || *p == L_('*') || *p == L_('+') || *p == L_('@') - || *p == L_('!')) && p[1] == L_('(')) + || *p == L_('!')) && p[1] == L_('(')) /* Remember the nesting level. */ ++level; else if (*p == L_(')')) { - if (level-- == 0) - { - /* This means we found the end of the pattern. */ + if (level-- == 0) + { + /* This means we found the end of the pattern. */ #define NEW_PATTERN \ - struct patternlist *newp; \ - size_t plen; \ - size_t plensize; \ - size_t newpsize; \ - \ - plen = (opt == L_('?') || opt == L_('@') \ - ? pattern_len \ - : p - startp + 1UL); \ - plensize = plen * sizeof (CHAR); \ - newpsize = offsetof (struct patternlist, str) + plensize; \ - if ((size_t) -1 / sizeof (CHAR) < plen \ - || newpsize < offsetof (struct patternlist, str) \ - || ALLOCA_LIMIT <= newpsize) \ - return -1; \ - newp = (struct patternlist *) alloca (newpsize); \ - *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L_('\0'); \ - newp->next = NULL; \ - *lastp = newp; \ - lastp = &newp->next - NEW_PATTERN; - break; - } + struct patternlist *newp; \ + size_t plen; \ + size_t plensize; \ + size_t newpsize; \ + \ + plen = (opt == L_('?') || opt == L_('@') \ + ? pattern_len \ + : p - startp + 1UL); \ + plensize = plen * sizeof (CHAR); \ + newpsize = offsetof (struct patternlist, str) + plensize; \ + if ((size_t) -1 / sizeof (CHAR) < plen \ + || newpsize < offsetof (struct patternlist, str) \ + || ALLOCA_LIMIT <= newpsize) \ + return -1; \ + newp = (struct patternlist *) alloca (newpsize); \ + *((CHAR *) MEMPCPY (newp->str, startp, p - startp)) = L_('\0'); \ + newp->next = NULL; \ + *lastp = newp; \ + lastp = &newp->next + NEW_PATTERN; + break; + } } else if (*p == L_('|')) { - if (level == 0) - { - NEW_PATTERN; - startp = p + 1; - } + if (level == 0) + { + NEW_PATTERN; + startp = p + 1; + } } assert (list != NULL); assert (p[-1] == L_(')')); @@ -1103,36 +1103,36 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, { case L_('*'): if (FCT (p, string, string_end, no_leading_period, flags) == 0) - return 0; + return 0; /* FALLTHROUGH */ case L_('+'): do - { - for (rs = string; rs <= string_end; ++rs) - /* First match the prefix with the current pattern with the - current pattern. */ - if (FCT (list->str, string, rs, no_leading_period, - flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0 - /* This was successful. Now match the rest with the rest - of the pattern. */ - && (FCT (p, rs, string_end, - rs == string - ? no_leading_period - : rs[-1] == '/' && NO_LEADING_PERIOD (flags), - flags & FNM_FILE_NAME - ? flags : flags & ~FNM_PERIOD) == 0 - /* This didn't work. Try the whole pattern. */ - || (rs != string - && FCT (pattern - 1, rs, string_end, - rs == string - ? no_leading_period - : rs[-1] == '/' && NO_LEADING_PERIOD (flags), - flags & FNM_FILE_NAME - ? flags : flags & ~FNM_PERIOD) == 0))) - /* It worked. Signal success. */ - return 0; - } + { + for (rs = string; rs <= string_end; ++rs) + /* First match the prefix with the current pattern with the + current pattern. */ + if (FCT (list->str, string, rs, no_leading_period, + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0 + /* This was successful. Now match the rest with the rest + of the pattern. */ + && (FCT (p, rs, string_end, + rs == string + ? no_leading_period + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), + flags & FNM_FILE_NAME + ? flags : flags & ~FNM_PERIOD) == 0 + /* This didn't work. Try the whole pattern. */ + || (rs != string + && FCT (pattern - 1, rs, string_end, + rs == string + ? no_leading_period + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), + flags & FNM_FILE_NAME + ? flags : flags & ~FNM_PERIOD) == 0))) + /* It worked. Signal success. */ + return 0; + } while ((list = list->next) != NULL); /* None of the patterns lead to a match. */ @@ -1140,20 +1140,20 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, case L_('?'): if (FCT (p, string, string_end, no_leading_period, flags) == 0) - return 0; + return 0; /* FALLTHROUGH */ case L_('@'): do - /* I cannot believe it but `strcat' is actually acceptable - here. Match the entire string with the prefix from the - pattern list and the rest of the pattern following the - pattern list. */ - if (FCT (STRCAT (list->str, p), string, string_end, - no_leading_period, - flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0) - /* It worked. Signal success. */ - return 0; + /* I cannot believe it but `strcat' is actually acceptable + here. Match the entire string with the prefix from the + pattern list and the rest of the pattern following the + pattern list. */ + if (FCT (STRCAT (list->str, p), string, string_end, + no_leading_period, + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0) + /* It worked. Signal success. */ + return 0; while ((list = list->next) != NULL); /* None of the patterns lead to a match. */ @@ -1161,28 +1161,28 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, case L_('!'): for (rs = string; rs <= string_end; ++rs) - { - struct patternlist *runp; - - for (runp = list; runp != NULL; runp = runp->next) - if (FCT (runp->str, string, rs, no_leading_period, - flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0) - break; - - /* If none of the patterns matched see whether the rest does. */ - if (runp == NULL - && (FCT (p, rs, string_end, - rs == string - ? no_leading_period - : rs[-1] == '/' && NO_LEADING_PERIOD (flags), - flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) - == 0)) - /* This is successful. */ - return 0; - } + { + struct patternlist *runp; + + for (runp = list; runp != NULL; runp = runp->next) + if (FCT (runp->str, string, rs, no_leading_period, + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0) + break; + + /* If none of the patterns matched see whether the rest does. */ + if (runp == NULL + && (FCT (p, rs, string_end, + rs == string + ? no_leading_period + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), + flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) + == 0)) + /* This is successful. */ + return 0; + } /* None of the patterns together with the rest of the pattern - lead to a match. */ + lead to a match. */ return FNM_NOMATCH; default: diff --git a/lib/fopen-safer.c b/lib/fopen-safer.c index 9c7992237..14d77d5cb 100644 --- a/lib/fopen-safer.c +++ b/lib/fopen-safer.c @@ -38,26 +38,26 @@ fopen_safer (char const *file, char const *mode) int fd = fileno (fp); if (0 <= fd && fd <= STDERR_FILENO) - { - int f = dup_safer (fd); + { + int f = dup_safer (fd); - if (f < 0) - { - int e = errno; - fclose (fp); - errno = e; - return NULL; - } + 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; - } - } + if (fclose (fp) != 0 + || ! (fp = fdopen (f, mode))) + { + int e = errno; + close (f); + errno = e; + return NULL; + } + } } return fp; diff --git a/lib/fopen.c b/lib/fopen.c index 72610bd9b..781ce2c50 100644 --- a/lib/fopen.c +++ b/lib/fopen.c @@ -68,35 +68,35 @@ rpl_fopen (const char *filename, const char *mode) 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; + 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 diff --git a/lib/fprintf.c b/lib/fprintf.c index 7070f95b4..eb1cf8e36 100644 --- a/lib/fprintf.c +++ b/lib/fprintf.c @@ -55,11 +55,11 @@ fprintf (FILE *fp, const char *format, ...) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/fprintftime.h b/lib/fprintftime.h index 886a7dd4f..918fb8929 100644 --- a/lib/fprintftime.h +++ b/lib/fprintftime.h @@ -26,4 +26,4 @@ nstrftime format string, FMT) the time data, *TM, and the UTC and NANOSECONDS values. */ size_t fprintftime (FILE *fp, char const *fmt, struct tm const *tm, - int utc, int nanoseconds); + int utc, int nanoseconds); diff --git a/lib/fpucw.h b/lib/fpucw.h index a6226afcf..2dd1734cb 100644 --- a/lib/fpucw.h +++ b/lib/fpucw.h @@ -70,19 +70,19 @@ typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */ # define FPU_PC_EXTENDED 0x300 /* glibc calls this _FPU_EXTENDED */ # define GET_FPUCW() \ - ({ fpucw_t _cw; \ - __asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \ - _cw; \ + ({ 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)); \ + (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 (), \ + (void)(oldcw = GET_FPUCW (), \ SET_FPUCW ((oldcw & ~FPU_PC_MASK) | FPU_PC_EXTENDED)) # define END_LONG_DOUBLE_ROUNDING() \ SET_FPUCW (oldcw) diff --git a/lib/fpurge.c b/lib/fpurge.c index 114dabf19..8ca7f12c2 100644 --- a/lib/fpurge.c +++ b/lib/fpurge.c @@ -75,13 +75,13 @@ fpurge (FILE *fp) 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_->_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); + free (fp_ub._base); fp_ub._base = NULL; } return 0; diff --git a/lib/freadahead.c b/lib/freadahead.c index f4b5ed702..ef7603498 100644 --- a/lib/freadahead.c +++ b/lib/freadahead.c @@ -29,8 +29,8 @@ freadahead (FILE *fp) 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); + + (fp->_flags & _IO_IN_BACKUP ? fp->_IO_save_end - fp->_IO_save_base : + 0); #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ if ((fp_->_flags & __SWR) != 0 || fp_->_r < 0) return 0; @@ -38,7 +38,7 @@ freadahead (FILE *fp) return __sreadahead (fp); # else return fp_->_r - + (HASUB (fp) ? fp_->_ur : 0); + + (HASUB (fp) ? fp_->_ur : 0); # endif #elif defined __EMX__ /* emx+gcc */ if ((fp->_flags & _IOWRT) != 0) @@ -57,7 +57,7 @@ freadahead (FILE *fp) if (fp->__modeflags & __FLAG_WRITING) return 0; return (fp->__bufread - fp->__bufpos) - + (fp->__modeflags & __FLAG_UNGOT ? 1 : 0); + + (fp->__modeflags & __FLAG_UNGOT ? 1 : 0); # else return 0; # endif @@ -67,15 +67,15 @@ freadahead (FILE *fp) /* 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); + + (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); + ? fp->__get_limit - fp->__pushback_bufp + 1 + : fp->__get_limit - fp->__bufp); #elif defined SLOW_BUT_NO_HACKS /* users can define this */ abort (); return 0; diff --git a/lib/freading.c b/lib/freading.c index 4da0e31bb..73cac2952 100644 --- a/lib/freading.c +++ b/lib/freading.c @@ -33,8 +33,8 @@ freading (FILE *fp) 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)); + || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0 + && fp->_IO_read_base != NULL)); #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ return (fp_->_flags & __SRD) != 0; #elif defined __EMX__ /* emx+gcc */ @@ -45,7 +45,7 @@ freading (FILE *fp) return (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) != 0; #elif defined __QNX__ /* QNX */ return ((fp->_Mode & 0x2 /* _MOPENW */) == 0 - || (fp->_Mode & 0x1000 /* _MREAD */) != 0); + || (fp->_Mode & 0x1000 /* _MREAD */) != 0); #elif defined __MINT__ /* Atari FreeMiNT */ if (!fp->__mode.__write) return 1; diff --git a/lib/freadseek.c b/lib/freadseek.c index fc50f5136..3166116fa 100644 --- a/lib/freadseek.c +++ b/lib/freadseek.c @@ -80,24 +80,24 @@ freadseek (FILE *fp, size_t offset) size_t buffered; if (freadptr (fp, &buffered) != NULL && buffered > 0) - { - size_t increment = (buffered < offset ? buffered : offset); - - freadptrinc (fp, increment); - offset -= increment; - if (offset == 0) - return 0; - total_buffered -= increment; - if (total_buffered == 0) - break; - } + { + size_t increment = (buffered < offset ? buffered : offset); + + freadptrinc (fp, increment); + offset -= increment; + if (offset == 0) + return 0; + total_buffered -= increment; + if (total_buffered == 0) + break; + } /* Read one byte. If we were reading from the ungetc buffer, this - switches the stream back to the main buffer. */ + switches the stream back to the main buffer. */ if (fgetc (fp) == EOF) - goto eof; + goto eof; offset--; if (offset == 0) - return 0; + return 0; total_buffered--; } @@ -111,16 +111,16 @@ freadseek (FILE *fp, size_t offset) else { /* FP is a non-seekable stream, possibly not even referring to a file - descriptor. Read OFFSET bytes explicitly and discard them. */ + descriptor. Read OFFSET bytes explicitly and discard them. */ char buf[4096]; do - { - size_t count = (sizeof (buf) < offset ? sizeof (buf) : offset); - if (fread (buf, 1, count, fp) < count) - goto eof; - offset -= count; - } + { + size_t count = (sizeof (buf) < offset ? sizeof (buf) : offset); + if (fread (buf, 1, count, fp) < count) + goto eof; + offset -= count; + } while (offset > 0); return 0; diff --git a/lib/frexp.c b/lib/frexp.c index 7e1f5d1ad..13c2fcdaa 100644 --- a/lib/frexp.c +++ b/lib/frexp.c @@ -85,73 +85,73 @@ FUNC (DOUBLE x, int *expptr) 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. */ + /* 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. */ + /* 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]; - } + i--; + if (x < powh[i]) + { + exponent -= (1 << i); + x *= pow2[i]; + } } /* Here 0.5 <= x < 1.0. */ } diff --git a/lib/fseeko.c b/lib/fseeko.c index af59fe9e8..8887f2469 100644 --- a/lib/fseeko.c +++ b/lib/fseeko.c @@ -50,10 +50,10 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) 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. */ + mode; but has an fseeko that requires 64-bit mode. */ FILE *tmp = fopen ("/dev/null", "r"); if (!tmp) - return -1; + return -1; fp->_flags |= __SL64; fp->_seek64 = tmp->_seek64; fclose (tmp); @@ -62,8 +62,8 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) 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_->_bf._size + : 0) && fp_ub._base == NULL) #elif defined __EMX__ /* emx+gcc */ if (fp->_ptr == fp->_buffer @@ -77,7 +77,7 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) if (((fp->__modeflags & __FLAG_WRITING) == 0 || fp->__bufpos == fp->__bufstart) && ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0 - || fp->__bufpos == fp->__bufread)) + || 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) @@ -92,20 +92,20 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) #endif { /* We get here when an fflush() call immediately preceded this one. We - know there are no buffers. - POSIX requires us to modify the file descriptor's position. - But we cannot position beyond end of file here. */ + know there are no buffers. + POSIX requires us to modify the file descriptor's position. + But we cannot position beyond end of file here. */ off_t pos = - lseek (fileno (fp), - whence == SEEK_END && offset > 0 ? 0 : offset, - whence); + lseek (fileno (fp), + whence == SEEK_END && offset > 0 ? 0 : offset, + whence); if (pos == -1) - { + { #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ - fp_->_flags &= ~__SOFF; + fp_->_flags &= ~__SOFF; #endif - return -1; - } + return -1; + } #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ fp->_flags &= ~_IO_EOF_SEEN; @@ -122,9 +122,9 @@ rpl_fseeko (FILE *fp, off_t offset, int whence) fp->__eof = 0; #endif /* If we were not requested to position beyond end of file, we're - done. */ + done. */ if (!(whence == SEEK_END && offset > 0)) - return 0; + return 0; } return fseeko (fp, offset, whence); } diff --git a/lib/fseterr.c b/lib/fseterr.c index 110716bfd..ce7e7364f 100644 --- a/lib/fseterr.c +++ b/lib/fseterr.c @@ -63,8 +63,8 @@ fseterr (FILE *fp) 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 (); + /* Whee... we botched the stream and now cannot restore it! */ + abort (); close (fd2); } errno = saved_errno; diff --git a/lib/fstatat.c b/lib/fstatat.c index 1c6c2d30b..d58e60b8a 100644 --- a/lib/fstatat.c +++ b/lib/fstatat.c @@ -48,12 +48,12 @@ rpl_fstatat (int fd, char const *file, struct stat *st, int flag) { /* Fix lstat behavior. */ if (file[len - 1] != '/' || S_ISDIR (st->st_mode)) - return 0; + return 0; if (!S_ISLNK (st->st_mode)) - { - errno = ENOTDIR; - return -1; - } + { + errno = ENOTDIR; + return -1; + } result = fstatat (fd, file, st, flag & ~AT_SYMLINK_NOFOLLOW); } /* Fix stat behavior. */ diff --git a/lib/fstrcmp.c b/lib/fstrcmp.c index 364e72b9d..18e3d150a 100644 --- a/lib/fstrcmp.c +++ b/lib/fstrcmp.c @@ -85,8 +85,8 @@ already allocated memory, store the allocated memory per thread. Free it only when the thread exits. */ -static gl_tls_key_t buffer_key; /* TLS key for a 'int *' */ -static gl_tls_key_t bufmax_key; /* TLS key for a 'size_t' */ +static gl_tls_key_t buffer_key; /* TLS key for a 'int *' */ +static gl_tls_key_t bufmax_key; /* TLS key for a 'size_t' */ static void keys_init (void) @@ -126,76 +126,76 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound) if (lower_bound > 0) { /* Compute a quick upper bound. - Each edit is an insertion or deletion of an element, hence modifies - the length of the sequence by at most 1. - Therefore, when starting from a sequence X and ending at a sequence Y, - with N edits, | yvec_length - xvec_length | <= N. (Proof by - induction over N.) - So, at the end, we will have - edit_count >= | xvec_length - yvec_length |. - and hence - result - = (xvec_length + yvec_length - edit_count) - / (xvec_length + yvec_length) - <= (xvec_length + yvec_length - | yvec_length - xvec_length |) - / (xvec_length + yvec_length) - = 2 * min (xvec_length, yvec_length) / (xvec_length + yvec_length). + Each edit is an insertion or deletion of an element, hence modifies + the length of the sequence by at most 1. + Therefore, when starting from a sequence X and ending at a sequence Y, + with N edits, | yvec_length - xvec_length | <= N. (Proof by + induction over N.) + So, at the end, we will have + edit_count >= | xvec_length - yvec_length |. + and hence + result + = (xvec_length + yvec_length - edit_count) + / (xvec_length + yvec_length) + <= (xvec_length + yvec_length - | yvec_length - xvec_length |) + / (xvec_length + yvec_length) + = 2 * min (xvec_length, yvec_length) / (xvec_length + yvec_length). */ volatile double upper_bound = - (double) (2 * MIN (xvec_length, yvec_length)) - / (xvec_length + yvec_length); + (double) (2 * MIN (xvec_length, yvec_length)) + / (xvec_length + yvec_length); if (upper_bound < lower_bound) /* Prob: 74% */ - /* Return an arbitrary value < LOWER_BOUND. */ - return 0.0; + /* Return an arbitrary value < LOWER_BOUND. */ + return 0.0; #if CHAR_BIT <= 8 /* When X and Y are both small, avoid the overhead of setting up an - array of size 256. */ + array of size 256. */ if (xvec_length + yvec_length >= 20) /* Prob: 99% */ - { - /* Compute a less quick upper bound. - Each edit is an insertion or deletion of a character, hence - modifies the occurrence count of a character by 1 and leaves the - other occurrence counts unchanged. - Therefore, when starting from a sequence X and ending at a - sequence Y, and denoting the occurrence count of C in X with - OCC (X, C), with N edits, - sum_C | OCC (X, C) - OCC (Y, C) | <= N. - (Proof by induction over N.) - So, at the end, we will have - edit_count >= sum_C | OCC (X, C) - OCC (Y, C) |, - and hence - result - = (xvec_length + yvec_length - edit_count) - / (xvec_length + yvec_length) - <= (xvec_length + yvec_length - sum_C | OCC(X,C) - OCC(Y,C) |) - / (xvec_length + yvec_length). - */ - int occ_diff[UCHAR_MAX + 1]; /* array C -> OCC(X,C) - OCC(Y,C) */ - int sum; - - /* Determine the occurrence counts in X. */ - memset (occ_diff, 0, sizeof (occ_diff)); - for (i = xvec_length - 1; i >= 0; i--) - occ_diff[(unsigned char) string1[i]]++; - /* Subtract the occurrence counts in Y. */ - for (i = yvec_length - 1; i >= 0; i--) - occ_diff[(unsigned char) string2[i]]--; - /* Sum up the absolute values. */ - sum = 0; - for (i = 0; i <= UCHAR_MAX; i++) - { - int d = occ_diff[i]; - sum += (d >= 0 ? d : -d); - } - - upper_bound = 1.0 - (double) sum / (xvec_length + yvec_length); - - if (upper_bound < lower_bound) /* Prob: 66% */ - /* Return an arbitrary value < LOWER_BOUND. */ - return 0.0; - } + { + /* Compute a less quick upper bound. + Each edit is an insertion or deletion of a character, hence + modifies the occurrence count of a character by 1 and leaves the + other occurrence counts unchanged. + Therefore, when starting from a sequence X and ending at a + sequence Y, and denoting the occurrence count of C in X with + OCC (X, C), with N edits, + sum_C | OCC (X, C) - OCC (Y, C) | <= N. + (Proof by induction over N.) + So, at the end, we will have + edit_count >= sum_C | OCC (X, C) - OCC (Y, C) |, + and hence + result + = (xvec_length + yvec_length - edit_count) + / (xvec_length + yvec_length) + <= (xvec_length + yvec_length - sum_C | OCC(X,C) - OCC(Y,C) |) + / (xvec_length + yvec_length). + */ + int occ_diff[UCHAR_MAX + 1]; /* array C -> OCC(X,C) - OCC(Y,C) */ + int sum; + + /* Determine the occurrence counts in X. */ + memset (occ_diff, 0, sizeof (occ_diff)); + for (i = xvec_length - 1; i >= 0; i--) + occ_diff[(unsigned char) string1[i]]++; + /* Subtract the occurrence counts in Y. */ + for (i = yvec_length - 1; i >= 0; i--) + occ_diff[(unsigned char) string2[i]]--; + /* Sum up the absolute values. */ + sum = 0; + for (i = 0; i <= UCHAR_MAX; i++) + { + int d = occ_diff[i]; + sum += (d >= 0 ? d : -d); + } + + upper_bound = 1.0 - (double) sum / (xvec_length + yvec_length); + + if (upper_bound < lower_bound) /* Prob: 66% */ + /* Return an arbitrary value < LOWER_BOUND. */ + return 0.0; + } #endif } @@ -223,11 +223,11 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound) /* Need more memory. */ bufmax = 2 * bufmax; if (fdiag_len > bufmax) - bufmax = fdiag_len; + bufmax = fdiag_len; /* Calling xrealloc would be a waste: buffer's contents does not need - to be preserved. */ + to be preserved. */ if (buffer != NULL) - free (buffer); + free (buffer); buffer = (int *) xnmalloc (bufmax, 2 * sizeof (int)); gl_tls_set (buffer_key, buffer); gl_tls_set (bufmax_key, (void *) (uintptr_t) bufmax); @@ -259,13 +259,13 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound) ctxt.edit_count += ctxt.edit_count_limit; /* The result is - ((number of chars in common) / (average length of the strings)). + ((number of chars in common) / (average length of the strings)). The numerator is - = xvec_length - (number of calls to NOTE_DELETE) - = yvec_length - (number of calls to NOTE_INSERT) - = 1/2 * (xvec_length + yvec_length - (number of edits)). + = xvec_length - (number of calls to NOTE_DELETE) + = yvec_length - (number of calls to NOTE_INSERT) + = 1/2 * (xvec_length + yvec_length - (number of edits)). This is admittedly biased towards finding that the strings are similar, however it does produce meaningful results. */ return ((double) (xvec_length + yvec_length - ctxt.edit_count) - / (xvec_length + yvec_length)); + / (xvec_length + yvec_length)); } diff --git a/lib/fstrcmp.h b/lib/fstrcmp.h index 807b0ae64..2888a692e 100644 --- a/lib/fstrcmp.h +++ b/lib/fstrcmp.h @@ -33,7 +33,7 @@ extern double fstrcmp (const char *s1, const char *s2); /* Like fstrcmp (S1, S2), except that if the result is < LOWER_BOUND, an arbitrary other value < LOWER_BOUND can be returned. */ extern double fstrcmp_bounded (const char *s1, const char *s2, - double lower_bound); + double lower_bound); /* A shortcut for fstrcmp. Avoids a function call. */ #define fstrcmp(s1,s2) fstrcmp_bounded (s1, s2, 0.0) diff --git a/lib/fsusage.c b/lib/fsusage.c index db0d3bc53..8901f9abd 100644 --- a/lib/fsusage.c +++ b/lib/fsusage.c @@ -23,7 +23,7 @@ #include #include -#if STAT_STATVFS /* POSIX 1003.1-2001 (and later) with XSI */ +#if STAT_STATVFS /* POSIX 1003.1-2001 (and later) with XSI */ # include #else /* Don't include backward-compatibility files unless they're needed. @@ -40,16 +40,16 @@ # if HAVE_SYS_VFS_H # include # endif -# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ +# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ # include # endif # if defined HAVE_SYS_FILSYS_H && !defined _CRAY -# include /* SVR2 */ +# include /* SVR2 */ # endif # if HAVE_SYS_STATFS_H # include # endif -# if HAVE_DUSTAT_H /* AIX PS/2 */ +# if HAVE_DUSTAT_H /* AIX PS/2 */ # include # endif # include "full-read.h" @@ -67,13 +67,13 @@ #define PROPAGATE_ALL_ONES(x) \ ((sizeof (x) < sizeof (uintmax_t) \ && (~ (x) == (sizeof (x) < sizeof (int) \ - ? - (1 << (sizeof (x) * CHAR_BIT)) \ - : 0))) \ + ? - (1 << (sizeof (x) * CHAR_BIT)) \ + : 0))) \ ? UINTMAX_MAX : (uintmax_t) (x)) /* Extract the top bit of X as an uintmax_t value. */ #define EXTRACT_TOP_BIT(x) ((x) \ - & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1))) + & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1))) /* If a value is negative, many space usage primitives store it into an integer variable by assignment, even if the variable's type is unsigned. @@ -94,7 +94,7 @@ int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) { -#if defined STAT_STATVFS /* POSIX */ +#if defined STAT_STATVFS /* POSIX */ struct statvfs fsd; @@ -103,10 +103,10 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) /* f_frsize isn't guaranteed to be supported. */ fsp->fsu_blocksize = (fsd.f_frsize - ? PROPAGATE_ALL_ONES (fsd.f_frsize) - : PROPAGATE_ALL_ONES (fsd.f_bsize)); + ? PROPAGATE_ALL_ONES (fsd.f_frsize) + : PROPAGATE_ALL_ONES (fsd.f_bsize)); -#elif defined STAT_STATFS2_FS_DATA /* Ultrix */ +#elif defined STAT_STATFS2_FS_DATA /* Ultrix */ struct fs_data fsd; @@ -121,7 +121,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); -#elif defined STAT_READ_FILSYS /* SVR2 */ +#elif defined STAT_READ_FILSYS /* SVR2 */ # ifndef SUPERBOFF # define SUPERBOFF (SUPERB * 512) # endif @@ -152,8 +152,8 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree); fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0; fsp->fsu_files = (fsd.s_isize == -1 - ? UINTMAX_MAX - : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); + ? UINTMAX_MAX + : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); #elif defined STAT_STATFS3_OSF1 @@ -165,7 +165,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); -#elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ +#elif defined STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ struct statfs fsd; @@ -189,7 +189,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) } # endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ -#elif defined STAT_STATFS2_FSIZE /* 4.4BSD */ +#elif defined STAT_STATFS2_FSIZE /* 4.4BSD */ struct statfs fsd; @@ -198,7 +198,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); -#elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ +#elif defined STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ # if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN # define f_bavail f_bfree diff --git a/lib/fsusage.h b/lib/fsusage.h index b32abe183..f079587b7 100644 --- a/lib/fsusage.h +++ b/lib/fsusage.h @@ -26,13 +26,13 @@ struct fs_usage { - uintmax_t fsu_blocksize; /* Size of a block. */ - uintmax_t fsu_blocks; /* Total blocks. */ - uintmax_t fsu_bfree; /* Free blocks available to superuser. */ - uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ - bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ - uintmax_t fsu_files; /* Total file nodes. */ - uintmax_t fsu_ffree; /* Free file nodes. */ + uintmax_t fsu_blocksize; /* Size of a block. */ + uintmax_t fsu_blocks; /* Total blocks. */ + uintmax_t fsu_bfree; /* Free blocks available to superuser. */ + uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ + bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ + uintmax_t fsu_files; /* Total file nodes. */ + uintmax_t fsu_ffree; /* Free file nodes. */ }; int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); diff --git a/lib/fsync.c b/lib/fsync.c index 4a0fe0f94..567b8e125 100644 --- a/lib/fsync.c +++ b/lib/fsync.c @@ -56,15 +56,15 @@ fsync (int fd) */ err = GetLastError (); switch (err) - { - /* eg. Trying to fsync a tty. */ - case ERROR_INVALID_HANDLE: - errno = EINVAL; - break; - - default: - errno = EIO; - } + { + /* eg. Trying to fsync a tty. */ + case ERROR_INVALID_HANDLE: + errno = EINVAL; + break; + + default: + errno = EIO; + } return -1; } diff --git a/lib/ftello.c b/lib/ftello.c index f2524084c..3eefe6001 100644 --- a/lib/ftello.c +++ b/lib/ftello.c @@ -41,10 +41,10 @@ rpl_ftello (FILE *fp) 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. */ + mode; but has an ftello that requires 64-bit mode. */ FILE *tmp = fopen ("/dev/null", "r"); if (!tmp) - return -1; + return -1; fp->_flags |= __SL64; fp->_seek64 = tmp->_seek64; fclose (tmp); diff --git a/lib/ftruncate.c b/lib/ftruncate.c index ff7d11b09..33b69d810 100644 --- a/lib/ftruncate.c +++ b/lib/ftruncate.c @@ -38,11 +38,11 @@ ftruncate (int fd, off_t length) { /* Extend file length. */ if (lseek (fd, (length - 1), SEEK_SET) < 0) - return -1; + return -1; /* Write a "0" byte. */ if (write (fd, "", 1) != 1) - return -1; + return -1; } else { @@ -52,14 +52,14 @@ ftruncate (int fd, off_t length) fl.l_whence = 0; fl.l_len = 0; fl.l_start = length; - fl.l_type = F_WRLCK; /* write lock on file space */ + fl.l_type = F_WRLCK; /* write lock on file space */ /* This relies on the *undocumented* F_FREESP argument to fcntl, - which truncates the file so that it ends at the position - indicated by fl.l_start. Will minor miracles never cease? */ + which truncates the file so that it ends at the position + indicated by fl.l_start. Will minor miracles never cease? */ if (fcntl (fd, F_FREESP, &fl) < 0) - return -1; + return -1; } return 0; diff --git a/lib/fts-cycle.c b/lib/fts-cycle.c index 5f81610a3..e96f80468 100644 --- a/lib/fts-cycle.c +++ b/lib/fts-cycle.c @@ -53,15 +53,15 @@ setup_dir (FTS *fts) { enum { HT_INITIAL_SIZE = 31 }; fts->fts_cycle.ht = hash_initialize (HT_INITIAL_SIZE, NULL, AD_hash, - AD_compare, free); + AD_compare, free); if (! fts->fts_cycle.ht) - return false; + return false; } else { fts->fts_cycle.state = malloc (sizeof *fts->fts_cycle.state); if (! fts->fts_cycle.state) - return false; + return false; cycle_check_init (fts->fts_cycle.state); } @@ -80,40 +80,40 @@ enter_dir (FTS *fts, FTSENT *ent) struct Active_dir *ad_from_table; if (!ad) - return false; + return false; ad->dev = st->st_dev; ad->ino = st->st_ino; ad->fts_ent = ent; /* See if we've already encountered this directory. - This can happen when following symlinks as well as - with a corrupted directory hierarchy. */ + This can happen when following symlinks as well as + with a corrupted directory hierarchy. */ ad_from_table = hash_insert (fts->fts_cycle.ht, ad); if (ad_from_table != ad) - { - free (ad); - if (!ad_from_table) - return false; - - /* There was an entry with matching dev/inode already in the table. - Record the fact that we've found a cycle. */ - ent->fts_cycle = ad_from_table->fts_ent; - ent->fts_info = FTS_DC; - } + { + free (ad); + if (!ad_from_table) + return false; + + /* There was an entry with matching dev/inode already in the table. + Record the fact that we've found a cycle. */ + ent->fts_cycle = ad_from_table->fts_ent; + ent->fts_info = FTS_DC; + } } else { if (cycle_check (fts->fts_cycle.state, ent->fts_statp)) - { - /* FIXME: setting fts_cycle like this isn't proper. - To do what the documentation requires, we'd have to - go around the cycle again and find the right entry. - But no callers in coreutils use the fts_cycle member. */ - ent->fts_cycle = ent; - ent->fts_info = FTS_DC; - } + { + /* FIXME: setting fts_cycle like this isn't proper. + To do what the documentation requires, we'd have to + go around the cycle again and find the right entry. + But no callers in coreutils use the fts_cycle member. */ + ent->fts_cycle = ent; + ent->fts_info = FTS_DC; + } } return true; @@ -133,15 +133,15 @@ leave_dir (FTS *fts, FTSENT *ent) obj.ino = st->st_ino; found = hash_delete (fts->fts_cycle.ht, &obj); if (!found) - abort (); + abort (); free (found); } else { FTSENT *parent = ent->fts_parent; if (parent != NULL && 0 <= parent->fts_level) - CYCLE_CHECK_REFLECT_CHDIR_UP (fts->fts_cycle.state, - *(parent->fts_statp), *st); + CYCLE_CHECK_REFLECT_CHDIR_UP (fts->fts_cycle.state, + *(parent->fts_statp), *st); } } @@ -153,7 +153,7 @@ free_dir (FTS *sp) if (sp->fts_options & (FTS_TIGHT_CYCLE_CHECK | FTS_LOGICAL)) { if (sp->fts_cycle.ht) - hash_free (sp->fts_cycle.ht); + hash_free (sp->fts_cycle.ht); } else free (sp->fts_cycle.state); diff --git a/lib/fts.c b/lib/fts.c index 39922b6a4..9329ef6c6 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -17,7 +17,7 @@ /*- * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,7 +47,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; +static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; #endif /* LIBC_SCCS and not lint */ #include "fts_.h" @@ -184,23 +184,23 @@ enum Fts_stat #ifdef NDEBUG # define fts_assert(expr) ((void) 0) #else -# define fts_assert(expr) \ - do \ - { \ - if (!(expr)) \ - abort (); \ - } \ +# define fts_assert(expr) \ + do \ + { \ + if (!(expr)) \ + abort (); \ + } \ while (false) #endif -static FTSENT *fts_alloc (FTS *, const char *, size_t) internal_function; -static FTSENT *fts_build (FTS *, int) internal_function; -static void fts_lfree (FTSENT *) internal_function; -static void fts_load (FTS *, FTSENT *) internal_function; -static size_t fts_maxarglen (char * const *) internal_function; -static void fts_padjust (FTS *, FTSENT *) internal_function; -static bool fts_palloc (FTS *, size_t) internal_function; -static FTSENT *fts_sort (FTS *, FTSENT *, size_t) internal_function; +static FTSENT *fts_alloc (FTS *, const char *, size_t) internal_function; +static FTSENT *fts_build (FTS *, int) internal_function; +static void fts_lfree (FTSENT *) internal_function; +static void fts_load (FTS *, FTSENT *) internal_function; +static size_t fts_maxarglen (char * const *) internal_function; +static void fts_padjust (FTS *, FTSENT *) internal_function; +static bool fts_palloc (FTS *, size_t) internal_function; +static FTSENT *fts_sort (FTS *, FTSENT *, size_t) internal_function; static unsigned short int fts_stat (FTS *, FTSENT *, bool) internal_function; static int fts_safe_changedir (FTS *, FTSENT *, int, const char *) internal_function; @@ -222,31 +222,31 @@ static void free_dir (FTS *fts) {} # define SIZE_MAX ((size_t) -1) #endif -#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) -#define STREQ(a, b) (strcmp ((a), (b)) == 0) +#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) +#define STREQ(a, b) (strcmp ((a), (b)) == 0) -#define CLR(opt) (sp->fts_options &= ~(opt)) -#define ISSET(opt) (sp->fts_options & (opt)) -#define SET(opt) (sp->fts_options |= (opt)) +#define CLR(opt) (sp->fts_options &= ~(opt)) +#define ISSET(opt) (sp->fts_options & (opt)) +#define SET(opt) (sp->fts_options |= (opt)) /* FIXME: make this a function */ -#define RESTORE_INITIAL_CWD(sp) \ - (fd_ring_clear (&((sp)->fts_fd_ring)), \ +#define RESTORE_INITIAL_CWD(sp) \ + (fd_ring_clear (&((sp)->fts_fd_ring)), \ FCHDIR ((sp), (ISSET (FTS_CWDFD) ? AT_FDCWD : (sp)->fts_rfd))) /* FIXME: FTS_NOCHDIR is now misnamed. Call it FTS_USE_FULL_RELATIVE_FILE_NAMES instead. */ -#define FCHDIR(sp, fd) \ - (!ISSET(FTS_NOCHDIR) && (ISSET(FTS_CWDFD) \ - ? (cwd_advance_fd ((sp), (fd), true), 0) \ - : fchdir (fd))) +#define FCHDIR(sp, fd) \ + (!ISSET(FTS_NOCHDIR) && (ISSET(FTS_CWDFD) \ + ? (cwd_advance_fd ((sp), (fd), true), 0) \ + : fchdir (fd))) /* fts_build flags */ /* FIXME: make this an enum */ -#define BCHILD 1 /* fts_children */ -#define BNAMES 2 /* fts_children, names only */ -#define BREAD 3 /* fts_read */ +#define BCHILD 1 /* fts_children */ +#define BNAMES 2 /* fts_children, names only */ +#define BREAD 3 /* fts_read */ #if FTS_DEBUG # include @@ -261,13 +261,13 @@ bool fts_debug = false; # define fd_ring_print(a, b, c) #endif -#define LEAVE_DIR(Fts, Ent, Tag) \ - do \ - { \ - Dprintf ((" %s-leaving: %s\n", Tag, (Ent)->fts_path)); \ - leave_dir (Fts, Ent); \ - fd_ring_check (Fts); \ - } \ +#define LEAVE_DIR(Fts, Ent, Tag) \ + do \ + { \ + Dprintf ((" %s-leaving: %s\n", Tag, (Ent)->fts_path)); \ + leave_dir (Fts, Ent); \ + fd_ring_check (Fts); \ + } \ while (false) static void @@ -277,7 +277,7 @@ fd_ring_clear (I_ring *fd_ring) { int fd = i_ring_pop (fd_ring); if (0 <= fd) - close (fd); + close (fd); } } @@ -289,8 +289,8 @@ fts_set_stat_required (FTSENT *p, bool required) { fts_assert (p->fts_info == FTS_NSOK); p->fts_statp->st_size = (required - ? FTS_STAT_REQUIRED - : FTS_NO_STAT_REQUIRED); + ? FTS_STAT_REQUIRED + : FTS_NO_STAT_REQUIRED); } /* file-descriptor-relative opendir. */ @@ -300,7 +300,7 @@ internal_function opendirat (int fd, char const *dir) { int new_fd = openat (fd, dir, - O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK); + O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK); DIR *dirp; if (new_fd < 0) @@ -331,16 +331,16 @@ cwd_advance_fd (FTS *sp, int fd, bool chdir_down_one) if (chdir_down_one) { /* Push "old" onto the ring. - If the displaced file descriptor is non-negative, close it. */ + If the displaced file descriptor is non-negative, close it. */ int prev_fd_in_slot = i_ring_push (&sp->fts_fd_ring, old); fd_ring_print (sp, stderr, "post-push"); if (0 <= prev_fd_in_slot) - close (prev_fd_in_slot); /* ignore any close failure */ + close (prev_fd_in_slot); /* ignore any close failure */ } else if ( ! ISSET (FTS_NOCHDIR)) { if (0 <= old) - close (old); /* ignore any close failure */ + close (old); /* ignore any close failure */ } sp->fts_cwd_fd = fd; @@ -355,7 +355,7 @@ internal_function diropen (FTS const *sp, char const *dir) { int open_flags = (O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK - | (ISSET (FTS_PHYSICAL) ? O_NOFOLLOW : 0)); + | (ISSET (FTS_PHYSICAL) ? O_NOFOLLOW : 0)); int fd = (ISSET (FTS_CWDFD) ? openat (sp->fts_cwd_fd, dir, open_flags) @@ -367,270 +367,270 @@ diropen (FTS const *sp, char const *dir) FTS * fts_open (char * const *argv, - register int options, - int (*compar) (FTSENT const **, FTSENT const **)) + register int options, + int (*compar) (FTSENT const **, FTSENT const **)) { - register FTS *sp; - register FTSENT *p, *root; - register size_t nitems; - FTSENT *parent = NULL; - FTSENT *tmp = NULL; /* pacify gcc */ - bool defer_stat; - - /* Options check. */ - if (options & ~FTS_OPTIONMASK) { - __set_errno (EINVAL); - return (NULL); - } - if ((options & FTS_NOCHDIR) && (options & FTS_CWDFD)) { - __set_errno (EINVAL); - return (NULL); - } - if ( ! (options & (FTS_LOGICAL | FTS_PHYSICAL))) { - __set_errno (EINVAL); - return (NULL); - } - - /* Allocate/initialize the stream */ - if ((sp = malloc(sizeof(FTS))) == NULL) - return (NULL); - memset(sp, 0, sizeof(FTS)); - sp->fts_compar = compar; - sp->fts_options = options; - - /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ - if (ISSET(FTS_LOGICAL)) { - SET(FTS_NOCHDIR); - CLR(FTS_CWDFD); - } - - /* Initialize fts_cwd_fd. */ - sp->fts_cwd_fd = AT_FDCWD; - if ( ISSET(FTS_CWDFD) && ! HAVE_OPENAT_SUPPORT) - { - /* While it isn't technically necessary to open "." this - early, doing it here saves us the trouble of ensuring - later (where it'd be messier) that "." can in fact - be opened. If not, revert to FTS_NOCHDIR mode. */ - int fd = open (".", O_RDONLY); - if (fd < 0) - { - /* Even if `.' is unreadable, don't revert to FTS_NOCHDIR mode - on systems like Linux+PROC_FS, where our openat emulation - is good enough. Note: on a system that emulates - openat via /proc, this technique can still fail, but - only in extreme conditions, e.g., when the working - directory cannot be saved (i.e. save_cwd fails) -- - and that happens on Linux only when "." is unreadable - and the CWD would be longer than PATH_MAX. - FIXME: once Linux kernel openat support is well established, - replace the above open call and this entire if/else block - with the body of the if-block below. */ - if ( openat_needs_fchdir ()) - { - SET(FTS_NOCHDIR); - CLR(FTS_CWDFD); - } - } - else - { - close (fd); - } - } - - /* - * Start out with 1K of file name space, and enough, in any case, - * to hold the user's file names. - */ + register FTS *sp; + register FTSENT *p, *root; + register size_t nitems; + FTSENT *parent = NULL; + FTSENT *tmp = NULL; /* pacify gcc */ + bool defer_stat; + + /* Options check. */ + if (options & ~FTS_OPTIONMASK) { + __set_errno (EINVAL); + return (NULL); + } + if ((options & FTS_NOCHDIR) && (options & FTS_CWDFD)) { + __set_errno (EINVAL); + return (NULL); + } + if ( ! (options & (FTS_LOGICAL | FTS_PHYSICAL))) { + __set_errno (EINVAL); + return (NULL); + } + + /* Allocate/initialize the stream */ + if ((sp = malloc(sizeof(FTS))) == NULL) + return (NULL); + memset(sp, 0, sizeof(FTS)); + sp->fts_compar = compar; + sp->fts_options = options; + + /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ + if (ISSET(FTS_LOGICAL)) { + SET(FTS_NOCHDIR); + CLR(FTS_CWDFD); + } + + /* Initialize fts_cwd_fd. */ + sp->fts_cwd_fd = AT_FDCWD; + if ( ISSET(FTS_CWDFD) && ! HAVE_OPENAT_SUPPORT) + { + /* While it isn't technically necessary to open "." this + early, doing it here saves us the trouble of ensuring + later (where it'd be messier) that "." can in fact + be opened. If not, revert to FTS_NOCHDIR mode. */ + int fd = open (".", O_RDONLY); + if (fd < 0) + { + /* Even if `.' is unreadable, don't revert to FTS_NOCHDIR mode + on systems like Linux+PROC_FS, where our openat emulation + is good enough. Note: on a system that emulates + openat via /proc, this technique can still fail, but + only in extreme conditions, e.g., when the working + directory cannot be saved (i.e. save_cwd fails) -- + and that happens on Linux only when "." is unreadable + and the CWD would be longer than PATH_MAX. + FIXME: once Linux kernel openat support is well established, + replace the above open call and this entire if/else block + with the body of the if-block below. */ + if ( openat_needs_fchdir ()) + { + SET(FTS_NOCHDIR); + CLR(FTS_CWDFD); + } + } + else + { + close (fd); + } + } + + /* + * Start out with 1K of file name space, and enough, in any case, + * to hold the user's file names. + */ #ifndef MAXPATHLEN # define MAXPATHLEN 1024 #endif - { - size_t maxarglen = fts_maxarglen(argv); - if (! fts_palloc(sp, MAX(maxarglen, MAXPATHLEN))) - goto mem1; - } - - /* Allocate/initialize root's parent. */ - if (*argv != NULL) { - if ((parent = fts_alloc(sp, "", 0)) == NULL) - goto mem2; - parent->fts_level = FTS_ROOTPARENTLEVEL; - } - - /* The classic fts implementation would call fts_stat with - a new entry for each iteration of the loop below. - If the comparison function is not specified or if the - FTS_DEFER_STAT option is in effect, don't stat any entry - in this loop. This is an attempt to minimize the interval - between the initial stat/lstat/fstatat and the point at which - a directory argument is first opened. This matters for any - directory command line argument that resides on a file system - without genuine i-nodes. If you specify FTS_DEFER_STAT along - with a comparison function, that function must not access any - data via the fts_statp pointer. */ - defer_stat = (compar == NULL || ISSET(FTS_DEFER_STAT)); - - /* Allocate/initialize root(s). */ - for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) { - /* *Do* allow zero-length file names. */ - size_t len = strlen(*argv); - if ((p = fts_alloc(sp, *argv, len)) == NULL) - goto mem3; - p->fts_level = FTS_ROOTLEVEL; - p->fts_parent = parent; - p->fts_accpath = p->fts_name; - /* Even when defer_stat is true, be sure to stat the first - command line argument, since fts_read (at least with - FTS_XDEV) requires that. */ - if (defer_stat && root != NULL) { - p->fts_info = FTS_NSOK; - fts_set_stat_required(p, true); - } else { - p->fts_info = fts_stat(sp, p, false); - } - - /* - * If comparison routine supplied, traverse in sorted - * order; otherwise traverse in the order specified. - */ - if (compar) { - p->fts_link = root; - root = p; - } else { - p->fts_link = NULL; - if (root == NULL) - tmp = root = p; - else { - tmp->fts_link = p; - tmp = p; - } - } - } - if (compar && nitems > 1) - root = fts_sort(sp, root, nitems); - - /* - * Allocate a dummy pointer and make fts_read think that we've just - * finished the node before the root(s); set p->fts_info to FTS_INIT - * so that everything about the "current" node is ignored. - */ - if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) - goto mem3; - sp->fts_cur->fts_link = root; - sp->fts_cur->fts_info = FTS_INIT; - if (! setup_dir (sp)) - goto mem3; - - /* - * If using chdir(2), grab a file descriptor pointing to dot to ensure - * that we can get back here; this could be avoided for some file names, - * but almost certainly not worth the effort. Slashes, symbolic links, - * and ".." are all fairly nasty problems. Note, if we can't get the - * descriptor we run anyway, just more slowly. - */ - if (!ISSET(FTS_NOCHDIR) && !ISSET(FTS_CWDFD) - && (sp->fts_rfd = diropen (sp, ".")) < 0) - SET(FTS_NOCHDIR); - - i_ring_init (&sp->fts_fd_ring, -1); - return (sp); - -mem3: fts_lfree(root); - free(parent); -mem2: free(sp->fts_path); -mem1: free(sp); - return (NULL); + { + size_t maxarglen = fts_maxarglen(argv); + if (! fts_palloc(sp, MAX(maxarglen, MAXPATHLEN))) + goto mem1; + } + + /* Allocate/initialize root's parent. */ + if (*argv != NULL) { + if ((parent = fts_alloc(sp, "", 0)) == NULL) + goto mem2; + parent->fts_level = FTS_ROOTPARENTLEVEL; + } + + /* The classic fts implementation would call fts_stat with + a new entry for each iteration of the loop below. + If the comparison function is not specified or if the + FTS_DEFER_STAT option is in effect, don't stat any entry + in this loop. This is an attempt to minimize the interval + between the initial stat/lstat/fstatat and the point at which + a directory argument is first opened. This matters for any + directory command line argument that resides on a file system + without genuine i-nodes. If you specify FTS_DEFER_STAT along + with a comparison function, that function must not access any + data via the fts_statp pointer. */ + defer_stat = (compar == NULL || ISSET(FTS_DEFER_STAT)); + + /* Allocate/initialize root(s). */ + for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) { + /* *Do* allow zero-length file names. */ + size_t len = strlen(*argv); + if ((p = fts_alloc(sp, *argv, len)) == NULL) + goto mem3; + p->fts_level = FTS_ROOTLEVEL; + p->fts_parent = parent; + p->fts_accpath = p->fts_name; + /* Even when defer_stat is true, be sure to stat the first + command line argument, since fts_read (at least with + FTS_XDEV) requires that. */ + if (defer_stat && root != NULL) { + p->fts_info = FTS_NSOK; + fts_set_stat_required(p, true); + } else { + p->fts_info = fts_stat(sp, p, false); + } + + /* + * If comparison routine supplied, traverse in sorted + * order; otherwise traverse in the order specified. + */ + if (compar) { + p->fts_link = root; + root = p; + } else { + p->fts_link = NULL; + if (root == NULL) + tmp = root = p; + else { + tmp->fts_link = p; + tmp = p; + } + } + } + if (compar && nitems > 1) + root = fts_sort(sp, root, nitems); + + /* + * Allocate a dummy pointer and make fts_read think that we've just + * finished the node before the root(s); set p->fts_info to FTS_INIT + * so that everything about the "current" node is ignored. + */ + if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) + goto mem3; + sp->fts_cur->fts_link = root; + sp->fts_cur->fts_info = FTS_INIT; + if (! setup_dir (sp)) + goto mem3; + + /* + * If using chdir(2), grab a file descriptor pointing to dot to ensure + * that we can get back here; this could be avoided for some file names, + * but almost certainly not worth the effort. Slashes, symbolic links, + * and ".." are all fairly nasty problems. Note, if we can't get the + * descriptor we run anyway, just more slowly. + */ + if (!ISSET(FTS_NOCHDIR) && !ISSET(FTS_CWDFD) + && (sp->fts_rfd = diropen (sp, ".")) < 0) + SET(FTS_NOCHDIR); + + i_ring_init (&sp->fts_fd_ring, -1); + return (sp); + +mem3: fts_lfree(root); + free(parent); +mem2: free(sp->fts_path); +mem1: free(sp); + return (NULL); } static void internal_function fts_load (FTS *sp, register FTSENT *p) { - register size_t len; - register char *cp; - - /* - * Load the stream structure for the next traversal. Since we don't - * actually enter the directory until after the preorder visit, set - * the fts_accpath field specially so the chdir gets done to the right - * place and the user can access the first node. From fts_open it's - * known that the file name will fit. - */ - len = p->fts_pathlen = p->fts_namelen; - memmove(sp->fts_path, p->fts_name, len + 1); - if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { - len = strlen(++cp); - memmove(p->fts_name, cp, len + 1); - p->fts_namelen = len; - } - p->fts_accpath = p->fts_path = sp->fts_path; + register size_t len; + register char *cp; + + /* + * Load the stream structure for the next traversal. Since we don't + * actually enter the directory until after the preorder visit, set + * the fts_accpath field specially so the chdir gets done to the right + * place and the user can access the first node. From fts_open it's + * known that the file name will fit. + */ + len = p->fts_pathlen = p->fts_namelen; + memmove(sp->fts_path, p->fts_name, len + 1); + if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { + len = strlen(++cp); + memmove(p->fts_name, cp, len + 1); + p->fts_namelen = len; + } + p->fts_accpath = p->fts_path = sp->fts_path; } int fts_close (FTS *sp) { - register FTSENT *freep, *p; - int saved_errno = 0; - - /* - * This still works if we haven't read anything -- the dummy structure - * points to the root list, so we step through to the end of the root - * list which has a valid parent pointer. - */ - if (sp->fts_cur) { - for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { - freep = p; - p = p->fts_link != NULL ? p->fts_link : p->fts_parent; - free(freep); - } - free(p); - } - - /* Free up child linked list, sort array, file name buffer. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - free(sp->fts_array); - free(sp->fts_path); - - if (ISSET(FTS_CWDFD)) - { - if (0 <= sp->fts_cwd_fd) - if (close (sp->fts_cwd_fd)) - saved_errno = errno; - } - else if (!ISSET(FTS_NOCHDIR)) - { - /* Return to original directory, save errno if necessary. */ - if (fchdir(sp->fts_rfd)) - saved_errno = errno; - - /* If close fails, record errno only if saved_errno is zero, - so that we report the probably-more-meaningful fchdir errno. */ - if (close (sp->fts_rfd)) - if (saved_errno == 0) - saved_errno = errno; - } - - fd_ring_clear (&sp->fts_fd_ring); + register FTSENT *freep, *p; + int saved_errno = 0; + + /* + * This still works if we haven't read anything -- the dummy structure + * points to the root list, so we step through to the end of the root + * list which has a valid parent pointer. + */ + if (sp->fts_cur) { + for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { + freep = p; + p = p->fts_link != NULL ? p->fts_link : p->fts_parent; + free(freep); + } + free(p); + } + + /* Free up child linked list, sort array, file name buffer. */ + if (sp->fts_child) + fts_lfree(sp->fts_child); + free(sp->fts_array); + free(sp->fts_path); + + if (ISSET(FTS_CWDFD)) + { + if (0 <= sp->fts_cwd_fd) + if (close (sp->fts_cwd_fd)) + saved_errno = errno; + } + else if (!ISSET(FTS_NOCHDIR)) + { + /* Return to original directory, save errno if necessary. */ + if (fchdir(sp->fts_rfd)) + saved_errno = errno; + + /* If close fails, record errno only if saved_errno is zero, + so that we report the probably-more-meaningful fchdir errno. */ + if (close (sp->fts_rfd)) + if (saved_errno == 0) + saved_errno = errno; + } + + fd_ring_clear (&sp->fts_fd_ring); #if GNULIB_FTS - if (sp->fts_leaf_optimization_works_ht) - hash_free (sp->fts_leaf_optimization_works_ht); + if (sp->fts_leaf_optimization_works_ht) + hash_free (sp->fts_leaf_optimization_works_ht); #endif - free_dir (sp); + free_dir (sp); - /* Free up the stream pointer. */ - free(sp); + /* Free up the stream pointer. */ + free(sp); - /* Set errno and return. */ - if (saved_errno) { - __set_errno (saved_errno); - return (-1); - } + /* Set errno and return. */ + if (saved_errno) { + __set_errno (saved_errno); + return (-1); + } - return (0); + return (0); } #if defined __linux__ \ @@ -669,7 +669,7 @@ dirent_inode_sort_may_be_useful (int dir_fd) case S_MAGIC_TMPFS: case S_MAGIC_NFS: /* On a file system of any of these types, sorting - is unnecessary, and hence wasteful. */ + is unnecessary, and hence wasteful. */ return false; default: @@ -695,15 +695,15 @@ leaf_optimization_applies (int dir_fd) switch (fs_buf.f_type) { /* List here the file system types that lack useable dirent.d_type - info, yet for which the optimization does apply. */ + info, yet for which the optimization does apply. */ case S_MAGIC_REISERFS: return true; case S_MAGIC_PROC: /* Explicitly listing this or any other file system type for which - the optimization is not applicable is not necessary, but we leave - it here to document the risk. Per http://bugs.debian.org/143111, - /proc may have bogus stat.st_nlink values. */ + the optimization is not applicable is not necessary, but we leave + it here to document the risk. Per http://bugs.debian.org/143111, + /proc may have bogus stat.st_nlink values. */ /* fall through */ default: return false; @@ -768,10 +768,10 @@ link_count_optimize_ok (FTSENT const *p) if (h == NULL) { h = sp->fts_leaf_optimization_works_ht - = hash_initialize (LCO_HT_INITIAL_SIZE, NULL, LCO_hash, - LCO_compare, free); + = hash_initialize (LCO_HT_INITIAL_SIZE, NULL, LCO_hash, + LCO_compare, free); if (h == NULL) - return false; + return false; } tmp.st_dev = p->fts_statp->st_dev; ent = hash_lookup (h, &tmp); @@ -805,255 +805,255 @@ link_count_optimize_ok (FTSENT const *p) * Special case of "/" at the end of the file name so that slashes aren't * appended which would cause file names to be written as "....//foo". */ -#define NAPPEND(p) \ - (p->fts_path[p->fts_pathlen - 1] == '/' \ - ? p->fts_pathlen - 1 : p->fts_pathlen) +#define NAPPEND(p) \ + (p->fts_path[p->fts_pathlen - 1] == '/' \ + ? p->fts_pathlen - 1 : p->fts_pathlen) FTSENT * fts_read (register FTS *sp) { - register FTSENT *p, *tmp; - register unsigned short int instr; - register char *t; - - /* If finished or unrecoverable error, return NULL. */ - if (sp->fts_cur == NULL || ISSET(FTS_STOP)) - return (NULL); - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* Save and zero out user instructions. */ - instr = p->fts_instr; - p->fts_instr = FTS_NOINSTR; - - /* Any type of file may be re-visited; re-stat and re-turn. */ - if (instr == FTS_AGAIN) { - p->fts_info = fts_stat(sp, p, false); - return (p); - } - Dprintf (("fts_read: p=%s\n", - p->fts_info == FTS_INIT ? "" : p->fts_path)); - - /* - * Following a symlink -- SLNONE test allows application to see - * SLNONE and recover. If indirecting through a symlink, have - * keep a pointer to current location. If unable to get that - * pointer, follow fails. - */ - if (instr == FTS_FOLLOW && - (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { - p->fts_info = fts_stat(sp, p, true); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = diropen (sp, ".")) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - goto check_for_dir; - } - - /* Directory in pre-order. */ - if (p->fts_info == FTS_D) { - /* If skipped or crossed mount point, do post-order visit. */ - if (instr == FTS_SKIP || - (ISSET(FTS_XDEV) && p->fts_statp->st_dev != sp->fts_dev)) { - if (p->fts_flags & FTS_SYMFOLLOW) - (void)close(p->fts_symfd); - if (sp->fts_child) { - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - p->fts_info = FTS_DP; - LEAVE_DIR (sp, p, "1"); - return (p); - } - - /* Rebuild if only read the names and now traversing. */ - if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) { - CLR(FTS_NAMEONLY); - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - - /* - * Cd to the subdirectory. - * - * If have already read and now fail to chdir, whack the list - * to make the names come out right, and set the parent errno - * so the application will eventually get an error condition. - * Set the FTS_DONTCHDIR flag so that when we logically change - * directories back to the parent we don't do a chdir. - * - * If haven't read do so. If the read fails, fts_build sets - * FTS_STOP or the fts_info field of the node. - */ - if (sp->fts_child != NULL) { - if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { - p->fts_errno = errno; - p->fts_flags |= FTS_DONTCHDIR; - for (p = sp->fts_child; p != NULL; - p = p->fts_link) - p->fts_accpath = - p->fts_parent->fts_accpath; - } - } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { - if (ISSET(FTS_STOP)) - return (NULL); - /* If fts_build's call to fts_safe_changedir failed - because it was not able to fchdir into a - subdirectory, tell the caller. */ - if (p->fts_errno && p->fts_info != FTS_DNR) - p->fts_info = FTS_ERR; - LEAVE_DIR (sp, p, "2"); - return (p); - } - p = sp->fts_child; - sp->fts_child = NULL; - goto name; - } - - /* Move to the next node on this level. */ -next: tmp = p; - if ((p = p->fts_link) != NULL) { - sp->fts_cur = p; - free(tmp); - - /* - * If reached the top, return to the original directory (or - * the root of the tree), and load the file names for the next - * root. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (RESTORE_INITIAL_CWD(sp)) { - SET(FTS_STOP); - return (NULL); - } - free_dir(sp); - fts_load(sp, p); - setup_dir(sp); - goto check_for_dir; - } - - /* - * User may have called fts_set on the node. If skipped, - * ignore. If followed, get a file descriptor so we can - * get back if necessary. - */ - if (p->fts_instr == FTS_SKIP) - goto next; - if (p->fts_instr == FTS_FOLLOW) { - p->fts_info = fts_stat(sp, p, true); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = diropen (sp, ".")) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - p->fts_instr = FTS_NOINSTR; - } - -name: t = sp->fts_path + NAPPEND(p->fts_parent); - *t++ = '/'; - memmove(t, p->fts_name, p->fts_namelen + 1); + register FTSENT *p, *tmp; + register unsigned short int instr; + register char *t; + + /* If finished or unrecoverable error, return NULL. */ + if (sp->fts_cur == NULL || ISSET(FTS_STOP)) + return (NULL); + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* Save and zero out user instructions. */ + instr = p->fts_instr; + p->fts_instr = FTS_NOINSTR; + + /* Any type of file may be re-visited; re-stat and re-turn. */ + if (instr == FTS_AGAIN) { + p->fts_info = fts_stat(sp, p, false); + return (p); + } + Dprintf (("fts_read: p=%s\n", + p->fts_info == FTS_INIT ? "" : p->fts_path)); + + /* + * Following a symlink -- SLNONE test allows application to see + * SLNONE and recover. If indirecting through a symlink, have + * keep a pointer to current location. If unable to get that + * pointer, follow fails. + */ + if (instr == FTS_FOLLOW && + (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { + p->fts_info = fts_stat(sp, p, true); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { + if ((p->fts_symfd = diropen (sp, ".")) < 0) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + } + goto check_for_dir; + } + + /* Directory in pre-order. */ + if (p->fts_info == FTS_D) { + /* If skipped or crossed mount point, do post-order visit. */ + if (instr == FTS_SKIP || + (ISSET(FTS_XDEV) && p->fts_statp->st_dev != sp->fts_dev)) { + if (p->fts_flags & FTS_SYMFOLLOW) + (void)close(p->fts_symfd); + if (sp->fts_child) { + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + p->fts_info = FTS_DP; + LEAVE_DIR (sp, p, "1"); + return (p); + } + + /* Rebuild if only read the names and now traversing. */ + if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) { + CLR(FTS_NAMEONLY); + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + + /* + * Cd to the subdirectory. + * + * If have already read and now fail to chdir, whack the list + * to make the names come out right, and set the parent errno + * so the application will eventually get an error condition. + * Set the FTS_DONTCHDIR flag so that when we logically change + * directories back to the parent we don't do a chdir. + * + * If haven't read do so. If the read fails, fts_build sets + * FTS_STOP or the fts_info field of the node. + */ + if (sp->fts_child != NULL) { + if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { + p->fts_errno = errno; + p->fts_flags |= FTS_DONTCHDIR; + for (p = sp->fts_child; p != NULL; + p = p->fts_link) + p->fts_accpath = + p->fts_parent->fts_accpath; + } + } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { + if (ISSET(FTS_STOP)) + return (NULL); + /* If fts_build's call to fts_safe_changedir failed + because it was not able to fchdir into a + subdirectory, tell the caller. */ + if (p->fts_errno && p->fts_info != FTS_DNR) + p->fts_info = FTS_ERR; + LEAVE_DIR (sp, p, "2"); + return (p); + } + p = sp->fts_child; + sp->fts_child = NULL; + goto name; + } + + /* Move to the next node on this level. */ +next: tmp = p; + if ((p = p->fts_link) != NULL) { + sp->fts_cur = p; + free(tmp); + + /* + * If reached the top, return to the original directory (or + * the root of the tree), and load the file names for the next + * root. + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (RESTORE_INITIAL_CWD(sp)) { + SET(FTS_STOP); + return (NULL); + } + free_dir(sp); + fts_load(sp, p); + setup_dir(sp); + goto check_for_dir; + } + + /* + * User may have called fts_set on the node. If skipped, + * ignore. If followed, get a file descriptor so we can + * get back if necessary. + */ + if (p->fts_instr == FTS_SKIP) + goto next; + if (p->fts_instr == FTS_FOLLOW) { + p->fts_info = fts_stat(sp, p, true); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { + if ((p->fts_symfd = diropen (sp, ".")) < 0) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + } + p->fts_instr = FTS_NOINSTR; + } + +name: t = sp->fts_path + NAPPEND(p->fts_parent); + *t++ = '/'; + memmove(t, p->fts_name, p->fts_namelen + 1); check_for_dir: - sp->fts_cur = p; - if (p->fts_info == FTS_NSOK) - { - if (p->fts_statp->st_size == FTS_STAT_REQUIRED) - { - FTSENT *parent = p->fts_parent; - if (FTS_ROOTLEVEL < p->fts_level - /* ->fts_n_dirs_remaining is not valid - for command-line-specified names. */ - && parent->fts_n_dirs_remaining == 0 - && ISSET(FTS_NOSTAT) - && ISSET(FTS_PHYSICAL) - && link_count_optimize_ok (parent)) - { - /* nothing more needed */ - } - else - { - p->fts_info = fts_stat(sp, p, false); - if (S_ISDIR(p->fts_statp->st_mode) - && p->fts_level != FTS_ROOTLEVEL - && parent->fts_n_dirs_remaining) - parent->fts_n_dirs_remaining--; - } - } - else - fts_assert (p->fts_statp->st_size == FTS_NO_STAT_REQUIRED); - } - - if (p->fts_info == FTS_D) - { - /* Now that P->fts_statp is guaranteed to be valid, - if this is a command-line directory, record its - device number, to be used for FTS_XDEV. */ - if (p->fts_level == FTS_ROOTLEVEL) - sp->fts_dev = p->fts_statp->st_dev; - Dprintf ((" entering: %s\n", p->fts_path)); - if (! enter_dir (sp, p)) - { - __set_errno (ENOMEM); - return NULL; - } - } - return p; - } - - /* Move up to the parent node. */ - p = tmp->fts_parent; - sp->fts_cur = p; - free(tmp); - - if (p->fts_level == FTS_ROOTPARENTLEVEL) { - /* - * Done; free everything up and set errno to 0 so the user - * can distinguish between error and EOF. - */ - free(p); - __set_errno (0); - return (sp->fts_cur = NULL); - } - - fts_assert (p->fts_info != FTS_NSOK); - - /* NUL terminate the file name. */ - sp->fts_path[p->fts_pathlen] = '\0'; - - /* - * Return to the parent directory. If at a root node, restore - * the initial working directory. If we came through a symlink, - * go back through the file descriptor. Otherwise, move up - * one level, via "..". - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (RESTORE_INITIAL_CWD(sp)) { - p->fts_errno = errno; - SET(FTS_STOP); - } - } else if (p->fts_flags & FTS_SYMFOLLOW) { - if (FCHDIR(sp, p->fts_symfd)) { - int saved_errno = errno; - (void)close(p->fts_symfd); - __set_errno (saved_errno); - p->fts_errno = errno; - SET(FTS_STOP); - } - (void)close(p->fts_symfd); - } else if (!(p->fts_flags & FTS_DONTCHDIR) && - fts_safe_changedir(sp, p->fts_parent, -1, "..")) { - p->fts_errno = errno; - SET(FTS_STOP); - } - p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; - if (p->fts_errno == 0) - LEAVE_DIR (sp, p, "3"); - return ISSET(FTS_STOP) ? NULL : p; + sp->fts_cur = p; + if (p->fts_info == FTS_NSOK) + { + if (p->fts_statp->st_size == FTS_STAT_REQUIRED) + { + FTSENT *parent = p->fts_parent; + if (FTS_ROOTLEVEL < p->fts_level + /* ->fts_n_dirs_remaining is not valid + for command-line-specified names. */ + && parent->fts_n_dirs_remaining == 0 + && ISSET(FTS_NOSTAT) + && ISSET(FTS_PHYSICAL) + && link_count_optimize_ok (parent)) + { + /* nothing more needed */ + } + else + { + p->fts_info = fts_stat(sp, p, false); + if (S_ISDIR(p->fts_statp->st_mode) + && p->fts_level != FTS_ROOTLEVEL + && parent->fts_n_dirs_remaining) + parent->fts_n_dirs_remaining--; + } + } + else + fts_assert (p->fts_statp->st_size == FTS_NO_STAT_REQUIRED); + } + + if (p->fts_info == FTS_D) + { + /* Now that P->fts_statp is guaranteed to be valid, + if this is a command-line directory, record its + device number, to be used for FTS_XDEV. */ + if (p->fts_level == FTS_ROOTLEVEL) + sp->fts_dev = p->fts_statp->st_dev; + Dprintf ((" entering: %s\n", p->fts_path)); + if (! enter_dir (sp, p)) + { + __set_errno (ENOMEM); + return NULL; + } + } + return p; + } + + /* Move up to the parent node. */ + p = tmp->fts_parent; + sp->fts_cur = p; + free(tmp); + + if (p->fts_level == FTS_ROOTPARENTLEVEL) { + /* + * Done; free everything up and set errno to 0 so the user + * can distinguish between error and EOF. + */ + free(p); + __set_errno (0); + return (sp->fts_cur = NULL); + } + + fts_assert (p->fts_info != FTS_NSOK); + + /* NUL terminate the file name. */ + sp->fts_path[p->fts_pathlen] = '\0'; + + /* + * Return to the parent directory. If at a root node, restore + * the initial working directory. If we came through a symlink, + * go back through the file descriptor. Otherwise, move up + * one level, via "..". + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (RESTORE_INITIAL_CWD(sp)) { + p->fts_errno = errno; + SET(FTS_STOP); + } + } else if (p->fts_flags & FTS_SYMFOLLOW) { + if (FCHDIR(sp, p->fts_symfd)) { + int saved_errno = errno; + (void)close(p->fts_symfd); + __set_errno (saved_errno); + p->fts_errno = errno; + SET(FTS_STOP); + } + (void)close(p->fts_symfd); + } else if (!(p->fts_flags & FTS_DONTCHDIR) && + fts_safe_changedir(sp, p->fts_parent, -1, "..")) { + p->fts_errno = errno; + SET(FTS_STOP); + } + p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; + if (p->fts_errno == 0) + LEAVE_DIR (sp, p, "3"); + return ISSET(FTS_STOP) ? NULL : p; } /* @@ -1066,91 +1066,91 @@ check_for_dir: int fts_set(FTS *sp _UNUSED_PARAMETER_, FTSENT *p, int instr) { - if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW && - instr != FTS_NOINSTR && instr != FTS_SKIP) { - __set_errno (EINVAL); - return (1); - } - p->fts_instr = instr; - return (0); + if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW && + instr != FTS_NOINSTR && instr != FTS_SKIP) { + __set_errno (EINVAL); + return (1); + } + p->fts_instr = instr; + return (0); } FTSENT * fts_children (register FTS *sp, int instr) { - register FTSENT *p; - int fd; - - if (instr != 0 && instr != FTS_NAMEONLY) { - __set_errno (EINVAL); - return (NULL); - } - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* - * Errno set to 0 so user can distinguish empty directory from - * an error. - */ - __set_errno (0); - - /* Fatal errors stop here. */ - if (ISSET(FTS_STOP)) - return (NULL); - - /* Return logical hierarchy of user's arguments. */ - if (p->fts_info == FTS_INIT) - return (p->fts_link); - - /* - * If not a directory being visited in pre-order, stop here. Could - * allow FTS_DNR, assuming the user has fixed the problem, but the - * same effect is available with FTS_AGAIN. - */ - if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) - return (NULL); - - /* Free up any previous child list. */ - if (sp->fts_child != NULL) - fts_lfree(sp->fts_child); - - if (instr == FTS_NAMEONLY) { - SET(FTS_NAMEONLY); - instr = BNAMES; - } else - instr = BCHILD; - - /* - * If using chdir on a relative file name and called BEFORE fts_read - * does its chdir to the root of a traversal, we can lose -- we need to - * chdir into the subdirectory, and we don't know where the current - * directory is, so we can't get back so that the upcoming chdir by - * fts_read will work. - */ - if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || - ISSET(FTS_NOCHDIR)) - return (sp->fts_child = fts_build(sp, instr)); - - if ((fd = diropen (sp, ".")) < 0) - return (sp->fts_child = NULL); - sp->fts_child = fts_build(sp, instr); - if (ISSET(FTS_CWDFD)) - { - cwd_advance_fd (sp, fd, true); - } - else - { - if (fchdir(fd)) - { - int saved_errno = errno; - close (fd); - __set_errno (saved_errno); - return NULL; - } - close (fd); - } - return (sp->fts_child); + register FTSENT *p; + int fd; + + if (instr != 0 && instr != FTS_NAMEONLY) { + __set_errno (EINVAL); + return (NULL); + } + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* + * Errno set to 0 so user can distinguish empty directory from + * an error. + */ + __set_errno (0); + + /* Fatal errors stop here. */ + if (ISSET(FTS_STOP)) + return (NULL); + + /* Return logical hierarchy of user's arguments. */ + if (p->fts_info == FTS_INIT) + return (p->fts_link); + + /* + * If not a directory being visited in pre-order, stop here. Could + * allow FTS_DNR, assuming the user has fixed the problem, but the + * same effect is available with FTS_AGAIN. + */ + if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) + return (NULL); + + /* Free up any previous child list. */ + if (sp->fts_child != NULL) + fts_lfree(sp->fts_child); + + if (instr == FTS_NAMEONLY) { + SET(FTS_NAMEONLY); + instr = BNAMES; + } else + instr = BCHILD; + + /* + * If using chdir on a relative file name and called BEFORE fts_read + * does its chdir to the root of a traversal, we can lose -- we need to + * chdir into the subdirectory, and we don't know where the current + * directory is, so we can't get back so that the upcoming chdir by + * fts_read will work. + */ + if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || + ISSET(FTS_NOCHDIR)) + return (sp->fts_child = fts_build(sp, instr)); + + if ((fd = diropen (sp, ".")) < 0) + return (sp->fts_child = NULL); + sp->fts_child = fts_build(sp, instr); + if (ISSET(FTS_CWDFD)) + { + cwd_advance_fd (sp, fd, true); + } + else + { + if (fchdir(fd)) + { + int saved_errno = errno; + close (fd); + __set_errno (saved_errno); + return NULL; + } + close (fd); + } + return (sp->fts_child); } /* A comparison function to sort on increasing inode number. @@ -1162,7 +1162,7 @@ static int fts_compare_ino (struct _ftsent const **a, struct _ftsent const **b) { return (a[0]->fts_statp->st_ino < b[0]->fts_statp->st_ino ? -1 - : b[0]->fts_statp->st_ino < a[0]->fts_statp->st_ino ? 1 : 0); + : b[0]->fts_statp->st_ino < a[0]->fts_statp->st_ino ? 1 : 0); } /* Map the dirent.d_type value, DTYPE, to the corresponding stat.st_mode @@ -1218,323 +1218,323 @@ static FTSENT * internal_function fts_build (register FTS *sp, int type) { - register struct dirent *dp; - register FTSENT *p, *head; - register size_t nitems; - FTSENT *cur, *tail; - DIR *dirp; - void *oldaddr; - int saved_errno; - bool descend; - bool doadjust; - ptrdiff_t level; - nlink_t nlinks; - bool nostat; - size_t len, maxlen, new_len; - char *cp; - - /* Set current node pointer. */ - cur = sp->fts_cur; - - /* - * Open the directory for reading. If this fails, we're done. - * If being called from fts_read, set the fts_info field. - */ + register struct dirent *dp; + register FTSENT *p, *head; + register size_t nitems; + FTSENT *cur, *tail; + DIR *dirp; + void *oldaddr; + int saved_errno; + bool descend; + bool doadjust; + ptrdiff_t level; + nlink_t nlinks; + bool nostat; + size_t len, maxlen, new_len; + char *cp; + + /* Set current node pointer. */ + cur = sp->fts_cur; + + /* + * Open the directory for reading. If this fails, we're done. + * If being called from fts_read, set the fts_info field. + */ #if defined FTS_WHITEOUT && 0 - if (ISSET(FTS_WHITEOUT)) - oflag = DTF_NODUP|DTF_REWIND; - else - oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; + if (ISSET(FTS_WHITEOUT)) + oflag = DTF_NODUP|DTF_REWIND; + else + oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; #else # define __opendir2(file, flag) \ - ( ! ISSET(FTS_NOCHDIR) && ISSET(FTS_CWDFD) \ - ? opendirat(sp->fts_cwd_fd, file) \ - : opendir(file)) + ( ! ISSET(FTS_NOCHDIR) && ISSET(FTS_CWDFD) \ + ? opendirat(sp->fts_cwd_fd, file) \ + : opendir(file)) #endif if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { - if (type == BREAD) { - cur->fts_info = FTS_DNR; - cur->fts_errno = errno; - } - return (NULL); - } + if (type == BREAD) { + cur->fts_info = FTS_DNR; + cur->fts_errno = errno; + } + return (NULL); + } /* Rather than calling fts_stat for each and every entry encountered - in the readdir loop (below), stat each directory only right after - opening it. */ + in the readdir loop (below), stat each directory only right after + opening it. */ if (cur->fts_info == FTS_NSOK) - cur->fts_info = fts_stat(sp, cur, false); + cur->fts_info = fts_stat(sp, cur, false); else if (sp->fts_options & FTS_TIGHT_CYCLE_CHECK) { - /* Now read the stat info again after opening a directory to - * reveal eventual changes caused by a submount triggered by - * the traversal. But do it only for utilities which use - * FTS_TIGHT_CYCLE_CHECK. Therefore, only find and du - * benefit/suffer from this feature for now. - */ - LEAVE_DIR (sp, cur, "4"); - fts_stat (sp, cur, false); - if (! enter_dir (sp, cur)) { - __set_errno (ENOMEM); - return NULL; - } - } - - /* - * Nlinks is the number of possible entries of type directory in the - * directory if we're cheating on stat calls, 0 if we're not doing - * any stat calls at all, (nlink_t) -1 if we're statting everything. - */ - if (type == BNAMES) { - nlinks = 0; - /* Be quiet about nostat, GCC. */ - nostat = false; - } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { - nlinks = (cur->fts_statp->st_nlink - - (ISSET(FTS_SEEDOT) ? 0 : 2)); - nostat = true; - } else { - nlinks = -1; - nostat = false; - } - - /* - * If we're going to need to stat anything or we want to descend - * and stay in the directory, chdir. If this fails we keep going, - * but set a flag so we don't chdir after the post-order visit. - * We won't be able to stat anything, but we can still return the - * names themselves. Note, that since fts_read won't be able to - * chdir into the directory, it will have to return different file - * names than before, i.e. "a/b" instead of "b". Since the node - * has already been visited in pre-order, have to wait until the - * post-order visit to return the error. There is a special case - * here, if there was nothing to stat then it's not an error to - * not be able to stat. This is all fairly nasty. If a program - * needed sorted entries or stat information, they had better be - * checking FTS_NS on the returned nodes. - */ - if (nlinks || type == BREAD) { - int dir_fd = dirfd(dirp); - if (ISSET(FTS_CWDFD) && 0 <= dir_fd) - { - dir_fd = dup (dir_fd); - set_cloexec_flag (dir_fd, true); - } - if (dir_fd < 0 || fts_safe_changedir(sp, cur, dir_fd, NULL)) { - if (nlinks && type == BREAD) - cur->fts_errno = errno; - cur->fts_flags |= FTS_DONTCHDIR; - descend = false; - closedir(dirp); - if (ISSET(FTS_CWDFD) && 0 <= dir_fd) - close (dir_fd); - dirp = NULL; - } else - descend = true; - } else - descend = false; - - /* - * Figure out the max file name length that can be stored in the - * current buffer -- the inner loop allocates more space as necessary. - * We really wouldn't have to do the maxlen calculations here, we - * could do them in fts_read before returning the name, but it's a - * lot easier here since the length is part of the dirent structure. - * - * If not changing directories set a pointer so that can just append - * each new component into the file name. - */ - len = NAPPEND(cur); - if (ISSET(FTS_NOCHDIR)) { - cp = sp->fts_path + len; - *cp++ = '/'; - } else { - /* GCC, you're too verbose. */ - cp = NULL; - } - len++; - maxlen = sp->fts_pathlen - len; - - level = cur->fts_level + 1; - - /* Read the directory, attaching each entry to the `link' pointer. */ - doadjust = false; - for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { - bool is_dir; - - if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) - continue; - - if ((p = fts_alloc (sp, dp->d_name, - _D_EXACT_NAMLEN (dp))) == NULL) - goto mem1; - if (_D_EXACT_NAMLEN (dp) >= maxlen) { - /* include space for NUL */ - oldaddr = sp->fts_path; - if (! fts_palloc(sp, _D_EXACT_NAMLEN (dp) + len + 1)) { - /* - * No more memory. Save - * errno, free up the current structure and the - * structures already allocated. - */ -mem1: saved_errno = errno; - free(p); - fts_lfree(head); - closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - __set_errno (saved_errno); - return (NULL); - } - /* Did realloc() change the pointer? */ - if (oldaddr != sp->fts_path) { - doadjust = true; - if (ISSET(FTS_NOCHDIR)) - cp = sp->fts_path + len; - } - maxlen = sp->fts_pathlen - len; - } - - new_len = len + _D_EXACT_NAMLEN (dp); - if (new_len < len) { - /* - * In the unlikely event that we would end up - * with a file name longer than SIZE_MAX, free up - * the current structure and the structures already - * allocated, then error out with ENAMETOOLONG. - */ - free(p); - fts_lfree(head); - closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - __set_errno (ENAMETOOLONG); - return (NULL); - } - p->fts_level = level; - p->fts_parent = sp->fts_cur; - p->fts_pathlen = new_len; + /* Now read the stat info again after opening a directory to + * reveal eventual changes caused by a submount triggered by + * the traversal. But do it only for utilities which use + * FTS_TIGHT_CYCLE_CHECK. Therefore, only find and du + * benefit/suffer from this feature for now. + */ + LEAVE_DIR (sp, cur, "4"); + fts_stat (sp, cur, false); + if (! enter_dir (sp, cur)) { + __set_errno (ENOMEM); + return NULL; + } + } + + /* + * Nlinks is the number of possible entries of type directory in the + * directory if we're cheating on stat calls, 0 if we're not doing + * any stat calls at all, (nlink_t) -1 if we're statting everything. + */ + if (type == BNAMES) { + nlinks = 0; + /* Be quiet about nostat, GCC. */ + nostat = false; + } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { + nlinks = (cur->fts_statp->st_nlink + - (ISSET(FTS_SEEDOT) ? 0 : 2)); + nostat = true; + } else { + nlinks = -1; + nostat = false; + } + + /* + * If we're going to need to stat anything or we want to descend + * and stay in the directory, chdir. If this fails we keep going, + * but set a flag so we don't chdir after the post-order visit. + * We won't be able to stat anything, but we can still return the + * names themselves. Note, that since fts_read won't be able to + * chdir into the directory, it will have to return different file + * names than before, i.e. "a/b" instead of "b". Since the node + * has already been visited in pre-order, have to wait until the + * post-order visit to return the error. There is a special case + * here, if there was nothing to stat then it's not an error to + * not be able to stat. This is all fairly nasty. If a program + * needed sorted entries or stat information, they had better be + * checking FTS_NS on the returned nodes. + */ + if (nlinks || type == BREAD) { + int dir_fd = dirfd(dirp); + if (ISSET(FTS_CWDFD) && 0 <= dir_fd) + { + dir_fd = dup (dir_fd); + set_cloexec_flag (dir_fd, true); + } + if (dir_fd < 0 || fts_safe_changedir(sp, cur, dir_fd, NULL)) { + if (nlinks && type == BREAD) + cur->fts_errno = errno; + cur->fts_flags |= FTS_DONTCHDIR; + descend = false; + closedir(dirp); + if (ISSET(FTS_CWDFD) && 0 <= dir_fd) + close (dir_fd); + dirp = NULL; + } else + descend = true; + } else + descend = false; + + /* + * Figure out the max file name length that can be stored in the + * current buffer -- the inner loop allocates more space as necessary. + * We really wouldn't have to do the maxlen calculations here, we + * could do them in fts_read before returning the name, but it's a + * lot easier here since the length is part of the dirent structure. + * + * If not changing directories set a pointer so that can just append + * each new component into the file name. + */ + len = NAPPEND(cur); + if (ISSET(FTS_NOCHDIR)) { + cp = sp->fts_path + len; + *cp++ = '/'; + } else { + /* GCC, you're too verbose. */ + cp = NULL; + } + len++; + maxlen = sp->fts_pathlen - len; + + level = cur->fts_level + 1; + + /* Read the directory, attaching each entry to the `link' pointer. */ + doadjust = false; + for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { + bool is_dir; + + if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) + continue; + + if ((p = fts_alloc (sp, dp->d_name, + _D_EXACT_NAMLEN (dp))) == NULL) + goto mem1; + if (_D_EXACT_NAMLEN (dp) >= maxlen) { + /* include space for NUL */ + oldaddr = sp->fts_path; + if (! fts_palloc(sp, _D_EXACT_NAMLEN (dp) + len + 1)) { + /* + * No more memory. Save + * errno, free up the current structure and the + * structures already allocated. + */ +mem1: saved_errno = errno; + free(p); + fts_lfree(head); + closedir(dirp); + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + __set_errno (saved_errno); + return (NULL); + } + /* Did realloc() change the pointer? */ + if (oldaddr != sp->fts_path) { + doadjust = true; + if (ISSET(FTS_NOCHDIR)) + cp = sp->fts_path + len; + } + maxlen = sp->fts_pathlen - len; + } + + new_len = len + _D_EXACT_NAMLEN (dp); + if (new_len < len) { + /* + * In the unlikely event that we would end up + * with a file name longer than SIZE_MAX, free up + * the current structure and the structures already + * allocated, then error out with ENAMETOOLONG. + */ + free(p); + fts_lfree(head); + closedir(dirp); + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + __set_errno (ENAMETOOLONG); + return (NULL); + } + p->fts_level = level; + p->fts_parent = sp->fts_cur; + p->fts_pathlen = new_len; #if defined FTS_WHITEOUT && 0 - if (dp->d_type == DT_WHT) - p->fts_flags |= FTS_ISW; + if (dp->d_type == DT_WHT) + p->fts_flags |= FTS_ISW; #endif - /* Store dirent.d_ino, in case we need to sort - entries before processing them. */ - p->fts_statp->st_ino = D_INO (dp); - - /* Build a file name for fts_stat to stat. */ - if (ISSET(FTS_NOCHDIR)) { - p->fts_accpath = p->fts_path; - memmove(cp, p->fts_name, p->fts_namelen + 1); - } else - p->fts_accpath = p->fts_name; - - if (sp->fts_compar == NULL || ISSET(FTS_DEFER_STAT)) { - /* Record what fts_read will have to do with this - entry. In many cases, it will simply fts_stat it, - but we can take advantage of any d_type information - to optimize away the unnecessary stat calls. I.e., - if FTS_NOSTAT is in effect and we're not following - symlinks (FTS_PHYSICAL) and d_type indicates this - is *not* a directory, then we won't have to stat it - at all. If it *is* a directory, then (currently) - we stat it regardless, in order to get device and - inode numbers. Some day we might optimize that - away, too, for directories where d_ino is known to - be valid. */ - bool skip_stat = (ISSET(FTS_PHYSICAL) - && ISSET(FTS_NOSTAT) - && DT_IS_KNOWN(dp) - && ! DT_MUST_BE(dp, DT_DIR)); - p->fts_info = FTS_NSOK; - /* Propagate dirent.d_type information back - to caller, when possible. */ - set_stat_type (p->fts_statp, D_TYPE (dp)); - fts_set_stat_required(p, !skip_stat); - is_dir = (ISSET(FTS_PHYSICAL) - && DT_MUST_BE(dp, DT_DIR)); - } else { - p->fts_info = fts_stat(sp, p, false); - is_dir = (p->fts_info == FTS_D - || p->fts_info == FTS_DC - || p->fts_info == FTS_DOT); - } - - /* Decrement link count if applicable. */ - if (nlinks > 0 && is_dir) - nlinks -= nostat; - - /* We walk in directory order so "ls -f" doesn't get upset. */ - p->fts_link = NULL; - if (head == NULL) - head = tail = p; - else { - tail->fts_link = p; - tail = p; - } - ++nitems; - } - if (dirp) - closedir(dirp); - - /* - * If realloc() changed the address of the file name, adjust the - * addresses for the rest of the tree and the dir list. - */ - if (doadjust) - fts_padjust(sp, head); - - /* - * If not changing directories, reset the file name back to original - * state. - */ - if (ISSET(FTS_NOCHDIR)) { - if (len == sp->fts_pathlen || nitems == 0) - --cp; - *cp = '\0'; - } - - /* - * If descended after called from fts_children or after called from - * fts_read and nothing found, get back. At the root level we use - * the saved fd; if one of fts_open()'s arguments is a relative name - * to an empty directory, we wind up here with no other way back. If - * can't get back, we're done. - */ - if (descend && (type == BCHILD || !nitems) && - (cur->fts_level == FTS_ROOTLEVEL - ? RESTORE_INITIAL_CWD(sp) - : fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - fts_lfree(head); - return (NULL); - } - - /* If didn't find anything, return NULL. */ - if (!nitems) { - if (type == BREAD) - cur->fts_info = FTS_DP; - fts_lfree(head); - return (NULL); - } - - /* If there are many entries, no sorting function has been specified, - and this file system is of a type that may be slow with a large - number of entries, then sort the directory entries on increasing - inode numbers. */ - if (nitems > _FTS_INODE_SORT_DIR_ENTRIES_THRESHOLD - && !sp->fts_compar - && ISSET (FTS_CWDFD) - && dirent_inode_sort_may_be_useful (sp->fts_cwd_fd)) { - sp->fts_compar = fts_compare_ino; - head = fts_sort (sp, head, nitems); - sp->fts_compar = NULL; - } - - /* Sort the entries. */ - if (sp->fts_compar && nitems > 1) - head = fts_sort(sp, head, nitems); - return (head); + /* Store dirent.d_ino, in case we need to sort + entries before processing them. */ + p->fts_statp->st_ino = D_INO (dp); + + /* Build a file name for fts_stat to stat. */ + if (ISSET(FTS_NOCHDIR)) { + p->fts_accpath = p->fts_path; + memmove(cp, p->fts_name, p->fts_namelen + 1); + } else + p->fts_accpath = p->fts_name; + + if (sp->fts_compar == NULL || ISSET(FTS_DEFER_STAT)) { + /* Record what fts_read will have to do with this + entry. In many cases, it will simply fts_stat it, + but we can take advantage of any d_type information + to optimize away the unnecessary stat calls. I.e., + if FTS_NOSTAT is in effect and we're not following + symlinks (FTS_PHYSICAL) and d_type indicates this + is *not* a directory, then we won't have to stat it + at all. If it *is* a directory, then (currently) + we stat it regardless, in order to get device and + inode numbers. Some day we might optimize that + away, too, for directories where d_ino is known to + be valid. */ + bool skip_stat = (ISSET(FTS_PHYSICAL) + && ISSET(FTS_NOSTAT) + && DT_IS_KNOWN(dp) + && ! DT_MUST_BE(dp, DT_DIR)); + p->fts_info = FTS_NSOK; + /* Propagate dirent.d_type information back + to caller, when possible. */ + set_stat_type (p->fts_statp, D_TYPE (dp)); + fts_set_stat_required(p, !skip_stat); + is_dir = (ISSET(FTS_PHYSICAL) + && DT_MUST_BE(dp, DT_DIR)); + } else { + p->fts_info = fts_stat(sp, p, false); + is_dir = (p->fts_info == FTS_D + || p->fts_info == FTS_DC + || p->fts_info == FTS_DOT); + } + + /* Decrement link count if applicable. */ + if (nlinks > 0 && is_dir) + nlinks -= nostat; + + /* We walk in directory order so "ls -f" doesn't get upset. */ + p->fts_link = NULL; + if (head == NULL) + head = tail = p; + else { + tail->fts_link = p; + tail = p; + } + ++nitems; + } + if (dirp) + closedir(dirp); + + /* + * If realloc() changed the address of the file name, adjust the + * addresses for the rest of the tree and the dir list. + */ + if (doadjust) + fts_padjust(sp, head); + + /* + * If not changing directories, reset the file name back to original + * state. + */ + if (ISSET(FTS_NOCHDIR)) { + if (len == sp->fts_pathlen || nitems == 0) + --cp; + *cp = '\0'; + } + + /* + * If descended after called from fts_children or after called from + * fts_read and nothing found, get back. At the root level we use + * the saved fd; if one of fts_open()'s arguments is a relative name + * to an empty directory, we wind up here with no other way back. If + * can't get back, we're done. + */ + if (descend && (type == BCHILD || !nitems) && + (cur->fts_level == FTS_ROOTLEVEL + ? RESTORE_INITIAL_CWD(sp) + : fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + fts_lfree(head); + return (NULL); + } + + /* If didn't find anything, return NULL. */ + if (!nitems) { + if (type == BREAD) + cur->fts_info = FTS_DP; + fts_lfree(head); + return (NULL); + } + + /* If there are many entries, no sorting function has been specified, + and this file system is of a type that may be slow with a large + number of entries, then sort the directory entries on increasing + inode numbers. */ + if (nitems > _FTS_INODE_SORT_DIR_ENTRIES_THRESHOLD + && !sp->fts_compar + && ISSET (FTS_CWDFD) + && dirent_inode_sort_may_be_useful (sp->fts_cwd_fd)) { + sp->fts_compar = fts_compare_ino; + head = fts_sort (sp, head, nitems); + sp->fts_compar = NULL; + } + + /* Sort the entries. */ + if (sp->fts_compar && nitems > 1) + head = fts_sort(sp, head, nitems); + return (head); } #if FTS_DEBUG @@ -1549,20 +1549,20 @@ find_matching_ancestor (FTSENT const *e_curr, struct Active_dir const *ad) for (ent = e_curr; ent->fts_level >= FTS_ROOTLEVEL; ent = ent->fts_parent) { if (ad->ino == ent->fts_statp->st_ino - && ad->dev == ent->fts_statp->st_dev) - return; + && ad->dev == ent->fts_statp->st_dev) + return; } printf ("ERROR: tree dir, %s, not active\n", ad->fts_ent->fts_accpath); printf ("active dirs:\n"); for (ent = e_curr; ent->fts_level >= FTS_ROOTLEVEL; ent = ent->fts_parent) printf (" %s(%"PRIuMAX"/%"PRIuMAX") to %s(%"PRIuMAX"/%"PRIuMAX")...\n", - ad->fts_ent->fts_accpath, - (uintmax_t) ad->dev, - (uintmax_t) ad->ino, - ent->fts_accpath, - (uintmax_t) ent->fts_statp->st_dev, - (uintmax_t) ent->fts_statp->st_ino); + ad->fts_ent->fts_accpath, + (uintmax_t) ad->dev, + (uintmax_t) ad->ino, + ent->fts_accpath, + (uintmax_t) ent->fts_statp->st_dev, + (uintmax_t) ent->fts_statp->st_ino); } void @@ -1581,21 +1581,21 @@ fts_cross_check (FTS const *sp) ad.ino = t->fts_statp->st_ino; ad.dev = t->fts_statp->st_dev; if ( ! hash_lookup (sp->fts_cycle.ht, &ad)) - printf ("ERROR: active dir, %s, not in tree\n", t->fts_path); + printf ("ERROR: active dir, %s, not in tree\n", t->fts_path); } /* Make sure every dir in the tree is an active dir. But ENT is not necessarily a directory. If so, just skip this part. */ if (ent->fts_parent->fts_level >= FTS_ROOTLEVEL && (ent->fts_info == FTS_DP - || ent->fts_info == FTS_D)) + || ent->fts_info == FTS_D)) { struct Active_dir *ad; for (ad = hash_get_first (sp->fts_cycle.ht); ad != NULL; - ad = hash_get_next (sp->fts_cycle.ht, ad)) - { - find_matching_ancestor (ent, ad); - } + ad = hash_get_next (sp->fts_cycle.ht, ad)) + { + find_matching_ancestor (ent, ad); + } } } @@ -1604,8 +1604,8 @@ same_fd (int fd1, int fd2) { struct stat sb1, sb2; return (fstat (fd1, &sb1) == 0 - && fstat (fd2, &sb2) == 0 - && SAME_INODE (sb1, sb2)); + && fstat (fd2, &sb2) == 0 + && SAME_INODE (sb1, sb2)); } static void @@ -1623,15 +1623,15 @@ fd_ring_print (FTS const *sp, FILE *stream, char const *msg) { int fd = fd_ring->fts_fd_ring[i]; if (fd < 0) - fprintf (stream, "%d: %d:\n", i, fd); + fprintf (stream, "%d: %d:\n", i, fd); else - { - char *wd = getcwdat (fd, NULL, 0); - fprintf (stream, "%d: %d: %s\n", i, fd, wd); - free (wd); - } + { + char *wd = getcwdat (fd, NULL, 0); + fprintf (stream, "%d: %d: %s\n", i, fd, wd); + free (wd); + } if (i == fd_ring->fts_back) - break; + break; i = (i + I_RING_SIZE - 1) % I_RING_SIZE; } } @@ -1656,26 +1656,26 @@ fd_ring_check (FTS const *sp) { int fd = i_ring_pop (&fd_w); if (0 <= fd) - { - int parent_fd = openat (cwd_fd, "..", O_RDONLY); - if (parent_fd < 0) - { - // Warn? - break; - } - if (!same_fd (fd, parent_fd)) - { - char *cwd = getcwdat (fd, NULL, 0); - error (0, errno, "ring : %s", cwd); - char *c2 = getcwdat (parent_fd, NULL, 0); - error (0, errno, "parent: %s", c2); - free (cwd); - free (c2); - fts_assert (0); - } - close (cwd_fd); - cwd_fd = parent_fd; - } + { + int parent_fd = openat (cwd_fd, "..", O_RDONLY); + if (parent_fd < 0) + { + // Warn? + break; + } + if (!same_fd (fd, parent_fd)) + { + char *cwd = getcwdat (fd, NULL, 0); + error (0, errno, "ring : %s", cwd); + char *c2 = getcwdat (parent_fd, NULL, 0); + error (0, errno, "parent: %s", c2); + free (cwd); + free (c2); + fts_assert (0); + } + close (cwd_fd); + cwd_fd = parent_fd; + } } close (cwd_fd); } @@ -1685,80 +1685,80 @@ static unsigned short int internal_function fts_stat(FTS *sp, register FTSENT *p, bool follow) { - struct stat *sbp = p->fts_statp; - int saved_errno; + struct stat *sbp = p->fts_statp; + int saved_errno; - if (p->fts_level == FTS_ROOTLEVEL && ISSET(FTS_COMFOLLOW)) - follow = true; + if (p->fts_level == FTS_ROOTLEVEL && ISSET(FTS_COMFOLLOW)) + follow = true; #if defined FTS_WHITEOUT && 0 - /* check for whiteout */ - if (p->fts_flags & FTS_ISW) { - memset(sbp, '\0', sizeof (*sbp)); - sbp->st_mode = S_IFWHT; - return (FTS_W); + /* check for whiteout */ + if (p->fts_flags & FTS_ISW) { + memset(sbp, '\0', sizeof (*sbp)); + sbp->st_mode = S_IFWHT; + return (FTS_W); } #endif - /* - * If doing a logical walk, or application requested FTS_FOLLOW, do - * a stat(2). If that fails, check for a non-existent symlink. If - * fail, set the errno from the stat call. - */ - if (ISSET(FTS_LOGICAL) || follow) { - if (stat(p->fts_accpath, sbp)) { - saved_errno = errno; - if (errno == ENOENT - && lstat(p->fts_accpath, sbp) == 0) { - __set_errno (0); - return (FTS_SLNONE); - } - p->fts_errno = saved_errno; - goto err; - } - } else if (fstatat(sp->fts_cwd_fd, p->fts_accpath, sbp, - AT_SYMLINK_NOFOLLOW)) { - p->fts_errno = errno; -err: memset(sbp, 0, sizeof(struct stat)); - return (FTS_NS); - } - - if (S_ISDIR(sbp->st_mode)) { - p->fts_n_dirs_remaining = (sbp->st_nlink - - (ISSET(FTS_SEEDOT) ? 0 : 2)); - if (ISDOT(p->fts_name)) { - /* Command-line "." and ".." are real directories. */ - return (p->fts_level == FTS_ROOTLEVEL ? FTS_D : FTS_DOT); - } + /* + * If doing a logical walk, or application requested FTS_FOLLOW, do + * a stat(2). If that fails, check for a non-existent symlink. If + * fail, set the errno from the stat call. + */ + if (ISSET(FTS_LOGICAL) || follow) { + if (stat(p->fts_accpath, sbp)) { + saved_errno = errno; + if (errno == ENOENT + && lstat(p->fts_accpath, sbp) == 0) { + __set_errno (0); + return (FTS_SLNONE); + } + p->fts_errno = saved_errno; + goto err; + } + } else if (fstatat(sp->fts_cwd_fd, p->fts_accpath, sbp, + AT_SYMLINK_NOFOLLOW)) { + p->fts_errno = errno; +err: memset(sbp, 0, sizeof(struct stat)); + return (FTS_NS); + } + + if (S_ISDIR(sbp->st_mode)) { + p->fts_n_dirs_remaining = (sbp->st_nlink + - (ISSET(FTS_SEEDOT) ? 0 : 2)); + if (ISDOT(p->fts_name)) { + /* Command-line "." and ".." are real directories. */ + return (p->fts_level == FTS_ROOTLEVEL ? FTS_D : FTS_DOT); + } #if !GNULIB_FTS - { - /* - * Cycle detection is done by brute force when the directory - * is first encountered. If the tree gets deep enough or the - * number of symbolic links to directories is high enough, - * something faster might be worthwhile. - */ - FTSENT *t; - - for (t = p->fts_parent; - t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) - if (sbp->st_ino == t->fts_statp->st_ino - && sbp->st_dev == t->fts_statp->st_dev) - { - p->fts_cycle = t; - return (FTS_DC); - } - } + { + /* + * Cycle detection is done by brute force when the directory + * is first encountered. If the tree gets deep enough or the + * number of symbolic links to directories is high enough, + * something faster might be worthwhile. + */ + FTSENT *t; + + for (t = p->fts_parent; + t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) + if (sbp->st_ino == t->fts_statp->st_ino + && sbp->st_dev == t->fts_statp->st_dev) + { + p->fts_cycle = t; + return (FTS_DC); + } + } #endif - return (FTS_D); - } - if (S_ISLNK(sbp->st_mode)) - return (FTS_SL); - if (S_ISREG(sbp->st_mode)) - return (FTS_F); - return (FTS_DEFAULT); + return (FTS_D); + } + if (S_ISLNK(sbp->st_mode)) + return (FTS_SL); + if (S_ISREG(sbp->st_mode)) + return (FTS_F); + return (FTS_DEFAULT); } static int @@ -1778,93 +1778,93 @@ static FTSENT * internal_function fts_sort (FTS *sp, FTSENT *head, register size_t nitems) { - register FTSENT **ap, *p; - - /* On most modern hosts, void * and FTSENT ** have the same - run-time representation, and one can convert sp->fts_compar to - the type qsort expects without problem. Use the heuristic that - this is OK if the two pointer types are the same size, and if - converting FTSENT ** to long int is the same as converting - FTSENT ** to void * and then to long int. This heuristic isn't - valid in general but we don't know of any counterexamples. */ - FTSENT *dummy; - int (*compare) (void const *, void const *) = - ((sizeof &dummy == sizeof (void *) - && (long int) &dummy == (long int) (void *) &dummy) - ? (int (*) (void const *, void const *)) sp->fts_compar - : fts_compar); - - /* - * Construct an array of pointers to the structures and call qsort(3). - * Reassemble the array in the order returned by qsort. If unable to - * sort for memory reasons, return the directory entries in their - * current order. Allocate enough space for the current needs plus - * 40 so don't realloc one entry at a time. - */ - if (nitems > sp->fts_nitems) { - FTSENT **a; - - sp->fts_nitems = nitems + 40; - if (SIZE_MAX / sizeof *a < sp->fts_nitems - || ! (a = realloc (sp->fts_array, - sp->fts_nitems * sizeof *a))) { - free(sp->fts_array); - sp->fts_array = NULL; - sp->fts_nitems = 0; - return (head); - } - sp->fts_array = a; - } - for (ap = sp->fts_array, p = head; p; p = p->fts_link) - *ap++ = p; - qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), compare); - for (head = *(ap = sp->fts_array); --nitems; ++ap) - ap[0]->fts_link = ap[1]; - ap[0]->fts_link = NULL; - return (head); + register FTSENT **ap, *p; + + /* On most modern hosts, void * and FTSENT ** have the same + run-time representation, and one can convert sp->fts_compar to + the type qsort expects without problem. Use the heuristic that + this is OK if the two pointer types are the same size, and if + converting FTSENT ** to long int is the same as converting + FTSENT ** to void * and then to long int. This heuristic isn't + valid in general but we don't know of any counterexamples. */ + FTSENT *dummy; + int (*compare) (void const *, void const *) = + ((sizeof &dummy == sizeof (void *) + && (long int) &dummy == (long int) (void *) &dummy) + ? (int (*) (void const *, void const *)) sp->fts_compar + : fts_compar); + + /* + * Construct an array of pointers to the structures and call qsort(3). + * Reassemble the array in the order returned by qsort. If unable to + * sort for memory reasons, return the directory entries in their + * current order. Allocate enough space for the current needs plus + * 40 so don't realloc one entry at a time. + */ + if (nitems > sp->fts_nitems) { + FTSENT **a; + + sp->fts_nitems = nitems + 40; + if (SIZE_MAX / sizeof *a < sp->fts_nitems + || ! (a = realloc (sp->fts_array, + sp->fts_nitems * sizeof *a))) { + free(sp->fts_array); + sp->fts_array = NULL; + sp->fts_nitems = 0; + return (head); + } + sp->fts_array = a; + } + for (ap = sp->fts_array, p = head; p; p = p->fts_link) + *ap++ = p; + qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), compare); + for (head = *(ap = sp->fts_array); --nitems; ++ap) + ap[0]->fts_link = ap[1]; + ap[0]->fts_link = NULL; + return (head); } static FTSENT * internal_function fts_alloc (FTS *sp, const char *name, register size_t namelen) { - register FTSENT *p; - size_t len; - - /* - * The file name is a variable length array. Allocate the FTSENT - * structure and the file name in one chunk. - */ - len = sizeof(FTSENT) + namelen; - if ((p = malloc(len)) == NULL) - return (NULL); - - /* Copy the name and guarantee NUL termination. */ - memmove(p->fts_name, name, namelen); - p->fts_name[namelen] = '\0'; - - p->fts_namelen = namelen; - p->fts_fts = sp; - p->fts_path = sp->fts_path; - p->fts_errno = 0; - p->fts_flags = 0; - p->fts_instr = FTS_NOINSTR; - p->fts_number = 0; - p->fts_pointer = NULL; - return (p); + register FTSENT *p; + size_t len; + + /* + * The file name is a variable length array. Allocate the FTSENT + * structure and the file name in one chunk. + */ + len = sizeof(FTSENT) + namelen; + if ((p = malloc(len)) == NULL) + return (NULL); + + /* Copy the name and guarantee NUL termination. */ + memmove(p->fts_name, name, namelen); + p->fts_name[namelen] = '\0'; + + p->fts_namelen = namelen; + p->fts_fts = sp; + p->fts_path = sp->fts_path; + p->fts_errno = 0; + p->fts_flags = 0; + p->fts_instr = FTS_NOINSTR; + p->fts_number = 0; + p->fts_pointer = NULL; + return (p); } static void internal_function fts_lfree (register FTSENT *head) { - register FTSENT *p; + register FTSENT *p; - /* Free a linked list of structures. */ - while ((p = head)) { - head = head->fts_link; - free(p); - } + /* Free a linked list of structures. */ + while ((p = head)) { + head = head->fts_link; + free(p); + } } /* @@ -1878,27 +1878,27 @@ static bool internal_function fts_palloc (FTS *sp, size_t more) { - char *p; - size_t new_len = sp->fts_pathlen + more + 256; - - /* - * See if fts_pathlen would overflow. - */ - if (new_len < sp->fts_pathlen) { - free(sp->fts_path); - sp->fts_path = NULL; - __set_errno (ENAMETOOLONG); - return false; - } - sp->fts_pathlen = new_len; - p = realloc(sp->fts_path, sp->fts_pathlen); - if (p == NULL) { - free(sp->fts_path); - sp->fts_path = NULL; - return false; - } - sp->fts_path = p; - return true; + char *p; + size_t new_len = sp->fts_pathlen + more + 256; + + /* + * See if fts_pathlen would overflow. + */ + if (new_len < sp->fts_pathlen) { + free(sp->fts_path); + sp->fts_path = NULL; + __set_errno (ENAMETOOLONG); + return false; + } + sp->fts_pathlen = new_len; + p = realloc(sp->fts_path, sp->fts_pathlen); + if (p == NULL) { + free(sp->fts_path); + sp->fts_path = NULL; + return false; + } + sp->fts_path = p; + return true; } /* @@ -1909,37 +1909,37 @@ static void internal_function fts_padjust (FTS *sp, FTSENT *head) { - FTSENT *p; - char *addr = sp->fts_path; - -#define ADJUST(p) do { \ - if ((p)->fts_accpath != (p)->fts_name) { \ - (p)->fts_accpath = \ - (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ - } \ - (p)->fts_path = addr; \ + FTSENT *p; + char *addr = sp->fts_path; + +#define ADJUST(p) do { \ + if ((p)->fts_accpath != (p)->fts_name) { \ + (p)->fts_accpath = \ + (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ + } \ + (p)->fts_path = addr; \ } while (0) - /* Adjust the current set of children. */ - for (p = sp->fts_child; p; p = p->fts_link) - ADJUST(p); - - /* Adjust the rest of the tree, including the current level. */ - for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { - ADJUST(p); - p = p->fts_link ? p->fts_link : p->fts_parent; - } + /* Adjust the current set of children. */ + for (p = sp->fts_child; p; p = p->fts_link) + ADJUST(p); + + /* Adjust the rest of the tree, including the current level. */ + for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { + ADJUST(p); + p = p->fts_link ? p->fts_link : p->fts_parent; + } } static size_t internal_function fts_maxarglen (char * const *argv) { - size_t len, max; + size_t len, max; - for (max = 0; *argv; ++argv) - if ((len = strlen(*argv)) > max) - max = len; - return (max + 1); + for (max = 0; *argv; ++argv) + if ((len = strlen(*argv)) > max) + max = len; + return (max + 1); } /* @@ -1955,84 +1955,84 @@ static int internal_function fts_safe_changedir (FTS *sp, FTSENT *p, int fd, char const *dir) { - int ret; - bool is_dotdot = dir && STREQ (dir, ".."); - int newfd; - - /* This clause handles the unusual case in which FTS_NOCHDIR - is specified, along with FTS_CWDFD. In that case, there is - no need to change even the virtual cwd file descriptor. - However, if FD is non-negative, we do close it here. */ - if (ISSET (FTS_NOCHDIR)) - { - if (ISSET (FTS_CWDFD) && 0 <= fd) - close (fd); - return 0; - } - - if (fd < 0 && is_dotdot && ISSET (FTS_CWDFD)) - { - /* When possible, skip the diropen and subsequent fstat+dev/ino - comparison. I.e., when changing to parent directory - (chdir ("..")), use a file descriptor from the ring and - save the overhead of diropen+fstat, as well as avoiding - failure when we lack "x" access to the virtual cwd. */ - if ( ! i_ring_empty (&sp->fts_fd_ring)) - { - int parent_fd; - fd_ring_print (sp, stderr, "pre-pop"); - parent_fd = i_ring_pop (&sp->fts_fd_ring); - is_dotdot = true; - if (0 <= parent_fd) - { - fd = parent_fd; - dir = NULL; - } - } - } - - newfd = fd; - if (fd < 0 && (newfd = diropen (sp, dir)) < 0) - return -1; - - /* The following dev/inode check is necessary if we're doing a - `logical' traversal (through symlinks, a la chown -L), if the - system lacks O_NOFOLLOW support, or if we're changing to ".." - (but not via a popped file descriptor). When changing to the - name "..", O_NOFOLLOW can't help. In general, when the target is - not "..", diropen's use of O_NOFOLLOW ensures we don't mistakenly - follow a symlink, so we can avoid the expense of this fstat. */ - if (ISSET(FTS_LOGICAL) || ! HAVE_WORKING_O_NOFOLLOW - || (dir && STREQ (dir, ".."))) - { - struct stat sb; - if (fstat(newfd, &sb)) - { - ret = -1; - goto bail; - } - if (p->fts_statp->st_dev != sb.st_dev - || p->fts_statp->st_ino != sb.st_ino) - { - __set_errno (ENOENT); /* disinformation */ - ret = -1; - goto bail; - } - } - - if (ISSET(FTS_CWDFD)) - { - cwd_advance_fd (sp, newfd, ! is_dotdot); - return 0; - } - - ret = fchdir(newfd); + int ret; + bool is_dotdot = dir && STREQ (dir, ".."); + int newfd; + + /* This clause handles the unusual case in which FTS_NOCHDIR + is specified, along with FTS_CWDFD. In that case, there is + no need to change even the virtual cwd file descriptor. + However, if FD is non-negative, we do close it here. */ + if (ISSET (FTS_NOCHDIR)) + { + if (ISSET (FTS_CWDFD) && 0 <= fd) + close (fd); + return 0; + } + + if (fd < 0 && is_dotdot && ISSET (FTS_CWDFD)) + { + /* When possible, skip the diropen and subsequent fstat+dev/ino + comparison. I.e., when changing to parent directory + (chdir ("..")), use a file descriptor from the ring and + save the overhead of diropen+fstat, as well as avoiding + failure when we lack "x" access to the virtual cwd. */ + if ( ! i_ring_empty (&sp->fts_fd_ring)) + { + int parent_fd; + fd_ring_print (sp, stderr, "pre-pop"); + parent_fd = i_ring_pop (&sp->fts_fd_ring); + is_dotdot = true; + if (0 <= parent_fd) + { + fd = parent_fd; + dir = NULL; + } + } + } + + newfd = fd; + if (fd < 0 && (newfd = diropen (sp, dir)) < 0) + return -1; + + /* The following dev/inode check is necessary if we're doing a + `logical' traversal (through symlinks, a la chown -L), if the + system lacks O_NOFOLLOW support, or if we're changing to ".." + (but not via a popped file descriptor). When changing to the + name "..", O_NOFOLLOW can't help. In general, when the target is + not "..", diropen's use of O_NOFOLLOW ensures we don't mistakenly + follow a symlink, so we can avoid the expense of this fstat. */ + if (ISSET(FTS_LOGICAL) || ! HAVE_WORKING_O_NOFOLLOW + || (dir && STREQ (dir, ".."))) + { + struct stat sb; + if (fstat(newfd, &sb)) + { + ret = -1; + goto bail; + } + if (p->fts_statp->st_dev != sb.st_dev + || p->fts_statp->st_ino != sb.st_ino) + { + __set_errno (ENOENT); /* disinformation */ + ret = -1; + goto bail; + } + } + + if (ISSET(FTS_CWDFD)) + { + cwd_advance_fd (sp, newfd, ! is_dotdot); + return 0; + } + + ret = fchdir(newfd); bail: - if (fd < 0) - { - int oerrno = errno; - (void)close(newfd); - __set_errno (oerrno); - } - return ret; + if (fd < 0) + { + int oerrno = errno; + (void)close(newfd); + __set_errno (oerrno); + } + return ret; } diff --git a/lib/fts_.h b/lib/fts_.h index 0e2d505af..b2593fef7 100644 --- a/lib/fts_.h +++ b/lib/fts_.h @@ -17,7 +17,7 @@ /* * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,10 +43,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)fts.h 8.3 (Berkeley) 8/14/94 + * @(#)fts.h 8.3 (Berkeley) 8/14/94 */ -#ifndef _FTS_H +#ifndef _FTS_H # define _FTS_H 1 # ifdef _LIBC @@ -66,27 +66,27 @@ # include "i-ring.h" typedef struct { - struct _ftsent *fts_cur; /* current node */ - struct _ftsent *fts_child; /* linked list of children */ - struct _ftsent **fts_array; /* sort array */ - dev_t fts_dev; /* starting device # */ - char *fts_path; /* file name for this descent */ - int fts_rfd; /* fd for root */ - int fts_cwd_fd; /* the file descriptor on which the - virtual cwd is open, or AT_FDCWD */ - size_t fts_pathlen; /* sizeof(path) */ - size_t fts_nitems; /* elements in the sort array */ - int (*fts_compar) (struct _ftsent const **, struct _ftsent const **); - /* compare fn */ - -# define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */ -# define FTS_LOGICAL 0x0002 /* logical walk */ -# define FTS_NOCHDIR 0x0004 /* don't change directories */ -# define FTS_NOSTAT 0x0008 /* don't get stat info */ -# define FTS_PHYSICAL 0x0010 /* physical walk */ -# define FTS_SEEDOT 0x0020 /* return dot and dot-dot */ -# define FTS_XDEV 0x0040 /* don't cross devices */ -# define FTS_WHITEOUT 0x0080 /* return whiteout information */ + struct _ftsent *fts_cur; /* current node */ + struct _ftsent *fts_child; /* linked list of children */ + struct _ftsent **fts_array; /* sort array */ + dev_t fts_dev; /* starting device # */ + char *fts_path; /* file name for this descent */ + int fts_rfd; /* fd for root */ + int fts_cwd_fd; /* the file descriptor on which the + virtual cwd is open, or AT_FDCWD */ + size_t fts_pathlen; /* sizeof(path) */ + size_t fts_nitems; /* elements in the sort array */ + int (*fts_compar) (struct _ftsent const **, struct _ftsent const **); + /* compare fn */ + +# define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */ +# define FTS_LOGICAL 0x0002 /* logical walk */ +# define FTS_NOCHDIR 0x0004 /* don't change directories */ +# define FTS_NOSTAT 0x0008 /* don't get stat info */ +# define FTS_PHYSICAL 0x0010 /* physical walk */ +# define FTS_SEEDOT 0x0020 /* return dot and dot-dot */ +# define FTS_XDEV 0x0040 /* don't cross devices */ +# define FTS_WHITEOUT 0x0080 /* return whiteout information */ /* There are two ways to detect cycles. The lazy way (which works only with FTS_PHYSICAL), @@ -111,7 +111,7 @@ typedef struct { slink -> dir So, when FTS_LOGICAL is selected, we have to use a different mode of cycle detection: FTS_TIGHT_CYCLE_CHECK. */ -# define FTS_TIGHT_CYCLE_CHECK 0x0100 +# define FTS_TIGHT_CYCLE_CHECK 0x0100 /* Use this flag to enable semantics with which the parent application may be made both more efficient and more robust. @@ -120,7 +120,7 @@ typedef struct { working directory is never changed. Instead, these functions perform the traversal via a virtual working directory, maintained through the file descriptor member, fts_cwd_fd. */ -# define FTS_CWDFD 0x0200 +# define FTS_CWDFD 0x0200 /* Historically, for each directory that fts initially encounters, it would open it, read all entries, and stat each entry, storing the results, and @@ -135,102 +135,102 @@ typedef struct { nonzero, the S_IFMT type bits are valid, with mapped dirent.d_type data. Of course, that happens only on file systems that provide useful dirent.d_type data. */ -# define FTS_DEFER_STAT 0x0400 +# define FTS_DEFER_STAT 0x0400 -# define FTS_OPTIONMASK 0x07ff /* valid user option mask */ +# define FTS_OPTIONMASK 0x07ff /* valid user option mask */ -# define FTS_NAMEONLY 0x1000 /* (private) child names only */ -# define FTS_STOP 0x2000 /* (private) unrecoverable error */ - int fts_options; /* fts_open options, global flags */ +# define FTS_NAMEONLY 0x1000 /* (private) child names only */ +# define FTS_STOP 0x2000 /* (private) unrecoverable error */ + int fts_options; /* fts_open options, global flags */ # if GNULIB_FTS - /* Map a directory's device number to a boolean. The boolean is - true if for that file system (type determined by a single fstatfs - call per FS) st_nlink can be used to calculate the number of - sub-directory entries in a directory. - Using this table is an optimization that permits us to look up - file system type on a per-inode basis at the minimal cost of - calling fstatfs only once per traversed device. */ - struct hash_table *fts_leaf_optimization_works_ht; - - union { - /* This data structure is used if FTS_TIGHT_CYCLE_CHECK is - specified. It records the directories between a starting - point and the current directory. I.e., a directory is - recorded here IFF we have visited it once, but we have not - yet completed processing of all its entries. Every time we - visit a new directory, we add that directory to this set. - When we finish with a directory (usually by visiting it a - second time), we remove it from this set. Each entry in - this data structure is a device/inode pair. This data - structure is used to detect directory cycles efficiently and - promptly even when the depth of a hierarchy is in the tens - of thousands. */ - struct hash_table *ht; - - /* FIXME: rename these two members to have the fts_ prefix */ - /* This data structure uses a lazy cycle-detection algorithm, - as done by rm via cycle-check.c. It's the default, - but it's not appropriate for programs like du. */ - struct cycle_check_state *state; - } fts_cycle; + /* Map a directory's device number to a boolean. The boolean is + true if for that file system (type determined by a single fstatfs + call per FS) st_nlink can be used to calculate the number of + sub-directory entries in a directory. + Using this table is an optimization that permits us to look up + file system type on a per-inode basis at the minimal cost of + calling fstatfs only once per traversed device. */ + struct hash_table *fts_leaf_optimization_works_ht; + + union { + /* This data structure is used if FTS_TIGHT_CYCLE_CHECK is + specified. It records the directories between a starting + point and the current directory. I.e., a directory is + recorded here IFF we have visited it once, but we have not + yet completed processing of all its entries. Every time we + visit a new directory, we add that directory to this set. + When we finish with a directory (usually by visiting it a + second time), we remove it from this set. Each entry in + this data structure is a device/inode pair. This data + structure is used to detect directory cycles efficiently and + promptly even when the depth of a hierarchy is in the tens + of thousands. */ + struct hash_table *ht; + + /* FIXME: rename these two members to have the fts_ prefix */ + /* This data structure uses a lazy cycle-detection algorithm, + as done by rm via cycle-check.c. It's the default, + but it's not appropriate for programs like du. */ + struct cycle_check_state *state; + } fts_cycle; # endif - /* A stack of the file descriptors corresponding to the - most-recently traversed parent directories. - Currently used only in FTS_CWDFD mode. */ - I_ring fts_fd_ring; + /* A stack of the file descriptors corresponding to the + most-recently traversed parent directories. + Currently used only in FTS_CWDFD mode. */ + I_ring fts_fd_ring; } FTS; typedef struct _ftsent { - struct _ftsent *fts_cycle; /* cycle node */ - struct _ftsent *fts_parent; /* parent directory */ - struct _ftsent *fts_link; /* next file in directory */ - long fts_number; /* local numeric value */ - void *fts_pointer; /* local address value */ - char *fts_accpath; /* access file name */ - char *fts_path; /* root name; == fts_fts->fts_path */ - int fts_errno; /* errno for this node */ - int fts_symfd; /* fd for symlink */ - size_t fts_pathlen; /* strlen(fts_path) */ - - FTS *fts_fts; /* the file hierarchy itself */ - -# define FTS_ROOTPARENTLEVEL (-1) -# define FTS_ROOTLEVEL 0 - ptrdiff_t fts_level; /* depth (-1 to N) */ - - size_t fts_namelen; /* strlen(fts_name) */ - nlink_t fts_n_dirs_remaining; /* count down from st_nlink */ - -# define FTS_D 1 /* preorder directory */ -# define FTS_DC 2 /* directory that causes cycles */ -# define FTS_DEFAULT 3 /* none of the above */ -# define FTS_DNR 4 /* unreadable directory */ -# define FTS_DOT 5 /* dot or dot-dot */ -# define FTS_DP 6 /* postorder directory */ -# define FTS_ERR 7 /* error; errno is set */ -# define FTS_F 8 /* regular file */ -# define FTS_INIT 9 /* initialized only */ -# define FTS_NS 10 /* stat(2) failed */ -# define FTS_NSOK 11 /* no stat(2) requested */ -# define FTS_SL 12 /* symbolic link */ -# define FTS_SLNONE 13 /* symbolic link without target */ -# define FTS_W 14 /* whiteout object */ - unsigned short int fts_info; /* user flags for FTSENT structure */ - -# define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ -# define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ - unsigned short int fts_flags; /* private flags for FTSENT structure */ - -# define FTS_AGAIN 1 /* read node again */ -# define FTS_FOLLOW 2 /* follow symbolic link */ -# define FTS_NOINSTR 3 /* no instructions */ -# define FTS_SKIP 4 /* discard node */ - unsigned short int fts_instr; /* fts_set() instructions */ - - struct stat fts_statp[1]; /* stat(2) information */ - char fts_name[1]; /* file name */ + struct _ftsent *fts_cycle; /* cycle node */ + struct _ftsent *fts_parent; /* parent directory */ + struct _ftsent *fts_link; /* next file in directory */ + long fts_number; /* local numeric value */ + void *fts_pointer; /* local address value */ + char *fts_accpath; /* access file name */ + char *fts_path; /* root name; == fts_fts->fts_path */ + int fts_errno; /* errno for this node */ + int fts_symfd; /* fd for symlink */ + size_t fts_pathlen; /* strlen(fts_path) */ + + FTS *fts_fts; /* the file hierarchy itself */ + +# define FTS_ROOTPARENTLEVEL (-1) +# define FTS_ROOTLEVEL 0 + ptrdiff_t fts_level; /* depth (-1 to N) */ + + size_t fts_namelen; /* strlen(fts_name) */ + nlink_t fts_n_dirs_remaining; /* count down from st_nlink */ + +# define FTS_D 1 /* preorder directory */ +# define FTS_DC 2 /* directory that causes cycles */ +# define FTS_DEFAULT 3 /* none of the above */ +# define FTS_DNR 4 /* unreadable directory */ +# define FTS_DOT 5 /* dot or dot-dot */ +# define FTS_DP 6 /* postorder directory */ +# define FTS_ERR 7 /* error; errno is set */ +# define FTS_F 8 /* regular file */ +# define FTS_INIT 9 /* initialized only */ +# define FTS_NS 10 /* stat(2) failed */ +# define FTS_NSOK 11 /* no stat(2) requested */ +# define FTS_SL 12 /* symbolic link */ +# define FTS_SLNONE 13 /* symbolic link without target */ +# define FTS_W 14 /* whiteout object */ + unsigned short int fts_info; /* user flags for FTSENT structure */ + +# define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ +# define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ + unsigned short int fts_flags; /* private flags for FTSENT structure */ + +# define FTS_AGAIN 1 /* read node again */ +# define FTS_FOLLOW 2 /* follow symbolic link */ +# define FTS_NOINSTR 3 /* no instructions */ +# define FTS_SKIP 4 /* discard node */ + unsigned short int fts_instr; /* fts_set() instructions */ + + struct stat fts_statp[1]; /* stat(2) information */ + char fts_name[1]; /* file name */ } FTSENT; #ifndef __GNUC_PREREQ @@ -251,13 +251,13 @@ typedef struct _ftsent { #endif __BEGIN_DECLS -FTSENT *fts_children (FTS *, int) __THROW __attribute_warn_unused_result__; -int fts_close (FTS *) __THROW __attribute_warn_unused_result__; -FTS *fts_open (char * const *, int, - int (*)(const FTSENT **, const FTSENT **)) +FTSENT *fts_children (FTS *, int) __THROW __attribute_warn_unused_result__; +int fts_close (FTS *) __THROW __attribute_warn_unused_result__; +FTS *fts_open (char * const *, int, + int (*)(const FTSENT **, const FTSENT **)) __THROW __attribute_warn_unused_result__; -FTSENT *fts_read (FTS *) __THROW __attribute_warn_unused_result__; -int fts_set (FTS *, FTSENT *, int) __THROW; +FTSENT *fts_read (FTS *) __THROW __attribute_warn_unused_result__; +int fts_set (FTS *, FTSENT *, int) __THROW; __END_DECLS #endif /* fts.h */ diff --git a/lib/full-write.c b/lib/full-write.c index 51f2d3819..4ecad42f7 100644 --- a/lib/full-write.c +++ b/lib/full-write.c @@ -65,12 +65,12 @@ full_rw (int fd, const void *buf, size_t count) { size_t n_rw = safe_rw (fd, ptr, count); if (n_rw == (size_t) -1) - break; + break; if (n_rw == 0) - { - errno = ZERO_BYTE_TRANSFER_ERRNO; - break; - } + { + errno = ZERO_BYTE_TRANSFER_ERRNO; + break; + } total += n_rw; ptr += n_rw; count -= n_rw; diff --git a/lib/fwriteerror.c b/lib/fwriteerror.c index 325f9bf7d..a24de9d65 100644 --- a/lib/fwriteerror.c +++ b/lib/fwriteerror.c @@ -32,7 +32,7 @@ do_fwriteerror (FILE *fp, bool ignore_ebadf) if (fp == stdout) { if (stdout_closed) - return 0; + return 0; /* If we are closing stdout, don't attempt to do it later again. */ stdout_closed = true; @@ -41,14 +41,14 @@ do_fwriteerror (FILE *fp, bool ignore_ebadf) /* This function returns an error indication if there was a previous failure or if fclose failed, with two exceptions: - 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). + 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). - Ignore an fclose failure due to EPIPE. That can happen when a - program blocks or ignores SIGPIPE, and the output pipe or socket - has no readers now. The EPIPE tells us that we should stop writing - to this output. That's what we are doing anyway here. + program blocks or ignores SIGPIPE, and the output pipe or socket + has no readers now. The EPIPE tells us that we should stop writing + to this output. That's what we are doing anyway here. Need to 1. test the error indicator of the stream, @@ -62,15 +62,15 @@ do_fwriteerror (FILE *fp, bool ignore_ebadf) if (ferror (fp)) { if (fflush (fp)) - goto close_preserving_errno; /* errno is set here */ + goto close_preserving_errno; /* errno is set here */ /* The stream had an error earlier, but its errno was lost. If the - error was not temporary, we can get the same errno by writing and - flushing one more byte. We can do so because at this point the - stream's contents is garbage anyway. */ + error was not temporary, we can get the same errno by writing and + flushing one more byte. We can do so because at this point the + stream's contents is garbage anyway. */ if (fputc ('\0', fp) == EOF) - goto close_preserving_errno; /* errno is set here */ + goto close_preserving_errno; /* errno is set here */ if (fflush (fp)) - goto close_preserving_errno; /* errno is set here */ + goto close_preserving_errno; /* errno is set here */ /* Give up on errno. */ errno = 0; goto close_preserving_errno; @@ -79,16 +79,16 @@ do_fwriteerror (FILE *fp, bool ignore_ebadf) if (ignore_ebadf) { /* We need an explicit fflush to tell whether some output was already - done on FP. */ + done on FP. */ if (fflush (fp)) - goto close_preserving_errno; /* errno is set here */ + goto close_preserving_errno; /* errno is set here */ if (fclose (fp) && errno != EBADF) - goto got_errno; /* errno is set here */ + goto got_errno; /* errno is set here */ } else { if (fclose (fp)) - goto got_errno; /* errno is set here */ + goto got_errno; /* errno is set here */ } return 0; @@ -147,32 +147,32 @@ main () size_t size = sizes[i]; for (j = 0; j < 2; j++) - { - /* Run a test depending on i and j: - Write size bytes and then calls fflush if j==1. */ - FILE *stream = fopen (UNWRITABLE_FILE, "w"); - - if (stream == NULL) - { - fprintf (stderr, "Test %u:%u: could not open file\n", i, j); - continue; - } - - fwrite (dummy, 347, 1, stream); - fwrite (dummy, size - 347, 1, stream); - if (j) - fflush (stream); - - if (fwriteerror (stream) == -1) - { - if (errno != ENOSPC) - fprintf (stderr, "Test %u:%u: fwriteerror ok, errno = %d\n", - i, j, errno); - } - else - fprintf (stderr, "Test %u:%u: fwriteerror found no error!\n", - i, j); - } + { + /* Run a test depending on i and j: + Write size bytes and then calls fflush if j==1. */ + FILE *stream = fopen (UNWRITABLE_FILE, "w"); + + if (stream == NULL) + { + fprintf (stderr, "Test %u:%u: could not open file\n", i, j); + continue; + } + + fwrite (dummy, 347, 1, stream); + fwrite (dummy, size - 347, 1, stream); + if (j) + fflush (stream); + + if (fwriteerror (stream) == -1) + { + if (errno != ENOSPC) + fprintf (stderr, "Test %u:%u: fwriteerror ok, errno = %d\n", + i, j, errno); + } + else + fprintf (stderr, "Test %u:%u: fwriteerror found no error!\n", + i, j); + } } return 0; diff --git a/lib/fwriting.c b/lib/fwriting.c index c6dc9ac8d..7979e8576 100644 --- a/lib/fwriting.c +++ b/lib/fwriting.c @@ -39,7 +39,7 @@ fwriting (FILE *fp) return (fp->__modeflags & __FLAG_WRITING) != 0; #elif defined __QNX__ /* QNX */ return ((fp->_Mode & 0x1 /* _MOPENR */) == 0 - || (fp->_Mode & 0x2000 /* _MWRITE */) != 0); + || (fp->_Mode & 0x2000 /* _MWRITE */) != 0); #elif defined __MINT__ /* Atari FreeMiNT */ if (!fp->__mode.__read) return 1; diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c index 4862ad424..cb365c822 100644 --- a/lib/gc-gnulib.c +++ b/lib/gc-gnulib.c @@ -102,12 +102,12 @@ gc_init (void) /* We first try to use the Intel PIII RNG if drivers are present */ if (!CryptAcquireContext (&g_hProv, NULL, NULL, - PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT)) + PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT)) { /* not a PIII or no drivers available, use default RSA CSP */ if (!CryptAcquireContext (&g_hProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT)) - return GC_RANDOM_ERROR; + PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT)) + return GC_RANDOM_ERROR; } # endif #endif @@ -177,12 +177,12 @@ randomize (int level, char *data, size_t datalen) tmp = read (fd, data, datalen); if (tmp < 0) - { - int save_errno = errno; - close (fd); - errno = save_errno; - return GC_RANDOM_ERROR; - } + { + int save_errno = errno; + close (fd); + errno = save_errno; + return GC_RANDOM_ERROR; + } len += tmp; } @@ -220,9 +220,9 @@ gc_random (char *data, size_t datalen) void gc_set_allocators (gc_malloc_t func_malloc, - gc_malloc_t secure_malloc, - gc_secure_check_t secure_check, - gc_realloc_t func_realloc, gc_free_t func_free) + gc_malloc_t secure_malloc, + gc_secure_check_t secure_check, + gc_realloc_t func_realloc, gc_free_t func_free) { return; } @@ -252,7 +252,7 @@ typedef struct _gc_cipher_ctx Gc_rc gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode, - gc_cipher_handle * outhandle) + gc_cipher_handle * outhandle) { _gc_cipher_ctx *ctx; Gc_rc rc = GC_OK; @@ -269,14 +269,14 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode, #ifdef GNULIB_GC_ARCTWO case GC_ARCTWO40: switch (mode) - { - case GC_ECB: - case GC_CBC: - break; + { + case GC_ECB: + case GC_CBC: + break; - default: - rc = GC_INVALID_CIPHER; - } + default: + rc = GC_INVALID_CIPHER; + } break; #endif @@ -284,26 +284,26 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode, case GC_ARCFOUR128: case GC_ARCFOUR40: switch (mode) - { - case GC_STREAM: - break; + { + case GC_STREAM: + break; - default: - rc = GC_INVALID_CIPHER; - } + default: + rc = GC_INVALID_CIPHER; + } break; #endif #ifdef GNULIB_GC_DES case GC_DES: switch (mode) - { - case GC_ECB: - break; + { + case GC_ECB: + break; - default: - rc = GC_INVALID_CIPHER; - } + default: + rc = GC_INVALID_CIPHER; + } break; #endif @@ -312,14 +312,14 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode, case GC_AES192: case GC_AES256: switch (mode) - { - case GC_ECB: - case GC_CBC: - break; + { + case GC_ECB: + case GC_CBC: + break; - default: - rc = GC_INVALID_CIPHER; - } + default: + rc = GC_INVALID_CIPHER; + } break; #endif @@ -358,7 +358,7 @@ gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key) #ifdef GNULIB_GC_DES case GC_DES: if (keylen != 8) - return GC_INVALID_CIPHER; + return GC_INVALID_CIPHER; gl_des_setkey (&ctx->desContext, key); break; #endif @@ -368,26 +368,26 @@ gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char *key) case GC_AES192: case GC_AES256: { - rijndael_rc rc; - size_t i; - char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1]; - - for (i = 0; i < keylen; i++) - sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFF); - - rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT, - keylen * 8, keyMaterial); - if (rc < 0) - return GC_INVALID_CIPHER; - - rc = rijndaelMakeKey (&ctx->aesDecKey, RIJNDAEL_DIR_DECRYPT, - keylen * 8, keyMaterial); - if (rc < 0) - return GC_INVALID_CIPHER; - - rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_ECB, NULL); - if (rc < 0) - return GC_INVALID_CIPHER; + rijndael_rc rc; + size_t i; + char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1]; + + for (i = 0; i < keylen; i++) + sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFF); + + rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT, + keylen * 8, keyMaterial); + if (rc < 0) + return GC_INVALID_CIPHER; + + rc = rijndaelMakeKey (&ctx->aesDecKey, RIJNDAEL_DIR_DECRYPT, + keylen * 8, keyMaterial); + if (rc < 0) + return GC_INVALID_CIPHER; + + rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_ECB, NULL); + if (rc < 0) + return GC_INVALID_CIPHER; } break; #endif @@ -409,7 +409,7 @@ gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv) #ifdef GNULIB_GC_ARCTWO case GC_ARCTWO40: if (ivlen != ARCTWO_BLOCK_SIZE) - return GC_INVALID_CIPHER; + return GC_INVALID_CIPHER; memcpy (ctx->arctwoIV, iv, ivlen); break; #endif @@ -419,30 +419,30 @@ gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv) case GC_AES192: case GC_AES256: switch (ctx->mode) - { - case GC_ECB: - /* Doesn't use IV. */ - break; + { + case GC_ECB: + /* Doesn't use IV. */ + break; - case GC_CBC: - { - rijndael_rc rc; - size_t i; - char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1]; + case GC_CBC: + { + rijndael_rc rc; + size_t i; + char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1]; - for (i = 0; i < ivlen; i++) - sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFF); + for (i = 0; i < ivlen; i++) + sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFF); - rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC, - ivMaterial); - if (rc < 0) - return GC_INVALID_CIPHER; - } - break; + rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC, + ivMaterial); + if (rc < 0) + return GC_INVALID_CIPHER; + } + break; - default: - return GC_INVALID_CIPHER; - } + default: + return GC_INVALID_CIPHER; + } break; #endif @@ -463,27 +463,27 @@ gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data) #ifdef GNULIB_GC_ARCTWO case GC_ARCTWO40: switch (ctx->mode) - { - case GC_ECB: - arctwo_encrypt (&ctx->arctwoContext, data, data, len); - break; - - case GC_CBC: - for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE, - data += ARCTWO_BLOCK_SIZE) - { - size_t i; - for (i = 0; i < ARCTWO_BLOCK_SIZE; i++) - data[i] ^= ctx->arctwoIV[i]; - arctwo_encrypt (&ctx->arctwoContext, data, data, - ARCTWO_BLOCK_SIZE); - memcpy (ctx->arctwoIV, data, ARCTWO_BLOCK_SIZE); - } - break; - - default: - return GC_INVALID_CIPHER; - } + { + case GC_ECB: + arctwo_encrypt (&ctx->arctwoContext, data, data, len); + break; + + case GC_CBC: + for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE, + data += ARCTWO_BLOCK_SIZE) + { + size_t i; + for (i = 0; i < ARCTWO_BLOCK_SIZE; i++) + data[i] ^= ctx->arctwoIV[i]; + arctwo_encrypt (&ctx->arctwoContext, data, data, + ARCTWO_BLOCK_SIZE); + memcpy (ctx->arctwoIV, data, ARCTWO_BLOCK_SIZE); + } + break; + + default: + return GC_INVALID_CIPHER; + } break; #endif @@ -497,7 +497,7 @@ gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data) #ifdef GNULIB_GC_DES case GC_DES: for (; len >= 8; len -= 8, data += 8) - gl_des_ecb_encrypt (&ctx->desContext, data, data); + gl_des_ecb_encrypt (&ctx->desContext, data, data); break; #endif @@ -506,12 +506,12 @@ gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data) case GC_AES192: case GC_AES256: { - int nblocks; + int nblocks; - nblocks = rijndaelBlockEncrypt (&ctx->aesContext, &ctx->aesEncKey, - data, 8 * len, data); - if (nblocks < 0) - return GC_INVALID_CIPHER; + nblocks = rijndaelBlockEncrypt (&ctx->aesContext, &ctx->aesEncKey, + data, 8 * len, data); + if (nblocks < 0) + return GC_INVALID_CIPHER; } break; #endif @@ -533,29 +533,29 @@ gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data) #ifdef GNULIB_GC_ARCTWO case GC_ARCTWO40: switch (ctx->mode) - { - case GC_ECB: - arctwo_decrypt (&ctx->arctwoContext, data, data, len); - break; - - case GC_CBC: - for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE, - data += ARCTWO_BLOCK_SIZE) - { - char tmpIV[ARCTWO_BLOCK_SIZE]; - size_t i; - memcpy (tmpIV, data, ARCTWO_BLOCK_SIZE); - arctwo_decrypt (&ctx->arctwoContext, data, data, - ARCTWO_BLOCK_SIZE); - for (i = 0; i < ARCTWO_BLOCK_SIZE; i++) - data[i] ^= ctx->arctwoIV[i]; - memcpy (ctx->arctwoIV, tmpIV, ARCTWO_BLOCK_SIZE); - } - break; - - default: - return GC_INVALID_CIPHER; - } + { + case GC_ECB: + arctwo_decrypt (&ctx->arctwoContext, data, data, len); + break; + + case GC_CBC: + for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE, + data += ARCTWO_BLOCK_SIZE) + { + char tmpIV[ARCTWO_BLOCK_SIZE]; + size_t i; + memcpy (tmpIV, data, ARCTWO_BLOCK_SIZE); + arctwo_decrypt (&ctx->arctwoContext, data, data, + ARCTWO_BLOCK_SIZE); + for (i = 0; i < ARCTWO_BLOCK_SIZE; i++) + data[i] ^= ctx->arctwoIV[i]; + memcpy (ctx->arctwoIV, tmpIV, ARCTWO_BLOCK_SIZE); + } + break; + + default: + return GC_INVALID_CIPHER; + } break; #endif @@ -569,7 +569,7 @@ gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data) #ifdef GNULIB_GC_DES case GC_DES: for (; len >= 8; len -= 8, data += 8) - gl_des_ecb_decrypt (&ctx->desContext, data, data); + gl_des_ecb_decrypt (&ctx->desContext, data, data); break; #endif @@ -578,12 +578,12 @@ gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data) case GC_AES192: case GC_AES256: { - int nblocks; + int nblocks; - nblocks = rijndaelBlockDecrypt (&ctx->aesContext, &ctx->aesDecKey, - data, 8 * len, data); - if (nblocks < 0) - return GC_INVALID_CIPHER; + nblocks = rijndaelBlockDecrypt (&ctx->aesContext, &ctx->aesDecKey, + data, 8 * len, data); + if (nblocks < 0) + return GC_INVALID_CIPHER; } break; #endif @@ -901,7 +901,7 @@ gc_sha1 (const void *in, size_t inlen, void *resbuf) #ifdef GNULIB_GC_HMAC_MD5 Gc_rc gc_hmac_md5 (const void *key, size_t keylen, - const void *in, size_t inlen, char *resbuf) + const void *in, size_t inlen, char *resbuf) { hmac_md5 (key, keylen, in, inlen, resbuf); return GC_OK; @@ -911,7 +911,7 @@ gc_hmac_md5 (const void *key, size_t keylen, #ifdef GNULIB_GC_HMAC_SHA1 Gc_rc gc_hmac_sha1 (const void *key, size_t keylen, - const void *in, size_t inlen, char *resbuf) + const void *in, size_t inlen, char *resbuf) { hmac_sha1 (key, keylen, in, inlen, resbuf); return GC_OK; diff --git a/lib/gc-libgcrypt.c b/lib/gc-libgcrypt.c index 8ba42fbd5..1d26eb245 100644 --- a/lib/gc-libgcrypt.c +++ b/lib/gc-libgcrypt.c @@ -48,14 +48,14 @@ gc_init (void) if (err == GPG_ERR_NO_ERROR) { if (gcry_control (GCRYCTL_DISABLE_SECMEM, NULL, 0)) - return GC_INIT_ERROR; + return GC_INIT_ERROR; if (gcry_check_version (GCRYPT_VERSION) == NULL) - return GC_INIT_ERROR; + return GC_INIT_ERROR; err = gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL, 0); if (err != GPG_ERR_NO_ERROR) - return GC_INIT_ERROR; + return GC_INIT_ERROR; } return GC_OK; @@ -98,19 +98,19 @@ gc_random (char *data, size_t datalen) void gc_set_allocators (gc_malloc_t func_malloc, - gc_malloc_t secure_malloc, - gc_secure_check_t secure_check, - gc_realloc_t func_realloc, gc_free_t func_free) + gc_malloc_t secure_malloc, + gc_secure_check_t secure_check, + gc_realloc_t func_realloc, gc_free_t func_free) { gcry_set_allocation_handler (func_malloc, secure_malloc, secure_check, - func_realloc, func_free); + func_realloc, func_free); } /* Ciphers. */ Gc_rc gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode, - gc_cipher_handle * outhandle) + gc_cipher_handle * outhandle) { int gcryalg, gcrymode; gcry_error_t err; @@ -179,7 +179,7 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode, } err = gcry_cipher_open ((gcry_cipher_hd_t *) outhandle, - gcryalg, gcrymode, 0); + gcryalg, gcrymode, 0); if (gcry_err_code (err)) return GC_INVALID_CIPHER; @@ -214,7 +214,7 @@ Gc_rc gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char *data) { if (gcry_cipher_encrypt ((gcry_cipher_hd_t) handle, - data, len, NULL, len) != 0) + data, len, NULL, len) != 0) return GC_INVALID_CIPHER; return GC_OK; @@ -224,7 +224,7 @@ Gc_rc gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char *data) { if (gcry_cipher_decrypt ((gcry_cipher_hd_t) handle, - data, len, NULL, len) != 0) + data, len, NULL, len) != 0) return GC_INVALID_CIPHER; return GC_OK; @@ -325,7 +325,7 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle) { err = gcry_md_open (&ctx->gch, gcryalg, gcrymode); if (gcry_err_code (err)) - rc = GC_INVALID_HASH; + rc = GC_INVALID_HASH; } if (rc == GC_OK) @@ -648,7 +648,7 @@ gc_sha1 (const void *in, size_t inlen, void *resbuf) #ifdef GNULIB_GC_HMAC_MD5 Gc_rc gc_hmac_md5 (const void *key, size_t keylen, - const void *in, size_t inlen, char *resbuf) + const void *in, size_t inlen, char *resbuf) { size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_MD5); gcry_md_hd_t mdh; @@ -688,7 +688,7 @@ gc_hmac_md5 (const void *key, size_t keylen, #ifdef GNULIB_GC_HMAC_SHA1 Gc_rc gc_hmac_sha1 (const void *key, size_t keylen, - const void *in, size_t inlen, char *resbuf) + const void *in, size_t inlen, char *resbuf) { size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1); gcry_md_hd_t mdh; diff --git a/lib/gc-pbkdf2-sha1.c b/lib/gc-pbkdf2-sha1.c index 0f5211b2f..d8d5c4d13 100644 --- a/lib/gc-pbkdf2-sha1.c +++ b/lib/gc-pbkdf2-sha1.c @@ -32,9 +32,9 @@ be filled with the derived data. */ Gc_rc gc_pbkdf2_sha1 (const char *P, size_t Plen, - const char *S, size_t Slen, - unsigned int c, - char *DK, size_t dkLen) + const char *S, size_t Slen, + unsigned int c, + char *DK, size_t dkLen) { unsigned int hLen = 20; char U[20]; @@ -71,28 +71,28 @@ gc_pbkdf2_sha1 (const char *P, size_t Plen, memset (T, 0, hLen); for (u = 1; u <= c; u++) - { - if (u == 1) - { - tmp[Slen + 0] = (i & 0xff000000) >> 24; - tmp[Slen + 1] = (i & 0x00ff0000) >> 16; - tmp[Slen + 2] = (i & 0x0000ff00) >> 8; - tmp[Slen + 3] = (i & 0x000000ff) >> 0; - - rc = gc_hmac_sha1 (P, Plen, tmp, tmplen, U); - } - else - rc = gc_hmac_sha1 (P, Plen, U, hLen, U); - - if (rc != GC_OK) - { - free (tmp); - return rc; - } - - for (k = 0; k < hLen; k++) - T[k] ^= U[k]; - } + { + if (u == 1) + { + tmp[Slen + 0] = (i & 0xff000000) >> 24; + tmp[Slen + 1] = (i & 0x00ff0000) >> 16; + tmp[Slen + 2] = (i & 0x0000ff00) >> 8; + tmp[Slen + 3] = (i & 0x000000ff) >> 0; + + rc = gc_hmac_sha1 (P, Plen, tmp, tmplen, U); + } + else + rc = gc_hmac_sha1 (P, Plen, U, hLen, U); + + if (rc != GC_OK) + { + free (tmp); + return rc; + } + + for (k = 0; k < hLen; k++) + T[k] ^= U[k]; + } memcpy (DK + (i - 1) * hLen, T, i == l ? r : hLen); } diff --git a/lib/gc.h b/lib/gc.h index 35d3f8a41..03d27c17e 100644 --- a/lib/gc.h +++ b/lib/gc.h @@ -107,10 +107,10 @@ typedef int (*gc_secure_check_t) (const void *); typedef void *(*gc_realloc_t) (void *p, size_t n); typedef void (*gc_free_t) (void *); extern void gc_set_allocators (gc_malloc_t func_malloc, - gc_malloc_t secure_malloc, - gc_secure_check_t secure_check, - gc_realloc_t func_realloc, - gc_free_t func_free); + gc_malloc_t secure_malloc, + gc_secure_check_t secure_check, + gc_realloc_t func_realloc, + gc_free_t func_free); /* Randomness. */ extern Gc_rc gc_nonce (char *data, size_t datalen); @@ -119,27 +119,27 @@ extern Gc_rc gc_random (char *data, size_t datalen); /* Ciphers. */ extern Gc_rc gc_cipher_open (Gc_cipher cipher, Gc_cipher_mode mode, - gc_cipher_handle *outhandle); + gc_cipher_handle *outhandle); extern Gc_rc gc_cipher_setkey (gc_cipher_handle handle, - size_t keylen, const char *key); + size_t keylen, const char *key); extern Gc_rc gc_cipher_setiv (gc_cipher_handle handle, - size_t ivlen, const char *iv); + size_t ivlen, const char *iv); extern Gc_rc gc_cipher_encrypt_inline (gc_cipher_handle handle, - size_t len, char *data); + size_t len, char *data); extern Gc_rc gc_cipher_decrypt_inline (gc_cipher_handle handle, - size_t len, char *data); + size_t len, char *data); extern Gc_rc gc_cipher_close (gc_cipher_handle handle); /* Hashes. */ extern Gc_rc gc_hash_open (Gc_hash hash, Gc_hash_mode mode, - gc_hash_handle *outhandle); + gc_hash_handle *outhandle); extern Gc_rc gc_hash_clone (gc_hash_handle handle, gc_hash_handle *outhandle); extern size_t gc_hash_digest_length (Gc_hash hash); extern void gc_hash_hmac_setkey (gc_hash_handle handle, - size_t len, const char *key); + size_t len, const char *key); extern void gc_hash_write (gc_hash_handle handle, - size_t len, const char *data); + size_t len, const char *data); extern const char *gc_hash_read (gc_hash_handle handle); extern void gc_hash_close (gc_hash_handle handle); @@ -158,9 +158,9 @@ extern Gc_rc gc_md4 (const void *in, size_t inlen, void *resbuf); extern Gc_rc gc_md5 (const void *in, size_t inlen, void *resbuf); extern Gc_rc gc_sha1 (const void *in, size_t inlen, void *resbuf); extern Gc_rc gc_hmac_md5 (const void *key, size_t keylen, - const void *in, size_t inlen, char *resbuf); + const void *in, size_t inlen, char *resbuf); extern Gc_rc gc_hmac_sha1 (const void *key, size_t keylen, - const void *in, size_t inlen, char *resbuf); + const void *in, size_t inlen, char *resbuf); /* Derive cryptographic keys from a password P of length PLEN, with salt S of length SLEN, placing the result in pre-allocated buffer @@ -171,8 +171,8 @@ extern Gc_rc gc_hmac_sha1 (const void *key, size_t keylen, an Gc_rc error code is returned. */ extern Gc_rc gc_pbkdf2_sha1 (const char *P, size_t Plen, - const char *S, size_t Slen, - unsigned int c, char *DK, size_t dkLen); + const char *S, size_t Slen, + unsigned int c, char *DK, size_t dkLen); /* TODO: diff --git a/lib/gcd.c b/lib/gcd.c index 3562de56d..b288ea564 100644 --- a/lib/gcd.c +++ b/lib/gcd.c @@ -47,39 +47,39 @@ GCD (WORD_T a, WORD_T b) if (a & c) { if (b & c) - goto odd_odd; + goto odd_odd; else - goto odd_even; + goto odd_even; } else { if (b & c) - goto even_odd; + goto even_odd; else - abort (); + abort (); } for (;;) { odd_odd: /* a/c and b/c both odd */ if (a == b) - break; + break; if (a > b) - { - a = a - b; - even_odd: /* a/c even, b/c odd */ - do - a = a >> 1; - while ((a & c) == 0); - } + { + a = a - b; + even_odd: /* a/c even, b/c odd */ + do + a = a >> 1; + while ((a & c) == 0); + } else - { - b = b - a; - odd_even: /* a/c odd, b/c even */ - do - b = b >> 1; - while ((b & c) == 0); - } + { + b = b - a; + odd_even: /* a/c odd, b/c even */ + do + b = b >> 1; + while ((b & c) == 0); + } } /* a = b */ diff --git a/lib/gen-uni-tables.c b/lib/gen-uni-tables.c index 94752b251..467fa5506 100644 --- a/lib/gen-uni-tables.c +++ b/lib/gen-uni-tables.c @@ -74,13 +74,13 @@ struct unicode_attribute unicode_attributes [0x110000]; /* Stores in unicode_attributes[i] the values from the given fields. */ static void fill_attribute (unsigned int i, - const char *field1, const char *field2, - const char *field3, const char *field4, - const char *field5, const char *field6, - const char *field7, const char *field8, - const char *field9, const char *field10, - const char *field11, const char *field12, - const char *field13, const char *field14) + const char *field1, const char *field2, + const char *field3, const char *field4, + const char *field5, const char *field6, + const char *field7, const char *field8, + const char *field9, const char *field10, + const char *field11, const char *field12, + const char *field13, const char *field14) { struct unicode_attribute * uni; @@ -125,16 +125,16 @@ getfield (FILE *stream, char *buffer, int delim) for (; (c = getc (stream)), (c != EOF && c != delim); ) { /* The original unicode.org UnicodeData.txt file happens to have - CR/LF line terminators. Silently convert to LF. */ + CR/LF line terminators. Silently convert to LF. */ if (c == '\r') - continue; + continue; /* Put c into the buffer. */ if (++count >= FIELDLEN - 1) - { - fprintf (stderr, "field longer than expected, increase FIELDLEN\n"); - exit (1); - } + { + fprintf (stderr, "field longer than expected, increase FIELDLEN\n"); + exit (1); + } *buffer++ = c; } @@ -200,63 +200,63 @@ fill_attributes (const char *unicodedata_filename) n += getfield (stream, field13, ';'); n += getfield (stream, field14, '\n'); if (n == 0) - break; + break; if (n != 15) - { - fprintf (stderr, "short line in '%s':%d\n", - unicodedata_filename, lineno); - exit (1); - } + { + fprintf (stderr, "short line in '%s':%d\n", + unicodedata_filename, lineno); + exit (1); + } i = strtoul (field0, NULL, 16); if (field1[0] == '<' - && strlen (field1) >= 9 - && strcmp (field1 + strlen(field1) - 8, ", First>") == 0) - { - /* Deal with a range. */ - lineno++; - n = getfield (stream, field0, ';'); - n += getfield (stream, field1, ';'); - n += getfield (stream, field2, ';'); - n += getfield (stream, field3, ';'); - n += getfield (stream, field4, ';'); - n += getfield (stream, field5, ';'); - n += getfield (stream, field6, ';'); - n += getfield (stream, field7, ';'); - n += getfield (stream, field8, ';'); - n += getfield (stream, field9, ';'); - n += getfield (stream, field10, ';'); - n += getfield (stream, field11, ';'); - n += getfield (stream, field12, ';'); - n += getfield (stream, field13, ';'); - n += getfield (stream, field14, '\n'); - if (n != 15) - { - fprintf (stderr, "missing end range in '%s':%d\n", - unicodedata_filename, lineno); - exit (1); - } - if (!(field1[0] == '<' - && strlen (field1) >= 8 - && strcmp (field1 + strlen (field1) - 7, ", Last>") == 0)) - { - fprintf (stderr, "missing end range in '%s':%d\n", - unicodedata_filename, lineno); - exit (1); - } - field1[strlen (field1) - 7] = '\0'; - j = strtoul (field0, NULL, 16); - for (; i <= j; i++) - fill_attribute (i, field1+1, field2, field3, field4, field5, - field6, field7, field8, field9, field10, - field11, field12, field13, field14); - } + && strlen (field1) >= 9 + && strcmp (field1 + strlen(field1) - 8, ", First>") == 0) + { + /* Deal with a range. */ + lineno++; + n = getfield (stream, field0, ';'); + n += getfield (stream, field1, ';'); + n += getfield (stream, field2, ';'); + n += getfield (stream, field3, ';'); + n += getfield (stream, field4, ';'); + n += getfield (stream, field5, ';'); + n += getfield (stream, field6, ';'); + n += getfield (stream, field7, ';'); + n += getfield (stream, field8, ';'); + n += getfield (stream, field9, ';'); + n += getfield (stream, field10, ';'); + n += getfield (stream, field11, ';'); + n += getfield (stream, field12, ';'); + n += getfield (stream, field13, ';'); + n += getfield (stream, field14, '\n'); + if (n != 15) + { + fprintf (stderr, "missing end range in '%s':%d\n", + unicodedata_filename, lineno); + exit (1); + } + if (!(field1[0] == '<' + && strlen (field1) >= 8 + && strcmp (field1 + strlen (field1) - 7, ", Last>") == 0)) + { + fprintf (stderr, "missing end range in '%s':%d\n", + unicodedata_filename, lineno); + exit (1); + } + field1[strlen (field1) - 7] = '\0'; + j = strtoul (field0, NULL, 16); + for (; i <= j; i++) + fill_attribute (i, field1+1, field2, field3, field4, field5, + field6, field7, field8, field9, field10, + field11, field12, field13, field14); + } else - { - /* Single character line */ - fill_attribute (i, field1, field2, field3, field4, field5, - field6, field7, field8, field9, field10, - field11, field12, field13, field14); - } + { + /* Single character line */ + fill_attribute (i, field1, field2, field3, field4, field5, + field6, field7, field8, field9, field10, + field11, field12, field13, field14); + } } if (ferror (stream) || fclose (stream)) { @@ -275,265 +275,265 @@ static bool is_category_L (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'L'); + && unicode_attributes[ch].category[0] == 'L'); } static bool is_category_Lu (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'L' - && unicode_attributes[ch].category[1] == 'u'); + && unicode_attributes[ch].category[0] == 'L' + && unicode_attributes[ch].category[1] == 'u'); } static bool is_category_Ll (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'L' - && unicode_attributes[ch].category[1] == 'l'); + && unicode_attributes[ch].category[0] == 'L' + && unicode_attributes[ch].category[1] == 'l'); } static bool is_category_Lt (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'L' - && unicode_attributes[ch].category[1] == 't'); + && unicode_attributes[ch].category[0] == 'L' + && unicode_attributes[ch].category[1] == 't'); } static bool is_category_Lm (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'L' - && unicode_attributes[ch].category[1] == 'm'); + && unicode_attributes[ch].category[0] == 'L' + && unicode_attributes[ch].category[1] == 'm'); } static bool is_category_Lo (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'L' - && unicode_attributes[ch].category[1] == 'o'); + && unicode_attributes[ch].category[0] == 'L' + && unicode_attributes[ch].category[1] == 'o'); } static bool is_category_M (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'M'); + && unicode_attributes[ch].category[0] == 'M'); } static bool is_category_Mn (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'M' - && unicode_attributes[ch].category[1] == 'n'); + && unicode_attributes[ch].category[0] == 'M' + && unicode_attributes[ch].category[1] == 'n'); } static bool is_category_Mc (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'M' - && unicode_attributes[ch].category[1] == 'c'); + && unicode_attributes[ch].category[0] == 'M' + && unicode_attributes[ch].category[1] == 'c'); } static bool is_category_Me (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'M' - && unicode_attributes[ch].category[1] == 'e'); + && unicode_attributes[ch].category[0] == 'M' + && unicode_attributes[ch].category[1] == 'e'); } static bool is_category_N (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'N'); + && unicode_attributes[ch].category[0] == 'N'); } static bool is_category_Nd (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'N' - && unicode_attributes[ch].category[1] == 'd'); + && unicode_attributes[ch].category[0] == 'N' + && unicode_attributes[ch].category[1] == 'd'); } static bool is_category_Nl (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'N' - && unicode_attributes[ch].category[1] == 'l'); + && unicode_attributes[ch].category[0] == 'N' + && unicode_attributes[ch].category[1] == 'l'); } static bool is_category_No (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'N' - && unicode_attributes[ch].category[1] == 'o'); + && unicode_attributes[ch].category[0] == 'N' + && unicode_attributes[ch].category[1] == 'o'); } static bool is_category_P (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P'); + && unicode_attributes[ch].category[0] == 'P'); } static bool is_category_Pc (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 'c'); + && unicode_attributes[ch].category[0] == 'P' + && unicode_attributes[ch].category[1] == 'c'); } static bool is_category_Pd (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 'd'); + && unicode_attributes[ch].category[0] == 'P' + && unicode_attributes[ch].category[1] == 'd'); } static bool is_category_Ps (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 's'); + && unicode_attributes[ch].category[0] == 'P' + && unicode_attributes[ch].category[1] == 's'); } static bool is_category_Pe (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 'e'); + && unicode_attributes[ch].category[0] == 'P' + && unicode_attributes[ch].category[1] == 'e'); } static bool is_category_Pi (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 'i'); + && unicode_attributes[ch].category[0] == 'P' + && unicode_attributes[ch].category[1] == 'i'); } static bool is_category_Pf (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 'f'); + && unicode_attributes[ch].category[0] == 'P' + && unicode_attributes[ch].category[1] == 'f'); } static bool is_category_Po (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 'o'); + && unicode_attributes[ch].category[0] == 'P' + && unicode_attributes[ch].category[1] == 'o'); } static bool is_category_S (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'S'); + && unicode_attributes[ch].category[0] == 'S'); } static bool is_category_Sm (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'S' - && unicode_attributes[ch].category[1] == 'm'); + && unicode_attributes[ch].category[0] == 'S' + && unicode_attributes[ch].category[1] == 'm'); } static bool is_category_Sc (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'S' - && unicode_attributes[ch].category[1] == 'c'); + && unicode_attributes[ch].category[0] == 'S' + && unicode_attributes[ch].category[1] == 'c'); } static bool is_category_Sk (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'S' - && unicode_attributes[ch].category[1] == 'k'); + && unicode_attributes[ch].category[0] == 'S' + && unicode_attributes[ch].category[1] == 'k'); } static bool is_category_So (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'S' - && unicode_attributes[ch].category[1] == 'o'); + && unicode_attributes[ch].category[0] == 'S' + && unicode_attributes[ch].category[1] == 'o'); } static bool is_category_Z (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'Z'); + && unicode_attributes[ch].category[0] == 'Z'); } static bool is_category_Zs (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'Z' - && unicode_attributes[ch].category[1] == 's'); + && unicode_attributes[ch].category[0] == 'Z' + && unicode_attributes[ch].category[1] == 's'); } static bool is_category_Zl (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'Z' - && unicode_attributes[ch].category[1] == 'l'); + && unicode_attributes[ch].category[0] == 'Z' + && unicode_attributes[ch].category[1] == 'l'); } static bool is_category_Zp (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'Z' - && unicode_attributes[ch].category[1] == 'p'); + && unicode_attributes[ch].category[0] == 'Z' + && unicode_attributes[ch].category[1] == 'p'); } static bool is_category_C (unsigned int ch) { return (unicode_attributes[ch].name == NULL - || unicode_attributes[ch].category[0] == 'C'); + || unicode_attributes[ch].category[0] == 'C'); } static bool is_category_Cc (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'C' - && unicode_attributes[ch].category[1] == 'c'); + && unicode_attributes[ch].category[0] == 'C' + && unicode_attributes[ch].category[1] == 'c'); } static bool is_category_Cf (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'C' - && unicode_attributes[ch].category[1] == 'f'); + && unicode_attributes[ch].category[0] == 'C' + && unicode_attributes[ch].category[1] == 'f'); } static bool @@ -546,15 +546,15 @@ static bool is_category_Co (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'C' - && unicode_attributes[ch].category[1] == 'o'); + && unicode_attributes[ch].category[0] == 'C' + && unicode_attributes[ch].category[1] == 'o'); } static bool is_category_Cn (unsigned int ch) { return (unicode_attributes[ch].name == NULL - && !(ch >= 0xd800 && ch < 0xe000)); + && !(ch >= 0xd800 && ch < 0xe000)); } /* Output a boolean property in a human readable format. */ @@ -575,22 +575,22 @@ debug_output_predicate (const char *filename, bool (*predicate) (unsigned int)) for (ch = 0; ch < 0x110000; ch++) if (predicate (ch)) { - fprintf (stream, "0x%04X\n", ch); + fprintf (stream, "0x%04X\n", ch); } #else for (ch = 0; ch < 0x110000; ch++) if (predicate (ch)) { - unsigned int first = ch; - unsigned int last; - - while (ch + 1 < 0x110000 && predicate (ch + 1)) - ch++; - last = ch; - if (first < last) - fprintf (stream, "0x%04X..0x%04X\n", first, last); - else - fprintf (stream, "0x%04X\n", ch); + unsigned int first = ch; + unsigned int last; + + while (ch + 1 < 0x110000 && predicate (ch + 1)) + ch++; + last = ch; + if (first < last) + fprintf (stream, "0x%04X..0x%04X\n", first, last); + else + fprintf (stream, "0x%04X\n", ch); } #endif @@ -640,16 +640,16 @@ output_predicate_test (const char *filename, bool (*predicate) (unsigned int), c for (ch = 0; ch < 0x110000; ch++) if (predicate (ch)) { - unsigned int first = ch; - unsigned int last; - - while (ch + 1 < 0x110000 && predicate (ch + 1)) - ch++; - last = ch; - if (need_comma) - fprintf (stream, ",\n"); - fprintf (stream, " { 0x%04X, 0x%04X }", first, last); - need_comma = true; + unsigned int first = ch; + unsigned int last; + + while (ch + 1 < 0x110000 && predicate (ch + 1)) + ch++; + last = ch; + if (need_comma) + fprintf (stream, ",\n"); + fprintf (stream, " { 0x%04X, 0x%04X }", first, last); + need_comma = true; } if (need_comma) fprintf (stream, "\n"); @@ -690,7 +690,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* %s of Unicode characters. */\n", comment); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 4; /* or: 5 */ t.q = 7; /* or: 6 */ @@ -716,7 +716,7 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const for (i = 0; i < 5; i++) if (i != 1) fprintf (stream, "#define header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); @@ -736,13 +736,13 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const { uint32_t offset; if (i > 0 && (i % 1) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu * sizeof (int) / sizeof (short) + %5zu", - 1 + t.level1_size, (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu * sizeof (int) / sizeof (short) + %5zu", + 1 + t.level1_size, (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) fprintf (stream, ","); } @@ -756,15 +756,15 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const { uint32_t offset; if (i > 0 && (i % 1) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu + %5zu * sizeof (short) / sizeof (int) + %5zu", - 1 + t.level1_size, t.level2_size << t.q, (offset - level3_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu + %5zu * sizeof (short) / sizeof (int) + %5zu", + 1 + t.level1_size, t.level2_size << t.q, (offset - level3_offset) / sizeof (uint32_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 1) fprintf (stream, "\n "); @@ -775,11 +775,11 @@ output_predicate (const char *filename, bool (*predicate) (unsigned int), const for (i = 0; i < t.level3_size << t.p; i++) { if (i > 0 && (i % 4) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " 0x%08X", - ((uint32_t *) (t.result + level3_offset))[i]); + ((uint32_t *) (t.result + level3_offset))[i]); if (i+1 < t.level3_size << t.p) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level3_size << t.p > 4) fprintf (stream, "\n "); @@ -890,77 +890,77 @@ general_category_byname (const char *category_name) switch (category_name[0]) { case 'L': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_MASK_L; - case 'u': return UC_CATEGORY_MASK_Lu; - case 'l': return UC_CATEGORY_MASK_Ll; - case 't': return UC_CATEGORY_MASK_Lt; - case 'm': return UC_CATEGORY_MASK_Lm; - case 'o': return UC_CATEGORY_MASK_Lo; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_MASK_L; + case 'u': return UC_CATEGORY_MASK_Lu; + case 'l': return UC_CATEGORY_MASK_Ll; + case 't': return UC_CATEGORY_MASK_Lt; + case 'm': return UC_CATEGORY_MASK_Lm; + case 'o': return UC_CATEGORY_MASK_Lo; + } + break; case 'M': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_MASK_M; - case 'n': return UC_CATEGORY_MASK_Mn; - case 'c': return UC_CATEGORY_MASK_Mc; - case 'e': return UC_CATEGORY_MASK_Me; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_MASK_M; + case 'n': return UC_CATEGORY_MASK_Mn; + case 'c': return UC_CATEGORY_MASK_Mc; + case 'e': return UC_CATEGORY_MASK_Me; + } + break; case 'N': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_MASK_N; - case 'd': return UC_CATEGORY_MASK_Nd; - case 'l': return UC_CATEGORY_MASK_Nl; - case 'o': return UC_CATEGORY_MASK_No; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_MASK_N; + case 'd': return UC_CATEGORY_MASK_Nd; + case 'l': return UC_CATEGORY_MASK_Nl; + case 'o': return UC_CATEGORY_MASK_No; + } + break; case 'P': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_MASK_P; - case 'c': return UC_CATEGORY_MASK_Pc; - case 'd': return UC_CATEGORY_MASK_Pd; - case 's': return UC_CATEGORY_MASK_Ps; - case 'e': return UC_CATEGORY_MASK_Pe; - case 'i': return UC_CATEGORY_MASK_Pi; - case 'f': return UC_CATEGORY_MASK_Pf; - case 'o': return UC_CATEGORY_MASK_Po; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_MASK_P; + case 'c': return UC_CATEGORY_MASK_Pc; + case 'd': return UC_CATEGORY_MASK_Pd; + case 's': return UC_CATEGORY_MASK_Ps; + case 'e': return UC_CATEGORY_MASK_Pe; + case 'i': return UC_CATEGORY_MASK_Pi; + case 'f': return UC_CATEGORY_MASK_Pf; + case 'o': return UC_CATEGORY_MASK_Po; + } + break; case 'S': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_MASK_S; - case 'm': return UC_CATEGORY_MASK_Sm; - case 'c': return UC_CATEGORY_MASK_Sc; - case 'k': return UC_CATEGORY_MASK_Sk; - case 'o': return UC_CATEGORY_MASK_So; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_MASK_S; + case 'm': return UC_CATEGORY_MASK_Sm; + case 'c': return UC_CATEGORY_MASK_Sc; + case 'k': return UC_CATEGORY_MASK_Sk; + case 'o': return UC_CATEGORY_MASK_So; + } + break; case 'Z': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_MASK_Z; - case 's': return UC_CATEGORY_MASK_Zs; - case 'l': return UC_CATEGORY_MASK_Zl; - case 'p': return UC_CATEGORY_MASK_Zp; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_MASK_Z; + case 's': return UC_CATEGORY_MASK_Zs; + case 'l': return UC_CATEGORY_MASK_Zl; + case 'p': return UC_CATEGORY_MASK_Zp; + } + break; case 'C': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_MASK_C; - case 'c': return UC_CATEGORY_MASK_Cc; - case 'f': return UC_CATEGORY_MASK_Cf; - case 's': return UC_CATEGORY_MASK_Cs; - case 'o': return UC_CATEGORY_MASK_Co; - case 'n': return UC_CATEGORY_MASK_Cn; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_MASK_C; + case 'c': return UC_CATEGORY_MASK_Cc; + case 'f': return UC_CATEGORY_MASK_Cf; + case 's': return UC_CATEGORY_MASK_Cs; + case 'o': return UC_CATEGORY_MASK_Co; + case 'n': return UC_CATEGORY_MASK_Cn; + } + break; } /* Invalid category name. */ abort (); @@ -994,7 +994,7 @@ output_category (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Categories of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 7; t.q = 9; @@ -1006,15 +1006,15 @@ output_category (const char *filename, const char *version) unsigned int log2_value; if (is_category_Cs (ch)) - value = UC_CATEGORY_MASK_Cs; + value = UC_CATEGORY_MASK_Cs; else if (unicode_attributes[ch].name != NULL) - value = general_category_byname (unicode_attributes[ch].category); + value = general_category_byname (unicode_attributes[ch].category); else - continue; + continue; /* Now value should contain exactly one bit. */ if (value == 0 || ((value & (value - 1)) != 0)) - abort (); + abort (); for (log2_value = 0; value > 1; value >>= 1, log2_value++); @@ -1036,14 +1036,14 @@ output_category (const char *filename, const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define category_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); fprintf (stream, " int level1[%zu];\n", t.level1_size); fprintf (stream, " short level2[%zu << %d];\n", t.level2_size, t.q); fprintf (stream, " unsigned short level3[%zu * %d + 1];\n", t.level3_size, - (1 << t.p) * 5 / 16); + (1 << t.p) * 5 / 16); fprintf (stream, " }\n"); fprintf (stream, "u_category =\n"); fprintf (stream, "{\n"); @@ -1054,15 +1054,15 @@ output_category (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -1074,15 +1074,15 @@ output_category (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -1107,10 +1107,10 @@ output_category (const char *filename, const char *version) for (i = 0; i < (t.level3_size << t.p) * 5 / 16 + 1; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " 0x%04x", level3_packed[i]); if (i+1 < (t.level3_size << t.p) * 5 / 16 + 1) - fprintf (stream, ","); + fprintf (stream, ","); } if ((t.level3_size << t.p) * 5 / 16 + 1 > 8) fprintf (stream, "\n "); @@ -1158,7 +1158,7 @@ output_combclass (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Combining class of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 7; t.q = 9; @@ -1167,10 +1167,10 @@ output_combclass (const char *filename, const char *version) for (ch = 0; ch < 0x110000; ch++) if (unicode_attributes[ch].name != NULL) { - int value = atoi (unicode_attributes[ch].combining); + int value = atoi (unicode_attributes[ch].combining); if (!(value >= 0 && value <= 255)) - abort (); - combclass_table_add (&t, ch, value); + abort (); + combclass_table_add (&t, ch, value); } combclass_table_finalize (&t); @@ -1188,7 +1188,7 @@ output_combclass (const char *filename, const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define combclass_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); @@ -1205,15 +1205,15 @@ output_combclass (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -1225,15 +1225,15 @@ output_combclass (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -1244,10 +1244,10 @@ output_combclass (const char *filename, const char *version) for (i = 0; i < t.level3_size << t.p; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " %3d", ((uint8_t *) (t.result + level3_offset))[i]); if (i+1 < t.level3_size << t.p) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level3_size << t.p > 8) fprintf (stream, "\n "); @@ -1297,143 +1297,143 @@ bidi_category_byname (const char *category_name) { case 'A': switch (category_name[1]) - { - case 'L': - if (category_name[2] == '\0') - return UC_BIDI_AL; - break; - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_AN; - break; - } + { + case 'L': + if (category_name[2] == '\0') + return UC_BIDI_AL; + break; + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_AN; + break; + } break; case 'B': switch (category_name[1]) - { - case '\0': - return UC_BIDI_B; - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_BN; - break; - } + { + case '\0': + return UC_BIDI_B; + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_BN; + break; + } break; case 'C': switch (category_name[1]) - { - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_CS; - break; - } + { + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_CS; + break; + } break; case 'E': switch (category_name[1]) - { - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_EN; - break; - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_ES; - break; - case 'T': - if (category_name[2] == '\0') - return UC_BIDI_ET; - break; - } + { + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_EN; + break; + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_ES; + break; + case 'T': + if (category_name[2] == '\0') + return UC_BIDI_ET; + break; + } break; case 'L': switch (category_name[1]) - { - case '\0': - return UC_BIDI_L; - case 'R': - switch (category_name[2]) - { - case 'E': - if (category_name[3] == '\0') - return UC_BIDI_LRE; - break; - case 'O': - if (category_name[3] == '\0') - return UC_BIDI_LRO; - break; - } - break; - } + { + case '\0': + return UC_BIDI_L; + case 'R': + switch (category_name[2]) + { + case 'E': + if (category_name[3] == '\0') + return UC_BIDI_LRE; + break; + case 'O': + if (category_name[3] == '\0') + return UC_BIDI_LRO; + break; + } + break; + } break; case 'N': switch (category_name[1]) - { - case 'S': - switch (category_name[2]) - { - case 'M': - if (category_name[3] == '\0') - return UC_BIDI_NSM; - break; - } - break; - } + { + case 'S': + switch (category_name[2]) + { + case 'M': + if (category_name[3] == '\0') + return UC_BIDI_NSM; + break; + } + break; + } break; case 'O': switch (category_name[1]) - { - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_ON; - break; - } + { + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_ON; + break; + } break; case 'P': switch (category_name[1]) - { - case 'D': - switch (category_name[2]) - { - case 'F': - if (category_name[3] == '\0') - return UC_BIDI_PDF; - break; - } - break; - } + { + case 'D': + switch (category_name[2]) + { + case 'F': + if (category_name[3] == '\0') + return UC_BIDI_PDF; + break; + } + break; + } break; case 'R': switch (category_name[1]) - { - case '\0': - return UC_BIDI_R; - case 'L': - switch (category_name[2]) - { - case 'E': - if (category_name[3] == '\0') - return UC_BIDI_RLE; - break; - case 'O': - if (category_name[3] == '\0') - return UC_BIDI_RLO; - break; - } - break; - } + { + case '\0': + return UC_BIDI_R; + case 'L': + switch (category_name[2]) + { + case 'E': + if (category_name[3] == '\0') + return UC_BIDI_RLE; + break; + case 'O': + if (category_name[3] == '\0') + return UC_BIDI_RLO; + break; + } + break; + } break; case 'S': if (category_name[1] == '\0') - return UC_BIDI_S; + return UC_BIDI_S; break; case 'W': switch (category_name[1]) - { - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_WS; - break; - } + { + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_WS; + break; + } break; } /* Invalid bidi category name. */ @@ -1448,25 +1448,25 @@ get_bidi_category (unsigned int ch) else { /* The bidi category of unassigned characters depends on the range. - See UTR #9 and DerivedBidiClass.txt. */ + See UTR #9 and DerivedBidiClass.txt. */ if ((ch >= 0x0590 && ch <= 0x05FF) - || (ch >= 0x07FB && ch <= 0x08FF) - || (ch >= 0xFB37 && ch <= 0xFB45) - || (ch >= 0x10800 && ch <= 0x10FFF)) - return UC_BIDI_R; + || (ch >= 0x07FB && ch <= 0x08FF) + || (ch >= 0xFB37 && ch <= 0xFB45) + || (ch >= 0x10800 && ch <= 0x10FFF)) + return UC_BIDI_R; else if ((ch >= 0x0600 && ch <= 0x07BF) - || (ch >= 0x2064 && ch <= 0x2069) - || (ch >= 0xFBB2 && ch <= 0xFDCF) - || (ch >= 0xFDFE && ch <= 0xFEFE)) - return UC_BIDI_AL; + || (ch >= 0x2064 && ch <= 0x2069) + || (ch >= 0xFBB2 && ch <= 0xFDCF) + || (ch >= 0xFDFE && ch <= 0xFEFE)) + return UC_BIDI_AL; else if ((ch >= 0xFDD0 && ch <= 0xFDEF) - || (ch >= 0xFFF0 && ch <= 0xFFFF) - || (ch & 0xFFFF) == 0xFFFE - || (ch & 0xFFFF) == 0xFFFF - || (ch >= 0xE0000 && ch <= 0xE0FFF)) - return UC_BIDI_BN; + || (ch >= 0xFFF0 && ch <= 0xFFFF) + || (ch & 0xFFFF) == 0xFFFE + || (ch & 0xFFFF) == 0xFFFF + || (ch >= 0xE0000 && ch <= 0xE0FFF)) + return UC_BIDI_BN; else - return UC_BIDI_L; + return UC_BIDI_L; } } @@ -1498,7 +1498,7 @@ output_bidi_category (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Bidi categories of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 7; t.q = 9; @@ -1526,14 +1526,14 @@ output_bidi_category (const char *filename, const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define bidi_category_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); fprintf (stream, " int level1[%zu];\n", t.level1_size); fprintf (stream, " short level2[%zu << %d];\n", t.level2_size, t.q); fprintf (stream, " unsigned short level3[%zu * %d + 1];\n", t.level3_size, - (1 << t.p) * 5 / 16); + (1 << t.p) * 5 / 16); fprintf (stream, " }\n"); fprintf (stream, "u_bidi_category =\n"); fprintf (stream, "{\n"); @@ -1544,15 +1544,15 @@ output_bidi_category (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -1564,15 +1564,15 @@ output_bidi_category (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -1597,10 +1597,10 @@ output_bidi_category (const char *filename, const char *version) for (i = 0; i < (t.level3_size << t.p) * 5 / 16 + 1; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " 0x%04x", level3_packed[i]); if (i+1 < (t.level3_size << t.p) * 5 / 16 + 1) - fprintf (stream, ","); + fprintf (stream, ","); } if ((t.level3_size << t.p) * 5 / 16 + 1 > 8) fprintf (stream, "\n "); @@ -1655,7 +1655,7 @@ output_decimal_digit_test (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Decimal digit values of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); need_comma = false; for (ch = 0; ch < 0x110000; ch++) @@ -1663,15 +1663,15 @@ output_decimal_digit_test (const char *filename, const char *version) int value = get_decdigit_value (ch); if (!(value >= -1 && value < 10)) - abort (); + abort (); if (value >= 0) - { - if (need_comma) - fprintf (stream, ",\n"); - fprintf (stream, " { 0x%04X, %d }", ch, value); - need_comma = true; - } + { + if (need_comma) + fprintf (stream, ",\n"); + fprintf (stream, " { 0x%04X, %d }", ch, value); + need_comma = true; + } } if (need_comma) fprintf (stream, "\n"); @@ -1702,7 +1702,7 @@ output_decimal_digit (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Decimal digit values of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 7; t.q = 9; @@ -1713,7 +1713,7 @@ output_decimal_digit (const char *filename, const char *version) int value = 1 + get_decdigit_value (ch); if (!(value >= 0 && value <= 10)) - abort (); + abort (); decdigit_table_add (&t, ch, value); } @@ -1733,14 +1733,14 @@ output_decimal_digit (const char *filename, const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define decdigit_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); fprintf (stream, " int level1[%zu];\n", t.level1_size); fprintf (stream, " short level2[%zu << %d];\n", t.level2_size, t.q); fprintf (stream, " unsigned char level3[%zu << %d];\n", t.level3_size, - t.p - 1); + t.p - 1); fprintf (stream, " }\n"); fprintf (stream, "u_decdigit =\n"); fprintf (stream, "{\n"); @@ -1751,15 +1751,15 @@ output_decimal_digit (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -1771,15 +1771,15 @@ output_decimal_digit (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -1791,12 +1791,12 @@ output_decimal_digit (const char *filename, const char *version) for (i = 0; i < t.level3_size << (t.p - 1); i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " 0x%02x", - ((uint8_t *) (t.result + level3_offset))[2*i] - + (((uint8_t *) (t.result + level3_offset))[2*i+1] << 4)); + ((uint8_t *) (t.result + level3_offset))[2*i] + + (((uint8_t *) (t.result + level3_offset))[2*i+1] << 4)); if (i+1 < t.level3_size << (t.p - 1)) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level3_size << (t.p - 1) > 8) fprintf (stream, "\n "); @@ -1842,7 +1842,7 @@ output_digit_test (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Digit values of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); need_comma = false; for (ch = 0; ch < 0x110000; ch++) @@ -1850,15 +1850,15 @@ output_digit_test (const char *filename, const char *version) int value = get_digit_value (ch); if (!(value >= -1 && value < 10)) - abort (); + abort (); if (value >= 0) - { - if (need_comma) - fprintf (stream, ",\n"); - fprintf (stream, " { 0x%04X, %d }", ch, value); - need_comma = true; - } + { + if (need_comma) + fprintf (stream, ",\n"); + fprintf (stream, " { 0x%04X, %d }", ch, value); + need_comma = true; + } } if (need_comma) fprintf (stream, "\n"); @@ -1889,7 +1889,7 @@ output_digit (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Digit values of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 7; t.q = 9; @@ -1900,7 +1900,7 @@ output_digit (const char *filename, const char *version) int value = 1 + get_digit_value (ch); if (!(value >= 0 && value <= 10)) - abort (); + abort (); decdigit_table_add (&t, ch, value); } @@ -1920,14 +1920,14 @@ output_digit (const char *filename, const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define digit_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); fprintf (stream, " int level1[%zu];\n", t.level1_size); fprintf (stream, " short level2[%zu << %d];\n", t.level2_size, t.q); fprintf (stream, " unsigned char level3[%zu << %d];\n", t.level3_size, - t.p - 1); + t.p - 1); fprintf (stream, " }\n"); fprintf (stream, "u_digit =\n"); fprintf (stream, "{\n"); @@ -1938,15 +1938,15 @@ output_digit (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -1958,15 +1958,15 @@ output_digit (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -1978,12 +1978,12 @@ output_digit (const char *filename, const char *version) for (i = 0; i < t.level3_size << (t.p - 1); i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " 0x%02x", - ((uint8_t *) (t.result + level3_offset))[2*i] - + (((uint8_t *) (t.result + level3_offset))[2*i+1] << 4)); + ((uint8_t *) (t.result + level3_offset))[2*i] + + (((uint8_t *) (t.result + level3_offset))[2*i+1] << 4)); if (i+1 < t.level3_size << (t.p - 1)) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level3_size << (t.p - 1) > 8) fprintf (stream, "\n "); @@ -2016,9 +2016,9 @@ get_numeric_value (unsigned int ch) /* str is of the form "integer" or "integer/posinteger". */ value.numerator = atoi (str); if (strchr (str, '/') != NULL) - value.denominator = atoi (strchr (str, '/') + 1); + value.denominator = atoi (strchr (str, '/') + 1); else - value.denominator = 1; + value.denominator = 1; } else { @@ -2046,7 +2046,7 @@ output_numeric_test (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Numeric values of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); need_comma = false; for (ch = 0; ch < 0x110000; ch++) @@ -2054,13 +2054,13 @@ output_numeric_test (const char *filename, const char *version) uc_fraction_t value = get_numeric_value (ch); if (value.numerator != 0 || value.denominator != 0) - { - if (need_comma) - fprintf (stream, ",\n"); - fprintf (stream, " { 0x%04X, %d, %d }", - ch, value.numerator, value.denominator); - need_comma = true; - } + { + if (need_comma) + fprintf (stream, ",\n"); + fprintf (stream, " { 0x%04X, %d, %d }", + ch, value.numerator, value.denominator); + need_comma = true; + } } if (need_comma) fprintf (stream, "\n"); @@ -2102,7 +2102,7 @@ output_numeric (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Numeric values of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); /* Create table of occurring fractions. */ nfractions = 0; @@ -2111,34 +2111,34 @@ output_numeric (const char *filename, const char *version) uc_fraction_t value = get_numeric_value (ch); for (i = 0; i < nfractions; i++) - if (value.numerator == fractions[i].numerator - && value.denominator == fractions[i].denominator) - break; + if (value.numerator == fractions[i].numerator + && value.denominator == fractions[i].denominator) + break; if (i == nfractions) - { - if (nfractions == 128) - abort (); - for (i = 0; i < nfractions; i++) - if (value.denominator < fractions[i].denominator - || (value.denominator == fractions[i].denominator - && value.numerator < fractions[i].numerator)) - break; - for (j = nfractions; j > i; j--) - fractions[j] = fractions[j - 1]; - fractions[i] = value; - nfractions++; - } + { + if (nfractions == 128) + abort (); + for (i = 0; i < nfractions; i++) + if (value.denominator < fractions[i].denominator + || (value.denominator == fractions[i].denominator + && value.numerator < fractions[i].numerator)) + break; + for (j = nfractions; j > i; j--) + fractions[j] = fractions[j - 1]; + fractions[i] = value; + nfractions++; + } } fprintf (stream, "static const uc_fraction_t u_numeric_values[%d] =\n", - nfractions); + nfractions); fprintf (stream, "{\n"); for (i = 0; i < nfractions; i++) { fprintf (stream, " { %d, %d }", fractions[i].numerator, - fractions[i].denominator); + fractions[i].denominator); if (i+1 < nfractions) - fprintf (stream, ","); + fprintf (stream, ","); fprintf (stream, "\n"); } fprintf (stream, "};\n"); @@ -2152,11 +2152,11 @@ output_numeric (const char *filename, const char *version) uc_fraction_t value = get_numeric_value (ch); for (i = 0; i < nfractions; i++) - if (value.numerator == fractions[i].numerator - && value.denominator == fractions[i].denominator) - break; + if (value.numerator == fractions[i].numerator + && value.denominator == fractions[i].denominator) + break; if (i == nfractions) - abort (); + abort (); numeric_table_add (&t, ch, i); } @@ -2176,14 +2176,14 @@ output_numeric (const char *filename, const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define numeric_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); fprintf (stream, " int level1[%zu];\n", t.level1_size); fprintf (stream, " short level2[%zu << %d];\n", t.level2_size, t.q); fprintf (stream, " unsigned short level3[%zu * %d + 1];\n", t.level3_size, - (1 << t.p) * 7 / 16); + (1 << t.p) * 7 / 16); fprintf (stream, " }\n"); fprintf (stream, "u_numeric =\n"); fprintf (stream, "{\n"); @@ -2194,15 +2194,15 @@ output_numeric (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -2214,15 +2214,15 @@ output_numeric (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -2247,10 +2247,10 @@ output_numeric (const char *filename, const char *version) for (i = 0; i < (t.level3_size << t.p) * 7 / 16 + 1; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " 0x%04x", level3_packed[i]); if (i+1 < (t.level3_size << t.p) * 7 / 16 + 1) - fprintf (stream, ","); + fprintf (stream, ","); } if ((t.level3_size << t.p) * 7 / 16 + 1 > 8) fprintf (stream, "\n "); @@ -2337,25 +2337,25 @@ get_mirror_value (unsigned int ch) unsigned int i; mirrored = (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].mirrored); + && unicode_attributes[ch].mirrored); mirror_char = 0xfffd; for (i = 0; i < sizeof (mirror_pairs) / sizeof (mirror_pairs[0]); i++) if (ch == mirror_pairs[i][0]) { - mirror_char = mirror_pairs[i][1]; - break; + mirror_char = mirror_pairs[i][1]; + break; } else if (ch == mirror_pairs[i][1]) { - mirror_char = mirror_pairs[i][0]; - break; + mirror_char = mirror_pairs[i][0]; + break; } if (mirrored) return (int) mirror_char - (int) ch; else { if (mirror_char != 0xfffd) - abort (); + abort (); return 0; } } @@ -2387,7 +2387,7 @@ output_mirror (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Mirrored Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 7; t.q = 9; @@ -2415,7 +2415,7 @@ output_mirror (const char *filename, const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define mirror_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); @@ -2432,15 +2432,15 @@ output_mirror (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -2452,15 +2452,15 @@ output_mirror (const char *filename, const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (int32_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (int32_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -2471,10 +2471,10 @@ output_mirror (const char *filename, const char *version) for (i = 0; i < t.level3_size << t.p; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " %5d", ((int32_t *) (t.result + level3_offset))[i]); if (i+1 < t.level3_size << t.p) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level3_size << t.p > 8) fprintf (stream, "\n "); @@ -2577,20 +2577,20 @@ fill_properties (const char *proplist_filename) unsigned int propvalue; if (fscanf (stream, "%200[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; if (sscanf (buf, "%X..%X%[ ;]%[^ ]", &i1, &i2, padding, propname) != 4) - { - if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, propname) != 3) - { - fprintf (stderr, "parse error in '%s'\n", proplist_filename); - exit (1); - } - i2 = i1; - } + { + if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, propname) != 3) + { + fprintf (stderr, "parse error in '%s'\n", proplist_filename); + exit (1); + } + i2 = i1; + } #define PROP(name,value) \ if (strcmp (propname, name) == 0) propvalue = value; else /* PropList.txt */ @@ -2640,16 +2640,16 @@ fill_properties (const char *proplist_filename) PROP ("Grapheme_Base", PROP_GRAPHEME_BASE) PROP ("Grapheme_Link", PROP_GRAPHEME_LINK) #undef PROP - { - fprintf (stderr, "unknown property named '%s' in '%s'\n", propname, - proplist_filename); - exit (1); - } + { + fprintf (stderr, "unknown property named '%s' in '%s'\n", propname, + proplist_filename); + exit (1); + } if (!(i1 <= i2 && i2 < 0x110000)) - abort (); + abort (); for (i = i1; i <= i2; i++) - unicode_properties[i] |= 1ULL << propvalue; + unicode_properties[i] |= 1ULL << propvalue; } if (ferror (stream) || fclose (stream)) @@ -2682,10 +2682,10 @@ fill_property30 (char array[0x110000], const char *proplist_filename, const char do { if (fscanf (stream, "%100[^\n]\n", buf) < 1) - { - fprintf (stderr, "no property found in '%s'\n", proplist_filename); - exit (1); - } + { + fprintf (stderr, "no property found in '%s'\n", proplist_filename); + exit (1); + } } while (strstr (buf, property_name) == NULL); @@ -2694,38 +2694,38 @@ fill_property30 (char array[0x110000], const char *proplist_filename, const char unsigned int i1, i2; if (fscanf (stream, "%100[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '*') - break; + break; if (strlen (buf) >= 10 && buf[4] == '.' && buf[5] == '.') - { - if (sscanf (buf, "%4X..%4X", &i1, &i2) < 2) - { - fprintf (stderr, "parse error in property in '%s'\n", - proplist_filename); - exit (1); - } - } + { + if (sscanf (buf, "%4X..%4X", &i1, &i2) < 2) + { + fprintf (stderr, "parse error in property in '%s'\n", + proplist_filename); + exit (1); + } + } else if (strlen (buf) >= 4) - { - if (sscanf (buf, "%4X", &i1) < 1) - { - fprintf (stderr, "parse error in property in '%s'\n", - proplist_filename); - exit (1); - } - i2 = i1; - } + { + if (sscanf (buf, "%4X", &i1) < 1) + { + fprintf (stderr, "parse error in property in '%s'\n", + proplist_filename); + exit (1); + } + i2 = i1; + } else - { - fprintf (stderr, "parse error in property in '%s'\n", - proplist_filename); - exit (1); - } + { + fprintf (stderr, "parse error in property in '%s'\n", + proplist_filename); + exit (1); + } if (!(i1 <= i2 && i2 < 0x110000)) - abort (); + abort (); for (i = i1; i <= i2; i++) - array[i] = 1; + array[i] = 1; } if (ferror (stream) || fclose (stream)) { @@ -2856,8 +2856,8 @@ is_property_private_use (unsigned int ch) { /* Determined through "grep 'Private Use,' UnicodeData-3.1.0.txt". */ return (ch >= 0xE000 && ch <= 0xF8FF) - || (ch >= 0xF0000 && ch <= 0xFFFFD) - || (ch >= 0x100000 && ch <= 0x10FFFD); + || (ch >= 0xF0000 && ch <= 0xFFFFD) + || (ch >= 0x100000 && ch <= 0x10FFFD); } /* See PropList-3.0.1.txt. */ @@ -3129,7 +3129,7 @@ is_property_bidi_embedding_or_override (unsigned int ch) { int category = get_bidi_category (ch); return (category == UC_BIDI_LRE || category == UC_BIDI_LRO - || category == UC_BIDI_RLE || category == UC_BIDI_RLO); + || category == UC_BIDI_RLE || category == UC_BIDI_RLO); } /* See PropList-3.0.1.txt. */ @@ -3194,8 +3194,8 @@ static bool is_property_zero_width (unsigned int ch) { return is_category_Cf (ch) - || (unicode_attributes[ch].name != NULL - && strstr (unicode_attributes[ch].name, "ZERO WIDTH") != NULL); + || (unicode_attributes[ch].name != NULL + && strstr (unicode_attributes[ch].name, "ZERO WIDTH") != NULL); } /* See PropList-3.0.1.txt. */ @@ -3212,21 +3212,21 @@ is_property_non_break (unsigned int ch) /* This is exactly the set of characters having line breaking property GL. */ return (ch == 0x00A0 /* NO-BREAK SPACE */ - || ch == 0x034F /* COMBINING GRAPHEME JOINER */ - || ch == 0x035C /* COMBINING DOUBLE BREVE BELOW */ - || ch == 0x035D /* COMBINING DOUBLE BREVE */ - || ch == 0x035E /* COMBINING DOUBLE MACRON */ - || ch == 0x035F /* COMBINING DOUBLE MACRON BELOW */ - || ch == 0x0360 /* COMBINING DOUBLE TILDE */ - || ch == 0x0361 /* COMBINING DOUBLE INVERTED BREVE */ - || ch == 0x0362 /* COMBINING DOUBLE RIGHTWARDS ARROW BELOW */ - || ch == 0x0F08 /* TIBETAN MARK SBRUL SHAD */ - || ch == 0x0F0C /* TIBETAN MARK DELIMITER TSHEG BSTAR */ - || ch == 0x0F12 /* TIBETAN MARK RGYA GRAM SHAD */ - || ch == 0x180E /* MONGOLIAN VOWEL SEPARATOR */ - || ch == 0x2007 /* FIGURE SPACE */ - || ch == 0x2011 /* NON-BREAKING HYPHEN */ - || ch == 0x202F /* NARROW NO-BREAK SPACE */); + || ch == 0x034F /* COMBINING GRAPHEME JOINER */ + || ch == 0x035C /* COMBINING DOUBLE BREVE BELOW */ + || ch == 0x035D /* COMBINING DOUBLE BREVE */ + || ch == 0x035E /* COMBINING DOUBLE MACRON */ + || ch == 0x035F /* COMBINING DOUBLE MACRON BELOW */ + || ch == 0x0360 /* COMBINING DOUBLE TILDE */ + || ch == 0x0361 /* COMBINING DOUBLE INVERTED BREVE */ + || ch == 0x0362 /* COMBINING DOUBLE RIGHTWARDS ARROW BELOW */ + || ch == 0x0F08 /* TIBETAN MARK SBRUL SHAD */ + || ch == 0x0F0C /* TIBETAN MARK DELIMITER TSHEG BSTAR */ + || ch == 0x0F12 /* TIBETAN MARK RGYA GRAM SHAD */ + || ch == 0x180E /* MONGOLIAN VOWEL SEPARATOR */ + || ch == 0x2007 /* FIGURE SPACE */ + || ch == 0x2011 /* NON-BREAKING HYPHEN */ + || ch == 0x202F /* NARROW NO-BREAK SPACE */); } /* See PropList-3.0.1.txt. */ @@ -3249,9 +3249,9 @@ static bool is_property_format_control (unsigned int ch) { return (is_category_Cf (ch) - && get_bidi_category (ch) == UC_BIDI_BN - && !is_property_join_control (ch) - && ch != 0xFEFF); + && get_bidi_category (ch) == UC_BIDI_BN + && !is_property_join_control (ch) + && ch != 0xFEFF); } /* See PropList.txt, UCD.html. */ @@ -3360,10 +3360,10 @@ static bool is_property_combining (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && (strcmp (unicode_attributes[ch].combining, "0") != 0 - || is_category_Mc (ch) - || is_category_Me (ch) - || is_category_Mn (ch))); + && (strcmp (unicode_attributes[ch].combining, "0") != 0 + || is_category_Mc (ch) + || is_category_Me (ch) + || is_category_Mn (ch))); } #if 0 /* same as is_property_bidi_non_spacing_mark */ @@ -3372,7 +3372,7 @@ static bool is_property_non_spacing (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && get_bidi_category (ch) == UC_BIDI_NSM); + && get_bidi_category (ch) == UC_BIDI_NSM); } #endif @@ -3388,14 +3388,14 @@ is_property_composite (unsigned int ch) && unicode_attributes[ch].decomposition != NULL) { /* Test whether the decomposition contains more than one character, - and the first is not a space. */ + and the first is not a space. */ const char *decomp = unicode_attributes[ch].decomposition; if (decomp[0] == '<') - { - decomp = strchr (decomp, '>') + 1; - if (decomp[0] == ' ') - decomp++; - } + { + decomp = strchr (decomp, '>') + 1; + if (decomp[0] == ' ') + decomp++; + } return strchr (decomp, ' ') != NULL && strncmp (decomp, "0020 ", 5) != 0; } return false; @@ -3413,8 +3413,8 @@ static bool is_property_numeric (unsigned int ch) { return ((get_numeric_value (ch)).denominator > 0) - || (ch == 0x09F8) /* BENGALI CURRENCY NUMERATOR ONE LESS THAN THE DENOMINATOR */ - || (ch == 0x2183); /* ROMAN NUMERAL REVERSED ONE HUNDRED */ + || (ch == 0x09F8) /* BENGALI CURRENCY NUMERATOR ONE LESS THAN THE DENOMINATOR */ + || (ch == 0x2183); /* ROMAN NUMERAL REVERSED ONE HUNDRED */ } /* See PropList.txt, UCD.html. */ @@ -3436,8 +3436,8 @@ static bool is_property_ignorable_control (unsigned int ch) { return ((is_category_Cc (ch) && get_bidi_category (ch) == UC_BIDI_BN) - || is_category_Cf (ch)) - && ch != 0x0000; + || is_category_Cf (ch)) + && ch != 0x0000; } /* ------------------------------------------------------------------------- */ @@ -3568,43 +3568,43 @@ fill_scripts (const char *scripts_filename) int script; if (fscanf (stream, "%200[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; if (sscanf (buf, "%X..%X%[ ;]%[^ ]", &i1, &i2, padding, scriptname) != 4) - { - if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, scriptname) != 3) - { - fprintf (stderr, "parse error in '%s'\n", scripts_filename); - exit (1); - } - i2 = i1; - } + { + if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, scriptname) != 3) + { + fprintf (stderr, "parse error in '%s'\n", scripts_filename); + exit (1); + } + i2 = i1; + } if (i2 < i1) - abort (); + abort (); if (i2 >= 0x110000) - abort (); + abort (); for (script = numscripts - 1; script >= 0; script--) - if (strcmp (scripts[script], scriptname) == 0) - break; + if (strcmp (scripts[script], scriptname) == 0) + break; if (script < 0) - { - scripts[numscripts] = strdup (scriptname); - script = numscripts; - numscripts++; - if (numscripts == 256) - abort (); - } + { + scripts[numscripts] = strdup (scriptname); + script = numscripts; + numscripts++; + if (numscripts == 256) + abort (); + } for (i = i1; i <= i2; i++) - { - if (unicode_scripts[i] != (uint8_t)~(uint8_t)0) - fprintf (stderr, "0x%04X belongs to multiple scripts\n", i); - unicode_scripts[i] = script; - } + { + if (unicode_scripts[i] != (uint8_t)~(uint8_t)0) + fprintf (stderr, "0x%04X belongs to multiple scripts\n", i); + unicode_scripts[i] = script; + } } if (ferror (stream) || fclose (stream)) @@ -3648,7 +3648,7 @@ output_scripts (const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Unicode scripts. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); for (s = 0; s < numscripts; s++) { @@ -3656,8 +3656,8 @@ output_scripts (const char *version) char *cp; for (cp = lcp; *cp != '\0'; cp++) - if (*cp >= 'A' && *cp <= 'Z') - *cp += 'a' - 'A'; + if (*cp >= 'A' && *cp <= 'Z') + *cp += 'a' - 'A'; scriptinfo[s].lowercase_name = lcp; } @@ -3665,29 +3665,29 @@ output_scripts (const char *version) for (s = 0; s < numscripts; s++) { fprintf (stream, "static const uc_interval_t script_%s_intervals[] =\n", - scriptinfo[s].lowercase_name); + scriptinfo[s].lowercase_name); fprintf (stream, "{\n"); i = 0; for (ch = 0; ch < 0x110000; ch++) - if (unicode_scripts[ch] == s) - { - unsigned int start; - unsigned int end; - - start = ch; - while (ch + 1 < 0x110000 && unicode_scripts[ch + 1] == s) - ch++; - end = ch; - - if (i > 0) - fprintf (stream, ",\n"); - if (start == end) - fprintf (stream, " { 0x%04X, 1, 1 }", start); - else - fprintf (stream, " { 0x%04X, 1, 0 }, { 0x%04X, 0, 1 }", - start, end); - i++; - } + if (unicode_scripts[ch] == s) + { + unsigned int start; + unsigned int end; + + start = ch; + while (ch + 1 < 0x110000 && unicode_scripts[ch + 1] == s) + ch++; + end = ch; + + if (i > 0) + fprintf (stream, ",\n"); + if (start == end) + fprintf (stream, " { 0x%04X, 1, 1 }", start); + else + fprintf (stream, " { 0x%04X, 1, 0 }, { 0x%04X, 0, 1 }", + start, end); + i++; + } fprintf (stream, "\n"); fprintf (stream, "};\n"); } @@ -3698,13 +3698,13 @@ output_scripts (const char *version) { fprintf (stream, " {\n"); fprintf (stream, " sizeof (script_%s_intervals) / sizeof (uc_interval_t),\n", - scriptinfo[s].lowercase_name); + scriptinfo[s].lowercase_name); fprintf (stream, " script_%s_intervals,\n", - scriptinfo[s].lowercase_name); + scriptinfo[s].lowercase_name); fprintf (stream, " \"%s\"\n", scripts[s]); fprintf (stream, " }"); if (s+1 < numscripts) - fprintf (stream, ","); + fprintf (stream, ","); fprintf (stream, "\n"); } fprintf (stream, "};\n"); @@ -3717,7 +3717,7 @@ output_scripts (const char *version) { unsigned int s = unicode_scripts[ch]; if (s != (uint8_t)~(uint8_t)0) - script_table_add (&t, ch, s); + script_table_add (&t, ch, s); } script_table_finalize (&t); @@ -3735,7 +3735,7 @@ output_scripts (const char *version) for (i = 0; i < 5; i++) fprintf (stream, "#define script_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); @@ -3752,15 +3752,15 @@ output_scripts (const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -3772,15 +3772,15 @@ output_scripts (const char *version) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -3791,10 +3791,10 @@ output_scripts (const char *version) for (i = 0; i < t.level3_size << t.p; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " %3d", ((uint8_t *) (t.result + level3_offset))[i]); if (i+1 < t.level3_size << t.p) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level3_size << t.p > 8) fprintf (stream, "\n "); @@ -3825,7 +3825,7 @@ output_scripts_byname (const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Unicode scripts. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); fprintf (stream, "struct named_script { const char *name; unsigned int index; };\n"); fprintf (stream, "%%struct-type\n"); fprintf (stream, "%%language=ANSI-C\n"); @@ -3874,25 +3874,25 @@ fill_blocks (const char *blocks_filename) char blockname[200+1]; if (fscanf (stream, "%200[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; if (sscanf (buf, "%X..%X%[ ;]%[^\r]", &i1, &i2, padding, blockname) != 4) - { - fprintf (stderr, "parse error in '%s'\n", blocks_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", blocks_filename); + exit (1); + } blocks[numblocks].start = i1; blocks[numblocks].end = i2; blocks[numblocks].name = strdup (blockname); /* It must be sorted. */ if (numblocks > 0 && !(blocks[numblocks-1].end < blocks[numblocks].start)) - abort (); + abort (); numblocks++; if (numblocks == 256) - abort (); + abort (); } if (ferror (stream) || fclose (stream)) @@ -3916,9 +3916,9 @@ block_first_index (unsigned int ch) { unsigned int mid = (lo + hi) / 2; /* >= lo, < hi */ if (blocks[mid].end < ch) - lo = mid + 1; + lo = mid + 1; else - hi = mid; + hi = mid; } return hi; } @@ -3938,9 +3938,9 @@ block_last_index (unsigned int ch) { unsigned int mid = (lo + hi) / 2; /* >= lo, < hi */ if (blocks[mid].start <= ch) - lo = mid + 1; + lo = mid + 1; else - hi = mid; + hi = mid; } return hi; } @@ -3965,23 +3965,23 @@ output_blocks (const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Unicode blocks. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); fprintf (stream, "static const uc_block_t blocks[] =\n"); fprintf (stream, "{\n"); for (i = 0; i < numblocks; i++) { fprintf (stream, " { 0x%04X, 0x%04X, \"%s\" }", blocks[i].start, - blocks[i].end, blocks[i].name); + blocks[i].end, blocks[i].name); if (i+1 < numblocks) - fprintf (stream, ","); + fprintf (stream, ","); fprintf (stream, "\n"); } fprintf (stream, "};\n"); fprintf (stream, "#define blocks_level1_shift %d\n", shift); fprintf (stream, "#define blocks_level1_threshold 0x%04X\n", threshold); fprintf (stream, "static const uint8_t blocks_level1[%d * 2] =\n", - threshold >> shift); + threshold >> shift); fprintf (stream, "{\n"); for (i1 = 0; i1 < (threshold >> shift); i1++) { @@ -3989,14 +3989,14 @@ output_blocks (const char *version) unsigned int last_index = block_last_index (((i1 + 1) << shift) - 1); fprintf (stream, " %3d, %3d", first_index, last_index); if (i1+1 < (threshold >> shift)) - fprintf (stream, ","); + fprintf (stream, ","); fprintf (stream, "\n"); } fprintf (stream, "};\n"); fprintf (stream, "#define blocks_upper_first_index %d\n", - block_first_index (threshold)); + block_first_index (threshold)); fprintf (stream, "#define blocks_upper_last_index %d\n", - block_last_index (0x10FFFF)); + block_last_index (0x10FFFF)); if (ferror (stream) || fclose (stream)) { @@ -4022,10 +4022,10 @@ static bool is_c_whitespace (unsigned int ch) { return (ch == ' ' /* space */ - || ch == '\t' /* horizontal tab */ - || ch == '\n' || ch == '\r' /* new-line */ - || ch == '\v' /* vertical tab */ - || ch == '\f'); /* form-feed */ + || ch == '\t' /* horizontal tab */ + || ch == '\n' || ch == '\r' /* new-line */ + || ch == '\v' /* vertical tab */ + || ch == '\f'); /* form-feed */ } /* ISO C 99 section 6.4.2.1 and appendix D. */ @@ -4325,7 +4325,7 @@ static bool is_java_whitespace (unsigned int ch) { return (ch == ' ' || ch == '\t' || ch == '\f' - || ch == '\n' || ch == '\r'); + || ch == '\n' || ch == '\r'); } /* The Java Language Specification, 3rd edition, §3.8. @@ -4382,7 +4382,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Language syntax properties of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-ctype.c for Unicode %s. */\n", - version); + version); t.p = 7; /* or 8 */ t.q = 5; /* or 4 */ @@ -4392,7 +4392,7 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co { int syntaxcode = predicate (ch); if (syntaxcode != UC_IDENTIFIER_INVALID) - identsyntax_table_add (&t, ch, syntaxcode); + identsyntax_table_add (&t, ch, syntaxcode); } identsyntax_table_finalize (&t); @@ -4410,14 +4410,14 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co for (i = 0; i < 5; i++) fprintf (stream, "#define identsyntax_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); fprintf (stream, " int level1[%zu];\n", t.level1_size); fprintf (stream, " short level2[%zu << %d];\n", t.level2_size, t.q); fprintf (stream, " unsigned short level3[%zu * %d];\n", t.level3_size, - (1 << t.p) * 2 / 16); + (1 << t.p) * 2 / 16); fprintf (stream, " }\n"); fprintf (stream, "%s =\n", name); fprintf (stream, "{\n"); @@ -4428,15 +4428,15 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -4448,15 +4448,15 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (uint8_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (uint8_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -4468,18 +4468,18 @@ output_ident_category (const char *filename, int (*predicate) (unsigned int), co for (i = 0; i < (t.level3_size << t.p) * 2 / 16; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " 0x%04x", - (((uint8_t *) (t.result + level3_offset))[8 * i] << 0) - | (((uint8_t *) (t.result + level3_offset))[8 * i + 1] << 2) - | (((uint8_t *) (t.result + level3_offset))[8 * i + 2] << 4) - | (((uint8_t *) (t.result + level3_offset))[8 * i + 3] << 6) - | (((uint8_t *) (t.result + level3_offset))[8 * i + 4] << 8) - | (((uint8_t *) (t.result + level3_offset))[8 * i + 5] << 10) - | (((uint8_t *) (t.result + level3_offset))[8 * i + 6] << 12) - | (((uint8_t *) (t.result + level3_offset))[8 * i + 7] << 14)); + (((uint8_t *) (t.result + level3_offset))[8 * i] << 0) + | (((uint8_t *) (t.result + level3_offset))[8 * i + 1] << 2) + | (((uint8_t *) (t.result + level3_offset))[8 * i + 2] << 4) + | (((uint8_t *) (t.result + level3_offset))[8 * i + 3] << 6) + | (((uint8_t *) (t.result + level3_offset))[8 * i + 4] << 8) + | (((uint8_t *) (t.result + level3_offset))[8 * i + 5] << 10) + | (((uint8_t *) (t.result + level3_offset))[8 * i + 6] << 12) + | (((uint8_t *) (t.result + level3_offset))[8 * i + 7] << 14)); if (i+1 < (t.level3_size << t.p) * 2 / 16) - fprintf (stream, ","); + fprintf (stream, ","); } if ((t.level3_size << t.p) * 2 / 16 > 8) fprintf (stream, "\n "); @@ -4558,39 +4558,39 @@ static bool is_lower (unsigned int ch) { return (to_upper (ch) != ch) - /* is lowercase, but without simple to_upper mapping. */ - || (ch == 0x00DF); + /* is lowercase, but without simple to_upper mapping. */ + || (ch == 0x00DF); } static bool is_alpha (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && ((unicode_attributes[ch].category[0] == 'L' - /* Theppitak Karoonboonyanan says - , should belong to is_punct. */ - && (ch != 0x0E2F) && (ch != 0x0E46)) - /* Theppitak Karoonboonyanan says - , .., .. are is_alpha. */ - || (ch == 0x0E31) - || (ch >= 0x0E34 && ch <= 0x0E3A) - || (ch >= 0x0E47 && ch <= 0x0E4E) - /* Avoid warning for . */ - || (ch == 0x0345) - /* Avoid warnings for ... */ - || (unicode_attributes[ch].category[0] == 'N' - && unicode_attributes[ch].category[1] == 'l') - /* Avoid warnings for ... */ - || (unicode_attributes[ch].category[0] == 'S' - && unicode_attributes[ch].category[1] == 'o' - && strstr (unicode_attributes[ch].name, " LETTER ") - != NULL) - /* Consider all the non-ASCII digits as alphabetic. - ISO C 99 forbids us to have them in category "digit", - but we want iswalnum to return true on them. */ - || (unicode_attributes[ch].category[0] == 'N' - && unicode_attributes[ch].category[1] == 'd' - && !(ch >= 0x0030 && ch <= 0x0039)))); + && ((unicode_attributes[ch].category[0] == 'L' + /* Theppitak Karoonboonyanan says + , should belong to is_punct. */ + && (ch != 0x0E2F) && (ch != 0x0E46)) + /* Theppitak Karoonboonyanan says + , .., .. are is_alpha. */ + || (ch == 0x0E31) + || (ch >= 0x0E34 && ch <= 0x0E3A) + || (ch >= 0x0E47 && ch <= 0x0E4E) + /* Avoid warning for . */ + || (ch == 0x0345) + /* Avoid warnings for ... */ + || (unicode_attributes[ch].category[0] == 'N' + && unicode_attributes[ch].category[1] == 'l') + /* Avoid warnings for ... */ + || (unicode_attributes[ch].category[0] == 'S' + && unicode_attributes[ch].category[1] == 'o' + && strstr (unicode_attributes[ch].name, " LETTER ") + != NULL) + /* Consider all the non-ASCII digits as alphabetic. + ISO C 99 forbids us to have them in category "digit", + but we want iswalnum to return true on them. */ + || (unicode_attributes[ch].category[0] == 'N' + && unicode_attributes[ch].category[1] == 'd' + && !(ch >= 0x0030 && ch <= 0x0039)))); } static bool @@ -4598,8 +4598,8 @@ is_digit (unsigned int ch) { #if 0 return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'N' - && unicode_attributes[ch].category[1] == 'd'); + && unicode_attributes[ch].category[0] == 'N' + && unicode_attributes[ch].category[1] == 'd'); /* Note: U+0BE7..U+0BEF and U+1369..U+1371 are digit systems without a zero. Must add <0> in front of them by hand. */ #else @@ -4631,11 +4631,11 @@ static bool is_blank (unsigned int ch) { return (ch == 0x0009 /* '\t' */ - /* Category Zs without mention of "" */ - || (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'Z' - && unicode_attributes[ch].category[1] == 's' - && !strstr (unicode_attributes[ch].decomposition, ""))); + /* Category Zs without mention of "" */ + || (unicode_attributes[ch].name != NULL + && unicode_attributes[ch].category[0] == 'Z' + && unicode_attributes[ch].category[1] == 's' + && !strstr (unicode_attributes[ch].decomposition, ""))); } static bool @@ -4644,30 +4644,30 @@ is_space (unsigned int ch) /* Don't make U+00A0 a space. Non-breaking space means that all programs should treat it like a punctuation character, not like a space. */ return (ch == 0x0020 /* ' ' */ - || ch == 0x000C /* '\f' */ - || ch == 0x000A /* '\n' */ - || ch == 0x000D /* '\r' */ - || ch == 0x0009 /* '\t' */ - || ch == 0x000B /* '\v' */ - /* Categories Zl, Zp, and Zs without mention of "" */ - || (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'Z' - && (unicode_attributes[ch].category[1] == 'l' - || unicode_attributes[ch].category[1] == 'p' - || (unicode_attributes[ch].category[1] == 's' - && !strstr (unicode_attributes[ch].decomposition, - ""))))); + || ch == 0x000C /* '\f' */ + || ch == 0x000A /* '\n' */ + || ch == 0x000D /* '\r' */ + || ch == 0x0009 /* '\t' */ + || ch == 0x000B /* '\v' */ + /* Categories Zl, Zp, and Zs without mention of "" */ + || (unicode_attributes[ch].name != NULL + && unicode_attributes[ch].category[0] == 'Z' + && (unicode_attributes[ch].category[1] == 'l' + || unicode_attributes[ch].category[1] == 'p' + || (unicode_attributes[ch].category[1] == 's' + && !strstr (unicode_attributes[ch].decomposition, + ""))))); } static bool is_cntrl (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && (strcmp (unicode_attributes[ch].name, "") == 0 - /* Categories Zl and Zp */ - || (unicode_attributes[ch].category[0] == 'Z' - && (unicode_attributes[ch].category[1] == 'l' - || unicode_attributes[ch].category[1] == 'p')))); + && (strcmp (unicode_attributes[ch].name, "") == 0 + /* Categories Zl and Zp */ + || (unicode_attributes[ch].category[0] == 'Z' + && (unicode_attributes[ch].category[1] == 'l' + || unicode_attributes[ch].category[1] == 'p')))); } static bool @@ -4675,8 +4675,8 @@ is_xdigit (unsigned int ch) { #if 0 return is_digit (ch) - || (ch >= 0x0041 && ch <= 0x0046) - || (ch >= 0x0061 && ch <= 0x0066); + || (ch >= 0x0041 && ch <= 0x0046) + || (ch >= 0x0061 && ch <= 0x0066); #else /* SUSV2 gives us some freedom for the "xdigit" category, but ISO C 99 takes it away: @@ -4687,8 +4687,8 @@ is_xdigit (unsigned int ch) hexadecimal-digit: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F */ return (ch >= 0x0030 && ch <= 0x0039) - || (ch >= 0x0041 && ch <= 0x0046) - || (ch >= 0x0061 && ch <= 0x0066); + || (ch >= 0x0041 && ch <= 0x0046) + || (ch >= 0x0061 && ch <= 0x0066); #endif } @@ -4696,20 +4696,20 @@ static bool is_graph (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && strcmp (unicode_attributes[ch].name, "") - && !is_space (ch)); + && strcmp (unicode_attributes[ch].name, "") + && !is_space (ch)); } static bool is_print (unsigned int ch) { return (unicode_attributes[ch].name != NULL - && strcmp (unicode_attributes[ch].name, "") - /* Categories Zl and Zp */ - && !(unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'Z' - && (unicode_attributes[ch].category[1] == 'l' - || unicode_attributes[ch].category[1] == 'p'))); + && strcmp (unicode_attributes[ch].name, "") + /* Categories Zl and Zp */ + && !(unicode_attributes[ch].name != NULL + && unicode_attributes[ch].category[0] == 'Z' + && (unicode_attributes[ch].category[1] == 'l' + || unicode_attributes[ch].category[1] == 'p'))); } static bool @@ -4717,7 +4717,7 @@ is_punct (unsigned int ch) { #if 0 return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'P'); + && unicode_attributes[ch].category[0] == 'P'); #else /* The traditional POSIX definition of punctuation is every graphic, non-alphanumeric character. */ @@ -4758,19 +4758,19 @@ is_combining (unsigned int ch) "Mn", "Mc", "Me". In Unicode 3.1 this property has been dropped from the PropList.txt file, so we take the latter definition. */ return (unicode_attributes[ch].name != NULL - && unicode_attributes[ch].category[0] == 'M' - && (unicode_attributes[ch].category[1] == 'n' - || unicode_attributes[ch].category[1] == 'c' - || unicode_attributes[ch].category[1] == 'e')); + && unicode_attributes[ch].category[0] == 'M' + && (unicode_attributes[ch].category[1] == 'n' + || unicode_attributes[ch].category[1] == 'c' + || unicode_attributes[ch].category[1] == 'e')); } static bool is_combining_level3 (unsigned int ch) { return is_combining (ch) - && !(unicode_attributes[ch].combining[0] != '\0' - && unicode_attributes[ch].combining[0] != '0' - && strtoul (unicode_attributes[ch].combining, NULL, 10) >= 200); + && !(unicode_attributes[ch].combining[0] != '\0' + && unicode_attributes[ch].combining[0] != '0' + && strtoul (unicode_attributes[ch].combining, NULL, 10) >= 200); } /* Return the UCS symbol string for a Unicode character. */ @@ -4799,7 +4799,7 @@ ucs_symbol_range (unsigned int low, unsigned int high) static void output_charclass (FILE *stream, const char *classname, - bool (*func) (unsigned int)) + bool (*func) (unsigned int)) { char table[0x110000]; unsigned int i; @@ -4816,39 +4816,39 @@ output_charclass (FILE *stream, const char *classname, for (i = 0; i < 0x110000; ) { if (!table[i]) - i++; + i++; else - { - unsigned int low, high; - char buf[25]; - - low = i; - do - i++; - while (i < 0x110000 && table[i]); - high = i - 1; - - if (low == high) - strcpy (buf, ucs_symbol (low)); - else - strcpy (buf, ucs_symbol_range (low, high)); - - if (need_semicolon) - { - fprintf (stream, ";"); - column++; - } - - if (column + strlen (buf) > max_column) - { - fprintf (stream, "/\n "); - column = 3; - } - - fprintf (stream, "%s", buf); - column += strlen (buf); - need_semicolon = true; - } + { + unsigned int low, high; + char buf[25]; + + low = i; + do + i++; + while (i < 0x110000 && table[i]); + high = i - 1; + + if (low == high) + strcpy (buf, ucs_symbol (low)); + else + strcpy (buf, ucs_symbol_range (low, high)); + + if (need_semicolon) + { + fprintf (stream, ";"); + column++; + } + + if (column + strlen (buf) > max_column) + { + fprintf (stream, "/\n "); + column = 3; + } + + fprintf (stream, "%s", buf); + column += strlen (buf); + need_semicolon = true; + } } fprintf (stream, "\n"); } @@ -4857,7 +4857,7 @@ output_charclass (FILE *stream, const char *classname, static void output_charmap (FILE *stream, const char *mapname, - unsigned int (*func) (unsigned int)) + unsigned int (*func) (unsigned int)) { char table[0x110000]; unsigned int i; @@ -4874,29 +4874,29 @@ output_charmap (FILE *stream, const char *mapname, for (i = 0; i < 0x110000; i++) if (table[i]) { - char buf[25+1]; - - strcpy (buf, "("); - strcat (buf, ucs_symbol (i)); - strcat (buf, ","); - strcat (buf, ucs_symbol (func (i))); - strcat (buf, ")"); - - if (need_semicolon) - { - fprintf (stream, ";"); - column++; - } - - if (column + strlen (buf) > max_column) - { - fprintf (stream, "/\n "); - column = 3; - } - - fprintf (stream, "%s", buf); - column += strlen (buf); - need_semicolon = true; + char buf[25+1]; + + strcpy (buf, "("); + strcat (buf, ucs_symbol (i)); + strcat (buf, ","); + strcat (buf, ucs_symbol (func (i))); + strcat (buf, ")"); + + if (need_semicolon) + { + fprintf (stream, ";"); + column++; + } + + if (column + strlen (buf) > max_column) + { + fprintf (stream, "/\n "); + column = 3; + } + + fprintf (stream, "%s", buf); + column += strlen (buf); + need_semicolon = true; } fprintf (stream, "\n"); } @@ -4927,7 +4927,7 @@ output_tables (const char *filename, const char *version) fprintf (stream, "comment_char %%\n"); fprintf (stream, "\n"); fprintf (stream, "%% Generated automatically by gen-unicode-ctype for Unicode %s.\n", - version); + version); fprintf (stream, "\n"); fprintf (stream, "LC_IDENTIFICATION\n"); @@ -4956,85 +4956,85 @@ output_tables (const char *filename, const char *version) for (ch = 0; ch < 0x110000; ch++) { /* toupper restriction: "Only characters specified for the keywords - lower and upper shall be specified. */ + lower and upper shall be specified. */ if (to_upper (ch) != ch && !(is_lower (ch) || is_upper (ch))) - fprintf (stderr, - "%s is not upper|lower but toupper(0x%04X) = 0x%04X\n", - ucs_symbol (ch), ch, to_upper (ch)); + fprintf (stderr, + "%s is not upper|lower but toupper(0x%04X) = 0x%04X\n", + ucs_symbol (ch), ch, to_upper (ch)); /* tolower restriction: "Only characters specified for the keywords - lower and upper shall be specified. */ + lower and upper shall be specified. */ if (to_lower (ch) != ch && !(is_lower (ch) || is_upper (ch))) - fprintf (stderr, - "%s is not upper|lower but tolower(0x%04X) = 0x%04X\n", - ucs_symbol (ch), ch, to_lower (ch)); + fprintf (stderr, + "%s is not upper|lower but tolower(0x%04X) = 0x%04X\n", + ucs_symbol (ch), ch, to_lower (ch)); /* alpha restriction: "Characters classified as either upper or lower - shall automatically belong to this class. */ + shall automatically belong to this class. */ if ((is_lower (ch) || is_upper (ch)) && !is_alpha (ch)) - fprintf (stderr, "%s is upper|lower but not alpha\n", ucs_symbol (ch)); + fprintf (stderr, "%s is upper|lower but not alpha\n", ucs_symbol (ch)); /* alpha restriction: "No character specified for the keywords cntrl, - digit, punct or space shall be specified." */ + digit, punct or space shall be specified." */ if (is_alpha (ch) && is_cntrl (ch)) - fprintf (stderr, "%s is alpha and cntrl\n", ucs_symbol (ch)); + fprintf (stderr, "%s is alpha and cntrl\n", ucs_symbol (ch)); if (is_alpha (ch) && is_digit (ch)) - fprintf (stderr, "%s is alpha and digit\n", ucs_symbol (ch)); + fprintf (stderr, "%s is alpha and digit\n", ucs_symbol (ch)); if (is_alpha (ch) && is_punct (ch)) - fprintf (stderr, "%s is alpha and punct\n", ucs_symbol (ch)); + fprintf (stderr, "%s is alpha and punct\n", ucs_symbol (ch)); if (is_alpha (ch) && is_space (ch)) - fprintf (stderr, "%s is alpha and space\n", ucs_symbol (ch)); + fprintf (stderr, "%s is alpha and space\n", ucs_symbol (ch)); /* space restriction: "No character specified for the keywords upper, - lower, alpha, digit, graph or xdigit shall be specified." - upper, lower, alpha already checked above. */ + lower, alpha, digit, graph or xdigit shall be specified." + upper, lower, alpha already checked above. */ if (is_space (ch) && is_digit (ch)) - fprintf (stderr, "%s is space and digit\n", ucs_symbol (ch)); + fprintf (stderr, "%s is space and digit\n", ucs_symbol (ch)); if (is_space (ch) && is_graph (ch)) - fprintf (stderr, "%s is space and graph\n", ucs_symbol (ch)); + fprintf (stderr, "%s is space and graph\n", ucs_symbol (ch)); if (is_space (ch) && is_xdigit (ch)) - fprintf (stderr, "%s is space and xdigit\n", ucs_symbol (ch)); + fprintf (stderr, "%s is space and xdigit\n", ucs_symbol (ch)); /* cntrl restriction: "No character specified for the keywords upper, - lower, alpha, digit, punct, graph, print or xdigit shall be - specified." upper, lower, alpha already checked above. */ + lower, alpha, digit, punct, graph, print or xdigit shall be + specified." upper, lower, alpha already checked above. */ if (is_cntrl (ch) && is_digit (ch)) - fprintf (stderr, "%s is cntrl and digit\n", ucs_symbol (ch)); + fprintf (stderr, "%s is cntrl and digit\n", ucs_symbol (ch)); if (is_cntrl (ch) && is_punct (ch)) - fprintf (stderr, "%s is cntrl and punct\n", ucs_symbol (ch)); + fprintf (stderr, "%s is cntrl and punct\n", ucs_symbol (ch)); if (is_cntrl (ch) && is_graph (ch)) - fprintf (stderr, "%s is cntrl and graph\n", ucs_symbol (ch)); + fprintf (stderr, "%s is cntrl and graph\n", ucs_symbol (ch)); if (is_cntrl (ch) && is_print (ch)) - fprintf (stderr, "%s is cntrl and print\n", ucs_symbol (ch)); + fprintf (stderr, "%s is cntrl and print\n", ucs_symbol (ch)); if (is_cntrl (ch) && is_xdigit (ch)) - fprintf (stderr, "%s is cntrl and xdigit\n", ucs_symbol (ch)); + fprintf (stderr, "%s is cntrl and xdigit\n", ucs_symbol (ch)); /* punct restriction: "No character specified for the keywords upper, - lower, alpha, digit, cntrl, xdigit or as the character shall - be specified." upper, lower, alpha, cntrl already checked above. */ + lower, alpha, digit, cntrl, xdigit or as the character shall + be specified." upper, lower, alpha, cntrl already checked above. */ if (is_punct (ch) && is_digit (ch)) - fprintf (stderr, "%s is punct and digit\n", ucs_symbol (ch)); + fprintf (stderr, "%s is punct and digit\n", ucs_symbol (ch)); if (is_punct (ch) && is_xdigit (ch)) - fprintf (stderr, "%s is punct and xdigit\n", ucs_symbol (ch)); + fprintf (stderr, "%s is punct and xdigit\n", ucs_symbol (ch)); if (is_punct (ch) && (ch == 0x0020)) - fprintf (stderr, "%s is punct\n", ucs_symbol (ch)); + fprintf (stderr, "%s is punct\n", ucs_symbol (ch)); /* graph restriction: "No character specified for the keyword cntrl - shall be specified." Already checked above. */ + shall be specified." Already checked above. */ /* print restriction: "No character specified for the keyword cntrl - shall be specified." Already checked above. */ + shall be specified." Already checked above. */ /* graph - print relation: differ only in the character. - How is this possible if there are more than one space character?! - I think susv2/xbd/locale.html should speak of "space characters", - not "space character". */ + How is this possible if there are more than one space character?! + I think susv2/xbd/locale.html should speak of "space characters", + not "space character". */ if (is_print (ch) && !(is_graph (ch) || /* ch == 0x0020 */ is_space (ch))) - fprintf (stderr, - "%s is print but not graph|\n", ucs_symbol (ch)); + fprintf (stderr, + "%s is print but not graph|\n", ucs_symbol (ch)); if (!is_print (ch) && (is_graph (ch) || ch == 0x0020)) - fprintf (stderr, - "%s is graph| but not print\n", ucs_symbol (ch)); + fprintf (stderr, + "%s is graph| but not print\n", ucs_symbol (ch)); } fprintf (stream, "LC_CTYPE\n"); @@ -5103,36 +5103,36 @@ fill_width (const char *width_filename) lineno++; c = getc (stream); if (c == EOF) - break; + break; if (c == '#') - { - do c = getc (stream); while (c != EOF && c != '\n'); - continue; - } + { + do c = getc (stream); while (c != EOF && c != '\n'); + continue; + } ungetc (c, stream); n = getfield (stream, field0, ';'); n += getfield (stream, field1, ' '); n += getfield (stream, field2, '\n'); if (n == 0) - break; + break; if (n != 3) - { - fprintf (stderr, "short line in '%s':%d\n", width_filename, lineno); - exit (1); - } + { + fprintf (stderr, "short line in '%s':%d\n", width_filename, lineno); + exit (1); + } i = strtoul (field0, NULL, 16); if (strstr (field0, "..") != NULL) - { - /* Deal with a range. */ - j = strtoul (strstr (field0, "..") + 2, NULL, 16); - for (; i <= j; i++) - unicode_width[i] = strdup (field1); - } + { + /* Deal with a range. */ + j = strtoul (strstr (field0, "..") + 2, NULL, 16); + for (; i <= j; i++) + unicode_width[i] = strdup (field1); + } else - { - /* Single character line. */ - unicode_width[i] = strdup (field1); - } + { + /* Single character line. */ + unicode_width[i] = strdup (field1); + } } if (ferror (stream) || fclose (stream)) { @@ -5194,580 +5194,580 @@ get_lbp (unsigned int ch) { /* mandatory break */ if (ch == 0x000A || ch == 0x000D || ch == 0x0085 /* newline */ - || ch == 0x000C /* form feed */ - || ch == 0x000B /* line tabulation */ - || ch == 0x2028 /* LINE SEPARATOR */ - || ch == 0x2029 /* PARAGRAPH SEPARATOR */) - attr |= 1 << LBP_BK; + || ch == 0x000C /* form feed */ + || ch == 0x000B /* line tabulation */ + || ch == 0x2028 /* LINE SEPARATOR */ + || ch == 0x2029 /* PARAGRAPH SEPARATOR */) + attr |= 1 << LBP_BK; if (ch == 0x2060 /* WORD JOINER */ - || ch == 0xFEFF /* ZERO WIDTH NO-BREAK SPACE */) - attr |= 1 << LBP_WJ; + || ch == 0xFEFF /* ZERO WIDTH NO-BREAK SPACE */) + attr |= 1 << LBP_WJ; /* zero width space */ if (ch == 0x200B /* ZERO WIDTH SPACE */) - attr |= 1 << LBP_ZW; + attr |= 1 << LBP_ZW; /* non-breaking (glue) */ if (ch == 0x00A0 /* NO-BREAK SPACE */ - || ch == 0x202F /* NARROW NO-BREAK SPACE */ - || ch == 0x180E /* MONGOLIAN VOWEL SEPARATOR */ - || ch == 0x034F /* COMBINING GRAPHEME JOINER */ - || ch == 0x2007 /* FIGURE SPACE */ - || ch == 0x2011 /* NON-BREAKING HYPHEN */ - || ch == 0x0F08 /* TIBETAN MARK SBRUL SHAD */ - || ch == 0x0F0C /* TIBETAN MARK DELIMITER TSHEG BSTAR */ - || ch == 0x0F12 /* TIBETAN MARK RGYA GRAM SHAD */ - || (ch >= 0x035C && ch <= 0x0362) /* COMBINING DOUBLE ... */) - attr |= 1 << LBP_GL; + || ch == 0x202F /* NARROW NO-BREAK SPACE */ + || ch == 0x180E /* MONGOLIAN VOWEL SEPARATOR */ + || ch == 0x034F /* COMBINING GRAPHEME JOINER */ + || ch == 0x2007 /* FIGURE SPACE */ + || ch == 0x2011 /* NON-BREAKING HYPHEN */ + || ch == 0x0F08 /* TIBETAN MARK SBRUL SHAD */ + || ch == 0x0F0C /* TIBETAN MARK DELIMITER TSHEG BSTAR */ + || ch == 0x0F12 /* TIBETAN MARK RGYA GRAM SHAD */ + || (ch >= 0x035C && ch <= 0x0362) /* COMBINING DOUBLE ... */) + attr |= 1 << LBP_GL; /* space */ if (ch == 0x0020 /* SPACE */) - attr |= 1 << LBP_SP; + attr |= 1 << LBP_SP; /* break opportunity before and after */ if (ch == 0x2014 /* EM DASH */) - attr |= 1 << LBP_B2; + attr |= 1 << LBP_B2; /* break opportunity after */ if (ch == 0x1680 /* OGHAM SPACE MARK */ - || ch == 0x2000 /* EN QUAD */ - || ch == 0x2001 /* EM QUAD */ - || ch == 0x2002 /* EN SPACE */ - || ch == 0x2003 /* EM SPACE */ - || ch == 0x2004 /* THREE-PER-EM SPACE */ - || ch == 0x2005 /* FOUR-PER-EM SPACE */ - || ch == 0x2006 /* SIX-PER-EM SPACE */ - || ch == 0x2008 /* PUNCTUATION SPACE */ - || ch == 0x2009 /* THIN SPACE */ - || ch == 0x200A /* HAIR SPACE */ - || ch == 0x205F /* MEDIUM MATHEMATICAL SPACE */ - || ch == 0x0009 /* tab */ - || ch == 0x00AD /* SOFT HYPHEN */ - || ch == 0x058A /* ARMENIAN HYPHEN */ - || ch == 0x2010 /* HYPHEN */ - || ch == 0x2012 /* FIGURE DASH */ - || ch == 0x2013 /* EN DASH */ - || ch == 0x05BE /* HEBREW PUNCTUATION MAQAF */ - || ch == 0x0F0B /* TIBETAN MARK INTERSYLLABIC TSHEG */ - || ch == 0x1361 /* ETHIOPIC WORDSPACE */ - || ch == 0x17D8 /* KHMER SIGN BEYYAL */ - || ch == 0x17DA /* KHMER SIGN KOOMUUT */ - || ch == 0x2027 /* HYPHENATION POINT */ - || ch == 0x007C /* VERTICAL LINE */ - || ch == 0x16EB /* RUNIC SINGLE PUNCTUATION */ - || ch == 0x16EC /* RUNIC MULTIPLE PUNCTUATION */ - || ch == 0x16ED /* RUNIC CROSS PUNCTUATION */ - || ch == 0x2056 /* THREE DOT PUNCTUATION */ - || ch == 0x2058 /* FOUR DOT PUNCTUATION */ - || ch == 0x2059 /* FIVE DOT PUNCTUATION */ - || ch == 0x205A /* TWO DOT PUNCTUATION */ - || ch == 0x205B /* FOUR DOT MARK */ - || ch == 0x205D /* TRICOLON */ - || ch == 0x205E /* VERTICAL FOUR DOTS */ - || ch == 0x2E19 /* PALM BRANCH */ - || ch == 0x2E2A /* TWO DOTS OVER ONE DOT PUNCTUATION */ - || ch == 0x2E2B /* ONE DOT OVER TWO DOTS PUNCTUATION */ - || ch == 0x2E2C /* SQUARED FOUR DOT PUNCTUATION */ - || ch == 0x2E2D /* FIVE DOT PUNCTUATION */ - || ch == 0x2E30 /* RING POINT */ - || ch == 0x10100 /* AEGEAN WORD SEPARATOR LINE */ - || ch == 0x10101 /* AEGEAN WORD SEPARATOR DOT */ - || ch == 0x10102 /* AEGEAN CHECK MARK */ - || ch == 0x1039F /* UGARITIC WORD DIVIDER */ - || ch == 0x103D0 /* OLD PERSIAN WORD DIVIDER */ - || ch == 0x1091F /* PHOENICIAN WORD SEPARATOR */ - || ch == 0x12470 /* CUNEIFORM PUNCTUATION SIGN OLD ASSYRIAN WORD DIVIDER */ - || ch == 0x0964 /* DEVANAGARI DANDA */ - || ch == 0x0965 /* DEVANAGARI DOUBLE DANDA */ - || ch == 0x0E5A /* THAI CHARACTER ANGKHANKHU */ - || ch == 0x0E5B /* THAI CHARACTER KHOMUT */ - || ch == 0x104A /* MYANMAR SIGN LITTLE SECTION */ - || ch == 0x104B /* MYANMAR SIGN SECTION */ - || ch == 0x1735 /* PHILIPPINE SINGLE PUNCTUATION */ - || ch == 0x1736 /* PHILIPPINE DOUBLE PUNCTUATION */ - || ch == 0x17D4 /* KHMER SIGN KHAN */ - || ch == 0x17D5 /* KHMER SIGN BARIYOOSAN */ - || ch == 0x1B5E /* BALINESE CARIK SIKI */ - || ch == 0x1B5F /* BALINESE CARIK PAREREN */ - || ch == 0xA8CE /* SAURASHTRA DANDA */ - || ch == 0xA8CF /* SAURASHTRA DOUBLE DANDA */ - || ch == 0xAA5D /* CHAM PUNCTUATION DANDA */ - || ch == 0xAA5E /* CHAM PUNCTUATION DOUBLE DANDA */ - || ch == 0xAA5F /* CHAM PUNCTUATION TRIPLE DANDA */ - || ch == 0x10A56 /* KHAROSHTHI PUNCTUATION DANDA */ - || ch == 0x10A57 /* KHAROSHTHI PUNCTUATION DOUBLE DANDA */ - || ch == 0x0F34 /* TIBETAN MARK BSDUS RTAGS */ - || ch == 0x0F7F /* TIBETAN SIGN RNAM BCAD */ - || ch == 0x0F85 /* TIBETAN MARK PALUTA */ - || ch == 0x0FBE /* TIBETAN KU RU KHA */ - || ch == 0x0FBF /* TIBETAN KU RU KHA BZHI MIG CAN */ - || ch == 0x0FD2 /* TIBETAN MARK NYIS TSHEG */ - || ch == 0x1804 /* MONGOLIAN COLON */ - || ch == 0x1805 /* MONGOLIAN FOUR DOTS */ - || ch == 0x1B5A /* BALINESE PANTI */ - || ch == 0x1B5B /* BALINESE PAMADA */ - || ch == 0x1B5C /* BALINESE WINDU */ - || ch == 0x1B5D /* BALINESE CARIK PAMUNGKAH */ - || ch == 0x1B60 /* BALINESE PAMENENG */ - || ch == 0x1C3B /* LEPCHA PUNCTUATION TA-ROL */ - || ch == 0x1C3C /* LEPCHA PUNCTUATION NYET THYOOM TA-ROL */ - || ch == 0x1C3D /* LEPCHA PUNCTUATION CER-WA */ - || ch == 0x1C3E /* LEPCHA PUNCTUATION TSHOOK CER-WA */ - || ch == 0x1C3F /* LEPCHA PUNCTUATION TSHOOK */ - || ch == 0x1C7E /* OL CHIKI PUNCTUATION MUCAAD */ - || ch == 0x1C7F /* OL CHIKI PUNCTUATION DOUBLE MUCAAD */ - || ch == 0x2CFA /* COPTIC OLD NUBIAN DIRECT QUESTION MARK */ - || ch == 0x2CFB /* COPTIC OLD NUBIAN INDIRECT QUESTION MARK */ - || ch == 0x2CFC /* COPTIC OLD NUBIAN VERSE DIVIDER */ - || ch == 0x2CFF /* COPTIC MORPHOLOGICAL DIVIDER */ - || (ch >= 0x2E0E && ch <= 0x2E15) /* EDITORIAL CORONIS .. UPWARDS ANCORA */ - || ch == 0x2E17 /* DOUBLE OBLIQUE HYPHEN */ - || ch == 0xA60D /* VAI COMMA */ - || ch == 0xA60F /* VAI QUESTION MARK */ - || ch == 0xA92E /* KAYAH LI SIGN CWI */ - || ch == 0xA92F /* KAYAH LI SIGN SHYA */ - || ch == 0x10A50 /* KHAROSHTHI PUNCTUATION DOT */ - || ch == 0x10A51 /* KHAROSHTHI PUNCTUATION SMALL CIRCLE */ - || ch == 0x10A52 /* KHAROSHTHI PUNCTUATION CIRCLE */ - || ch == 0x10A53 /* KHAROSHTHI PUNCTUATION CRESCENT BAR */ - || ch == 0x10A54 /* KHAROSHTHI PUNCTUATION MANGALAM */ - || ch == 0x10A55 /* KHAROSHTHI PUNCTUATION LOTUS */ - /* Extra characters for compatibility with Unicode LineBreak.txt. */ - || ch == 0x12471 /* CUNEIFORM PUNCTUATION SIGN VERTICAL COLON */ - || ch == 0x12472 /* CUNEIFORM PUNCTUATION SIGN DIAGONAL COLON */ - || ch == 0x12473 /* CUNEIFORM PUNCTUATION SIGN DIAGONAL TRICOLON */) - attr |= 1 << LBP_BA; + || ch == 0x2000 /* EN QUAD */ + || ch == 0x2001 /* EM QUAD */ + || ch == 0x2002 /* EN SPACE */ + || ch == 0x2003 /* EM SPACE */ + || ch == 0x2004 /* THREE-PER-EM SPACE */ + || ch == 0x2005 /* FOUR-PER-EM SPACE */ + || ch == 0x2006 /* SIX-PER-EM SPACE */ + || ch == 0x2008 /* PUNCTUATION SPACE */ + || ch == 0x2009 /* THIN SPACE */ + || ch == 0x200A /* HAIR SPACE */ + || ch == 0x205F /* MEDIUM MATHEMATICAL SPACE */ + || ch == 0x0009 /* tab */ + || ch == 0x00AD /* SOFT HYPHEN */ + || ch == 0x058A /* ARMENIAN HYPHEN */ + || ch == 0x2010 /* HYPHEN */ + || ch == 0x2012 /* FIGURE DASH */ + || ch == 0x2013 /* EN DASH */ + || ch == 0x05BE /* HEBREW PUNCTUATION MAQAF */ + || ch == 0x0F0B /* TIBETAN MARK INTERSYLLABIC TSHEG */ + || ch == 0x1361 /* ETHIOPIC WORDSPACE */ + || ch == 0x17D8 /* KHMER SIGN BEYYAL */ + || ch == 0x17DA /* KHMER SIGN KOOMUUT */ + || ch == 0x2027 /* HYPHENATION POINT */ + || ch == 0x007C /* VERTICAL LINE */ + || ch == 0x16EB /* RUNIC SINGLE PUNCTUATION */ + || ch == 0x16EC /* RUNIC MULTIPLE PUNCTUATION */ + || ch == 0x16ED /* RUNIC CROSS PUNCTUATION */ + || ch == 0x2056 /* THREE DOT PUNCTUATION */ + || ch == 0x2058 /* FOUR DOT PUNCTUATION */ + || ch == 0x2059 /* FIVE DOT PUNCTUATION */ + || ch == 0x205A /* TWO DOT PUNCTUATION */ + || ch == 0x205B /* FOUR DOT MARK */ + || ch == 0x205D /* TRICOLON */ + || ch == 0x205E /* VERTICAL FOUR DOTS */ + || ch == 0x2E19 /* PALM BRANCH */ + || ch == 0x2E2A /* TWO DOTS OVER ONE DOT PUNCTUATION */ + || ch == 0x2E2B /* ONE DOT OVER TWO DOTS PUNCTUATION */ + || ch == 0x2E2C /* SQUARED FOUR DOT PUNCTUATION */ + || ch == 0x2E2D /* FIVE DOT PUNCTUATION */ + || ch == 0x2E30 /* RING POINT */ + || ch == 0x10100 /* AEGEAN WORD SEPARATOR LINE */ + || ch == 0x10101 /* AEGEAN WORD SEPARATOR DOT */ + || ch == 0x10102 /* AEGEAN CHECK MARK */ + || ch == 0x1039F /* UGARITIC WORD DIVIDER */ + || ch == 0x103D0 /* OLD PERSIAN WORD DIVIDER */ + || ch == 0x1091F /* PHOENICIAN WORD SEPARATOR */ + || ch == 0x12470 /* CUNEIFORM PUNCTUATION SIGN OLD ASSYRIAN WORD DIVIDER */ + || ch == 0x0964 /* DEVANAGARI DANDA */ + || ch == 0x0965 /* DEVANAGARI DOUBLE DANDA */ + || ch == 0x0E5A /* THAI CHARACTER ANGKHANKHU */ + || ch == 0x0E5B /* THAI CHARACTER KHOMUT */ + || ch == 0x104A /* MYANMAR SIGN LITTLE SECTION */ + || ch == 0x104B /* MYANMAR SIGN SECTION */ + || ch == 0x1735 /* PHILIPPINE SINGLE PUNCTUATION */ + || ch == 0x1736 /* PHILIPPINE DOUBLE PUNCTUATION */ + || ch == 0x17D4 /* KHMER SIGN KHAN */ + || ch == 0x17D5 /* KHMER SIGN BARIYOOSAN */ + || ch == 0x1B5E /* BALINESE CARIK SIKI */ + || ch == 0x1B5F /* BALINESE CARIK PAREREN */ + || ch == 0xA8CE /* SAURASHTRA DANDA */ + || ch == 0xA8CF /* SAURASHTRA DOUBLE DANDA */ + || ch == 0xAA5D /* CHAM PUNCTUATION DANDA */ + || ch == 0xAA5E /* CHAM PUNCTUATION DOUBLE DANDA */ + || ch == 0xAA5F /* CHAM PUNCTUATION TRIPLE DANDA */ + || ch == 0x10A56 /* KHAROSHTHI PUNCTUATION DANDA */ + || ch == 0x10A57 /* KHAROSHTHI PUNCTUATION DOUBLE DANDA */ + || ch == 0x0F34 /* TIBETAN MARK BSDUS RTAGS */ + || ch == 0x0F7F /* TIBETAN SIGN RNAM BCAD */ + || ch == 0x0F85 /* TIBETAN MARK PALUTA */ + || ch == 0x0FBE /* TIBETAN KU RU KHA */ + || ch == 0x0FBF /* TIBETAN KU RU KHA BZHI MIG CAN */ + || ch == 0x0FD2 /* TIBETAN MARK NYIS TSHEG */ + || ch == 0x1804 /* MONGOLIAN COLON */ + || ch == 0x1805 /* MONGOLIAN FOUR DOTS */ + || ch == 0x1B5A /* BALINESE PANTI */ + || ch == 0x1B5B /* BALINESE PAMADA */ + || ch == 0x1B5C /* BALINESE WINDU */ + || ch == 0x1B5D /* BALINESE CARIK PAMUNGKAH */ + || ch == 0x1B60 /* BALINESE PAMENENG */ + || ch == 0x1C3B /* LEPCHA PUNCTUATION TA-ROL */ + || ch == 0x1C3C /* LEPCHA PUNCTUATION NYET THYOOM TA-ROL */ + || ch == 0x1C3D /* LEPCHA PUNCTUATION CER-WA */ + || ch == 0x1C3E /* LEPCHA PUNCTUATION TSHOOK CER-WA */ + || ch == 0x1C3F /* LEPCHA PUNCTUATION TSHOOK */ + || ch == 0x1C7E /* OL CHIKI PUNCTUATION MUCAAD */ + || ch == 0x1C7F /* OL CHIKI PUNCTUATION DOUBLE MUCAAD */ + || ch == 0x2CFA /* COPTIC OLD NUBIAN DIRECT QUESTION MARK */ + || ch == 0x2CFB /* COPTIC OLD NUBIAN INDIRECT QUESTION MARK */ + || ch == 0x2CFC /* COPTIC OLD NUBIAN VERSE DIVIDER */ + || ch == 0x2CFF /* COPTIC MORPHOLOGICAL DIVIDER */ + || (ch >= 0x2E0E && ch <= 0x2E15) /* EDITORIAL CORONIS .. UPWARDS ANCORA */ + || ch == 0x2E17 /* DOUBLE OBLIQUE HYPHEN */ + || ch == 0xA60D /* VAI COMMA */ + || ch == 0xA60F /* VAI QUESTION MARK */ + || ch == 0xA92E /* KAYAH LI SIGN CWI */ + || ch == 0xA92F /* KAYAH LI SIGN SHYA */ + || ch == 0x10A50 /* KHAROSHTHI PUNCTUATION DOT */ + || ch == 0x10A51 /* KHAROSHTHI PUNCTUATION SMALL CIRCLE */ + || ch == 0x10A52 /* KHAROSHTHI PUNCTUATION CIRCLE */ + || ch == 0x10A53 /* KHAROSHTHI PUNCTUATION CRESCENT BAR */ + || ch == 0x10A54 /* KHAROSHTHI PUNCTUATION MANGALAM */ + || ch == 0x10A55 /* KHAROSHTHI PUNCTUATION LOTUS */ + /* Extra characters for compatibility with Unicode LineBreak.txt. */ + || ch == 0x12471 /* CUNEIFORM PUNCTUATION SIGN VERTICAL COLON */ + || ch == 0x12472 /* CUNEIFORM PUNCTUATION SIGN DIAGONAL COLON */ + || ch == 0x12473 /* CUNEIFORM PUNCTUATION SIGN DIAGONAL TRICOLON */) + attr |= 1 << LBP_BA; /* break opportunity before */ if (ch == 0x00B4 /* ACUTE ACCENT */ - || ch == 0x1FFD /* GREEK OXIA */ - || ch == 0x02DF /* MODIFIER LETTER CROSS ACCENT */ - || ch == 0x02C8 /* MODIFIER LETTER VERTICAL LINE */ - || ch == 0x02CC /* MODIFIER LETTER LOW VERTICAL LINE */ - || ch == 0x0F01 /* TIBETAN MARK GTER YIG MGO TRUNCATED A */ - || ch == 0x0F02 /* TIBETAN MARK GTER YIG MGO -UM RNAM BCAD MA */ - || ch == 0x0F03 /* TIBETAN MARK GTER YIG MGO -UM GTER TSHEG MA */ - || ch == 0x0F04 /* TIBETAN MARK INITIAL YIG MGO MDUN MA */ - || ch == 0x0F06 /* TIBETAN MARK CARET YIG MGO PHUR SHAD MA */ - || ch == 0x0F07 /* TIBETAN MARK YIG MGO TSHEG SHAD MA */ - || ch == 0x0F09 /* TIBETAN MARK BSKUR YIG MGO */ - || ch == 0x0F0A /* TIBETAN MARK BKA- SHOG YIG MGO */ - || ch == 0x0FD0 /* TIBETAN MARK BSKA- SHOG GI MGO RGYAN */ - || ch == 0x0FD1 /* TIBETAN MARK MNYAM YIG GI MGO RGYAN */ - || ch == 0x0FD3 /* TIBETAN MARK INITIAL BRDA RNYING YIG MGO MDUN MA */ - || ch == 0xA874 /* PHAGS-PA SINGLE HEAD MARK */ - || ch == 0xA875 /* PHAGS-PA DOUBLE HEAD MARK */ - || ch == 0x1806 /* MONGOLIAN TODO SOFT HYPHEN */) - attr |= 1 << LBP_BB; + || ch == 0x1FFD /* GREEK OXIA */ + || ch == 0x02DF /* MODIFIER LETTER CROSS ACCENT */ + || ch == 0x02C8 /* MODIFIER LETTER VERTICAL LINE */ + || ch == 0x02CC /* MODIFIER LETTER LOW VERTICAL LINE */ + || ch == 0x0F01 /* TIBETAN MARK GTER YIG MGO TRUNCATED A */ + || ch == 0x0F02 /* TIBETAN MARK GTER YIG MGO -UM RNAM BCAD MA */ + || ch == 0x0F03 /* TIBETAN MARK GTER YIG MGO -UM GTER TSHEG MA */ + || ch == 0x0F04 /* TIBETAN MARK INITIAL YIG MGO MDUN MA */ + || ch == 0x0F06 /* TIBETAN MARK CARET YIG MGO PHUR SHAD MA */ + || ch == 0x0F07 /* TIBETAN MARK YIG MGO TSHEG SHAD MA */ + || ch == 0x0F09 /* TIBETAN MARK BSKUR YIG MGO */ + || ch == 0x0F0A /* TIBETAN MARK BKA- SHOG YIG MGO */ + || ch == 0x0FD0 /* TIBETAN MARK BSKA- SHOG GI MGO RGYAN */ + || ch == 0x0FD1 /* TIBETAN MARK MNYAM YIG GI MGO RGYAN */ + || ch == 0x0FD3 /* TIBETAN MARK INITIAL BRDA RNYING YIG MGO MDUN MA */ + || ch == 0xA874 /* PHAGS-PA SINGLE HEAD MARK */ + || ch == 0xA875 /* PHAGS-PA DOUBLE HEAD MARK */ + || ch == 0x1806 /* MONGOLIAN TODO SOFT HYPHEN */) + attr |= 1 << LBP_BB; /* hyphen */ if (ch == 0x002D /* HYPHEN-MINUS */) - attr |= 1 << LBP_HY; + attr |= 1 << LBP_HY; /* contingent break opportunity */ if (ch == 0xFFFC /* OBJECT REPLACEMENT CHARACTER */) - attr |= 1 << LBP_CB; + attr |= 1 << LBP_CB; /* closing punctuation */ if ((unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 'e') - || ch == 0x3001 /* IDEOGRAPHIC COMMA */ - || ch == 0x3002 /* IDEOGRAPHIC FULL STOP */ - || ch == 0xFE11 /* PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC COMMA */ - || ch == 0xFE12 /* PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC FULL STOP */ - || ch == 0xFE50 /* SMALL COMMA */ - || ch == 0xFE52 /* SMALL FULL STOP */ - || ch == 0xFF0C /* FULLWIDTH COMMA */ - || ch == 0xFF0E /* FULLWIDTH FULL STOP */ - || ch == 0xFF61 /* HALFWIDTH IDEOGRAPHIC FULL STOP */ - || ch == 0xFF64 /* HALFWIDTH IDEOGRAPHIC COMMA */) - attr |= 1 << LBP_CL; + && unicode_attributes[ch].category[1] == 'e') + || ch == 0x3001 /* IDEOGRAPHIC COMMA */ + || ch == 0x3002 /* IDEOGRAPHIC FULL STOP */ + || ch == 0xFE11 /* PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC COMMA */ + || ch == 0xFE12 /* PRESENTATION FORM FOR VERTICAL IDEOGRAPHIC FULL STOP */ + || ch == 0xFE50 /* SMALL COMMA */ + || ch == 0xFE52 /* SMALL FULL STOP */ + || ch == 0xFF0C /* FULLWIDTH COMMA */ + || ch == 0xFF0E /* FULLWIDTH FULL STOP */ + || ch == 0xFF61 /* HALFWIDTH IDEOGRAPHIC FULL STOP */ + || ch == 0xFF64 /* HALFWIDTH IDEOGRAPHIC COMMA */) + attr |= 1 << LBP_CL; /* exclamation/interrogation */ if (ch == 0x0021 /* EXCLAMATION MARK */ - || ch == 0x003F /* QUESTION MARK */ - || ch == 0x05C6 /* HEBREW PUNCTUATION NUN HAFUKHA */ - || ch == 0x061B /* ARABIC SEMICOLON */ - || ch == 0x061E /* ARABIC TRIPLE DOT PUNCTUATION MARK */ - || ch == 0x061F /* ARABIC QUESTION MARK */ - || ch == 0x06D4 /* ARABIC FULL STOP */ - || ch == 0x07F9 /* NKO EXCLAMATION MARK */ - || ch == 0x0F0D /* TIBETAN MARK SHAD */ - || ch == 0x0F0E /* TIBETAN MARK NYIS SHAD */ - || ch == 0x0F0F /* TIBETAN MARK TSHEG SHAD */ - || ch == 0x0F10 /* TIBETAN MARK NYIS TSHEG SHAD */ - || ch == 0x0F11 /* TIBETAN MARK RIN CHEN SPUNGS SHAD */ - || ch == 0x0F14 /* TIBETAN MARK GTER TSHEG */ - || ch == 0x1802 /* MONGOLIAN COMMA */ - || ch == 0x1803 /* MONGOLIAN FULL STOP */ - || ch == 0x1808 /* MONGOLIAN MANCHU COMMA */ - || ch == 0x1809 /* MONGOLIAN MANCHU FULL STOP */ - || ch == 0x1944 /* LIMBU EXCLAMATION MARK */ - || ch == 0x1945 /* LIMBU QUESTION MARK */ - || ch == 0x2762 /* HEAVY EXCLAMATION MARK ORNAMENT */ - || ch == 0x2763 /* HEAVY HEART EXCLAMATION MARK ORNAMENT */ - || ch == 0x2CF9 /* COPTIC OLD NUBIAN FULL STOP */ - || ch == 0x2CFE /* COPTIC FULL STOP */ - || ch == 0x2E2E /* REVERSED QUESTION MARK */ + || ch == 0x003F /* QUESTION MARK */ + || ch == 0x05C6 /* HEBREW PUNCTUATION NUN HAFUKHA */ + || ch == 0x061B /* ARABIC SEMICOLON */ + || ch == 0x061E /* ARABIC TRIPLE DOT PUNCTUATION MARK */ + || ch == 0x061F /* ARABIC QUESTION MARK */ + || ch == 0x06D4 /* ARABIC FULL STOP */ + || ch == 0x07F9 /* NKO EXCLAMATION MARK */ + || ch == 0x0F0D /* TIBETAN MARK SHAD */ + || ch == 0x0F0E /* TIBETAN MARK NYIS SHAD */ + || ch == 0x0F0F /* TIBETAN MARK TSHEG SHAD */ + || ch == 0x0F10 /* TIBETAN MARK NYIS TSHEG SHAD */ + || ch == 0x0F11 /* TIBETAN MARK RIN CHEN SPUNGS SHAD */ + || ch == 0x0F14 /* TIBETAN MARK GTER TSHEG */ + || ch == 0x1802 /* MONGOLIAN COMMA */ + || ch == 0x1803 /* MONGOLIAN FULL STOP */ + || ch == 0x1808 /* MONGOLIAN MANCHU COMMA */ + || ch == 0x1809 /* MONGOLIAN MANCHU FULL STOP */ + || ch == 0x1944 /* LIMBU EXCLAMATION MARK */ + || ch == 0x1945 /* LIMBU QUESTION MARK */ + || ch == 0x2762 /* HEAVY EXCLAMATION MARK ORNAMENT */ + || ch == 0x2763 /* HEAVY HEART EXCLAMATION MARK ORNAMENT */ + || ch == 0x2CF9 /* COPTIC OLD NUBIAN FULL STOP */ + || ch == 0x2CFE /* COPTIC FULL STOP */ + || ch == 0x2E2E /* REVERSED QUESTION MARK */ #if REVISION_22 - || ch == 0xA60C /* VAI SYLLABLE LENGTHENER */ + || ch == 0xA60C /* VAI SYLLABLE LENGTHENER */ #endif - || ch == 0xA60E /* VAI FULL STOP */ - || ch == 0xA876 /* PHAGS-PA MARK SHAD */ - || ch == 0xA877 /* PHAGS-PA MARK DOUBLE SHAD */ - || ch == 0xFE15 /* PRESENTATION FORM FOR VERTICAL EXCLAMATION MARK */ - || ch == 0xFE16 /* PRESENTATION FORM FOR VERTICAL QUESTION MARK */ - || ch == 0xFE56 /* SMALL QUESTION MARK */ - || ch == 0xFE57 /* SMALL EXCLAMATION MARK */ - || ch == 0xFF01 /* FULLWIDTH EXCLAMATION MARK */ - || ch == 0xFF1F /* FULLWIDTH QUESTION MARK */) - attr |= 1 << LBP_EX; + || ch == 0xA60E /* VAI FULL STOP */ + || ch == 0xA876 /* PHAGS-PA MARK SHAD */ + || ch == 0xA877 /* PHAGS-PA MARK DOUBLE SHAD */ + || ch == 0xFE15 /* PRESENTATION FORM FOR VERTICAL EXCLAMATION MARK */ + || ch == 0xFE16 /* PRESENTATION FORM FOR VERTICAL QUESTION MARK */ + || ch == 0xFE56 /* SMALL QUESTION MARK */ + || ch == 0xFE57 /* SMALL EXCLAMATION MARK */ + || ch == 0xFF01 /* FULLWIDTH EXCLAMATION MARK */ + || ch == 0xFF1F /* FULLWIDTH QUESTION MARK */) + attr |= 1 << LBP_EX; /* inseparable */ if (ch == 0x2024 /* ONE DOT LEADER */ - || ch == 0x2025 /* TWO DOT LEADER */ - || ch == 0x2026 /* HORIZONTAL ELLIPSIS */ - || ch == 0xFE19 /* PRESENTATION FORM FOR VERTICAL HORIZONTAL ELLIPSIS */) - attr |= 1 << LBP_IN; + || ch == 0x2025 /* TWO DOT LEADER */ + || ch == 0x2026 /* HORIZONTAL ELLIPSIS */ + || ch == 0xFE19 /* PRESENTATION FORM FOR VERTICAL HORIZONTAL ELLIPSIS */) + attr |= 1 << LBP_IN; /* non starter */ if (ch == 0x17D6 /* KHMER SIGN CAMNUC PII KUUH */ - || ch == 0x203C /* DOUBLE EXCLAMATION MARK */ - || ch == 0x203D /* INTERROBANG */ - || ch == 0x2047 /* DOUBLE QUESTION MARK */ - || ch == 0x2048 /* QUESTION EXCLAMATION MARK */ - || ch == 0x2049 /* EXCLAMATION QUESTION MARK */ - || ch == 0x3005 /* IDEOGRAPHIC ITERATION MARK */ - || ch == 0x301C /* WAVE DASH */ - || ch == 0x303C /* MASU MARK */ - || ch == 0x303B /* VERTICAL IDEOGRAPHIC ITERATION MARK */ - || ch == 0x309B /* KATAKANA-HIRAGANA VOICED SOUND MARK */ - || ch == 0x309C /* KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK */ - || ch == 0x309D /* HIRAGANA ITERATION MARK */ - || ch == 0x309E /* HIRAGANA VOICED ITERATION MARK */ - || ch == 0x30A0 /* KATAKANA-HIRAGANA DOUBLE HYPHEN */ - || ch == 0x30FB /* KATAKANA MIDDLE DOT */ - || ch == 0x30FC /* KATAKANA-HIRAGANA PROLONGED SOUND MARK */ - || ch == 0x30FD /* KATAKANA ITERATION MARK */ - || ch == 0x30FE /* KATAKANA VOICED ITERATION MARK */ - || ch == 0xA015 /* YI SYLLABLE WU */ - || ch == 0xFE54 /* SMALL SEMICOLON */ - || ch == 0xFE55 /* SMALL COLON */ - || ch == 0xFF1A /* FULLWIDTH COLON */ - || ch == 0xFF1B /* FULLWIDTH SEMICOLON */ - || ch == 0xFF65 /* HALFWIDTH KATAKANA MIDDLE DOT */ - || ch == 0xFF70 /* HALFWIDTH KATAKANA-HIRAGANA PROLONGED SOUND MARK */ - || ch == 0xFF9E /* HALFWIDTH KATAKANA VOICED SOUND MARK */ - || ch == 0xFF9F /* HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK */ - || strstr (unicode_attributes[ch].name, "HIRAGANA LETTER SMALL ") != NULL - || strstr (unicode_attributes[ch].name, "KATAKANA LETTER SMALL ") != NULL) - attr |= 1 << LBP_NS; + || ch == 0x203C /* DOUBLE EXCLAMATION MARK */ + || ch == 0x203D /* INTERROBANG */ + || ch == 0x2047 /* DOUBLE QUESTION MARK */ + || ch == 0x2048 /* QUESTION EXCLAMATION MARK */ + || ch == 0x2049 /* EXCLAMATION QUESTION MARK */ + || ch == 0x3005 /* IDEOGRAPHIC ITERATION MARK */ + || ch == 0x301C /* WAVE DASH */ + || ch == 0x303C /* MASU MARK */ + || ch == 0x303B /* VERTICAL IDEOGRAPHIC ITERATION MARK */ + || ch == 0x309B /* KATAKANA-HIRAGANA VOICED SOUND MARK */ + || ch == 0x309C /* KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK */ + || ch == 0x309D /* HIRAGANA ITERATION MARK */ + || ch == 0x309E /* HIRAGANA VOICED ITERATION MARK */ + || ch == 0x30A0 /* KATAKANA-HIRAGANA DOUBLE HYPHEN */ + || ch == 0x30FB /* KATAKANA MIDDLE DOT */ + || ch == 0x30FC /* KATAKANA-HIRAGANA PROLONGED SOUND MARK */ + || ch == 0x30FD /* KATAKANA ITERATION MARK */ + || ch == 0x30FE /* KATAKANA VOICED ITERATION MARK */ + || ch == 0xA015 /* YI SYLLABLE WU */ + || ch == 0xFE54 /* SMALL SEMICOLON */ + || ch == 0xFE55 /* SMALL COLON */ + || ch == 0xFF1A /* FULLWIDTH COLON */ + || ch == 0xFF1B /* FULLWIDTH SEMICOLON */ + || ch == 0xFF65 /* HALFWIDTH KATAKANA MIDDLE DOT */ + || ch == 0xFF70 /* HALFWIDTH KATAKANA-HIRAGANA PROLONGED SOUND MARK */ + || ch == 0xFF9E /* HALFWIDTH KATAKANA VOICED SOUND MARK */ + || ch == 0xFF9F /* HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK */ + || strstr (unicode_attributes[ch].name, "HIRAGANA LETTER SMALL ") != NULL + || strstr (unicode_attributes[ch].name, "KATAKANA LETTER SMALL ") != NULL) + attr |= 1 << LBP_NS; /* opening punctuation */ if ((unicode_attributes[ch].category[0] == 'P' - && unicode_attributes[ch].category[1] == 's') - || ch == 0x00A1 /* INVERTED EXCLAMATION MARK */ - || ch == 0x00BF /* INVERTED QUESTION MARK */ - || ch == 0x2E18 /* INVERTED INTERROBANG */) - attr |= 1 << LBP_OP; + && unicode_attributes[ch].category[1] == 's') + || ch == 0x00A1 /* INVERTED EXCLAMATION MARK */ + || ch == 0x00BF /* INVERTED QUESTION MARK */ + || ch == 0x2E18 /* INVERTED INTERROBANG */) + attr |= 1 << LBP_OP; /* ambiguous quotation */ if ((unicode_attributes[ch].category[0] == 'P' - && (unicode_attributes[ch].category[1] == 'f' - || unicode_attributes[ch].category[1] == 'i')) - || ch == 0x0022 /* QUOTATION MARK */ - || ch == 0x0027 /* APOSTROPHE */ - || ch == 0x275B /* HEAVY SINGLE TURNED COMMA QUOTATION MARK ORNAMENT */ - || ch == 0x275C /* HEAVY SINGLE COMMA QUOTATION MARK ORNAMENT */ - || ch == 0x275D /* HEAVY DOUBLE TURNED COMMA QUOTATION MARK ORNAMENT */ - || ch == 0x275E /* HEAVY DOUBLE COMMA QUOTATION MARK ORNAMENT */ - || ch == 0x2E00 /* RIGHT ANGLE SUBSTITUTION MARKER */ - || ch == 0x2E01 /* RIGHT ANGLE DOTTED SUBSTITUTION MARKER */ - || ch == 0x2E06 /* RAISED INTERPOLATION MARKER */ - || ch == 0x2E07 /* RAISED DOTTED INTERPOLATION MARKER */ - || ch == 0x2E08 /* DOTTED TRANSPOSITION MARKER */ - || ch == 0x2E0B /* RAISED SQUARE */) - attr |= 1 << LBP_QU; + && (unicode_attributes[ch].category[1] == 'f' + || unicode_attributes[ch].category[1] == 'i')) + || ch == 0x0022 /* QUOTATION MARK */ + || ch == 0x0027 /* APOSTROPHE */ + || ch == 0x275B /* HEAVY SINGLE TURNED COMMA QUOTATION MARK ORNAMENT */ + || ch == 0x275C /* HEAVY SINGLE COMMA QUOTATION MARK ORNAMENT */ + || ch == 0x275D /* HEAVY DOUBLE TURNED COMMA QUOTATION MARK ORNAMENT */ + || ch == 0x275E /* HEAVY DOUBLE COMMA QUOTATION MARK ORNAMENT */ + || ch == 0x2E00 /* RIGHT ANGLE SUBSTITUTION MARKER */ + || ch == 0x2E01 /* RIGHT ANGLE DOTTED SUBSTITUTION MARKER */ + || ch == 0x2E06 /* RAISED INTERPOLATION MARKER */ + || ch == 0x2E07 /* RAISED DOTTED INTERPOLATION MARKER */ + || ch == 0x2E08 /* DOTTED TRANSPOSITION MARKER */ + || ch == 0x2E0B /* RAISED SQUARE */) + attr |= 1 << LBP_QU; /* infix separator (numeric) */ if (ch == 0x002C /* COMMA */ - || ch == 0x002E /* FULL STOP */ - || ch == 0x003A /* COLON */ - || ch == 0x003B /* SEMICOLON */ - || ch == 0x037E /* GREEK QUESTION MARK */ - || ch == 0x0589 /* ARMENIAN FULL STOP */ - || ch == 0x060C /* ARABIC COMMA */ - || ch == 0x060D /* ARABIC DATE SEPARATOR */ - || ch == 0x07F8 /* NKO COMMA */ - || ch == 0x2044 /* FRACTION SLASH */ - || ch == 0xFE10 /* PRESENTATION FORM FOR VERTICAL COMMA */ - || ch == 0xFE13 /* PRESENTATION FORM FOR VERTICAL COLON */ - || ch == 0xFE14 /* PRESENTATION FORM FOR VERTICAL SEMICOLON */) - attr |= 1 << LBP_IS; + || ch == 0x002E /* FULL STOP */ + || ch == 0x003A /* COLON */ + || ch == 0x003B /* SEMICOLON */ + || ch == 0x037E /* GREEK QUESTION MARK */ + || ch == 0x0589 /* ARMENIAN FULL STOP */ + || ch == 0x060C /* ARABIC COMMA */ + || ch == 0x060D /* ARABIC DATE SEPARATOR */ + || ch == 0x07F8 /* NKO COMMA */ + || ch == 0x2044 /* FRACTION SLASH */ + || ch == 0xFE10 /* PRESENTATION FORM FOR VERTICAL COMMA */ + || ch == 0xFE13 /* PRESENTATION FORM FOR VERTICAL COLON */ + || ch == 0xFE14 /* PRESENTATION FORM FOR VERTICAL SEMICOLON */) + attr |= 1 << LBP_IS; /* numeric */ if ((unicode_attributes[ch].category[0] == 'N' - && unicode_attributes[ch].category[1] == 'd' - && strstr (unicode_attributes[ch].name, "FULLWIDTH") == NULL) - || ch == 0x066B /* ARABIC DECIMAL SEPARATOR */ - || ch == 0x066C /* ARABIC THOUSANDS SEPARATOR */) - attr |= 1 << LBP_NU; + && unicode_attributes[ch].category[1] == 'd' + && strstr (unicode_attributes[ch].name, "FULLWIDTH") == NULL) + || ch == 0x066B /* ARABIC DECIMAL SEPARATOR */ + || ch == 0x066C /* ARABIC THOUSANDS SEPARATOR */) + attr |= 1 << LBP_NU; /* postfix (numeric) */ if (ch == 0x0025 /* PERCENT SIGN */ - || ch == 0x00A2 /* CENT SIGN */ - || ch == 0x00B0 /* DEGREE SIGN */ - || ch == 0x060B /* AFGHANI SIGN */ - || ch == 0x066A /* ARABIC PERCENT SIGN */ - || ch == 0x2030 /* PER MILLE SIGN */ - || ch == 0x2031 /* PER TEN THOUSAND SIGN */ - || ch == 0x2032 /* PRIME */ - || ch == 0x2033 /* DOUBLE PRIME */ - || ch == 0x2034 /* TRIPLE PRIME */ - || ch == 0x2035 /* REVERSED PRIME */ - || ch == 0x2036 /* REVERSED DOUBLE PRIME */ - || ch == 0x2037 /* REVERSED TRIPLE PRIME */ - || ch == 0x20A7 /* PESETA SIGN */ - || ch == 0x2103 /* DEGREE CELSIUS */ - || ch == 0x2109 /* DEGREE FAHRENHEIT */ - || ch == 0xFDFC /* RIAL SIGN */ - || ch == 0xFE6A /* SMALL PERCENT SIGN */ - || ch == 0xFF05 /* FULLWIDTH PERCENT SIGN */ - || ch == 0xFFE0 /* FULLWIDTH DIGIT ZERO */ - /* Extra characters for compatibility with Unicode LineBreak.txt. */ - || ch == 0x0609 /* ARABIC-INDIC PER MILLE SIGN */ - || ch == 0x060A /* ARABIC-INDIC PER TEN THOUSAND SIGN */ - || ch == 0x0D79 /* MALAYALAM DATE MARK */) - attr |= 1 << LBP_PO; + || ch == 0x00A2 /* CENT SIGN */ + || ch == 0x00B0 /* DEGREE SIGN */ + || ch == 0x060B /* AFGHANI SIGN */ + || ch == 0x066A /* ARABIC PERCENT SIGN */ + || ch == 0x2030 /* PER MILLE SIGN */ + || ch == 0x2031 /* PER TEN THOUSAND SIGN */ + || ch == 0x2032 /* PRIME */ + || ch == 0x2033 /* DOUBLE PRIME */ + || ch == 0x2034 /* TRIPLE PRIME */ + || ch == 0x2035 /* REVERSED PRIME */ + || ch == 0x2036 /* REVERSED DOUBLE PRIME */ + || ch == 0x2037 /* REVERSED TRIPLE PRIME */ + || ch == 0x20A7 /* PESETA SIGN */ + || ch == 0x2103 /* DEGREE CELSIUS */ + || ch == 0x2109 /* DEGREE FAHRENHEIT */ + || ch == 0xFDFC /* RIAL SIGN */ + || ch == 0xFE6A /* SMALL PERCENT SIGN */ + || ch == 0xFF05 /* FULLWIDTH PERCENT SIGN */ + || ch == 0xFFE0 /* FULLWIDTH DIGIT ZERO */ + /* Extra characters for compatibility with Unicode LineBreak.txt. */ + || ch == 0x0609 /* ARABIC-INDIC PER MILLE SIGN */ + || ch == 0x060A /* ARABIC-INDIC PER TEN THOUSAND SIGN */ + || ch == 0x0D79 /* MALAYALAM DATE MARK */) + attr |= 1 << LBP_PO; /* prefix (numeric) */ if ((unicode_attributes[ch].category[0] == 'S' - && unicode_attributes[ch].category[1] == 'c') - || ch == 0x002B /* PLUS SIGN */ - || ch == 0x005C /* REVERSE SOLIDUS */ - || ch == 0x00B1 /* PLUS-MINUS SIGN */ - || ch == 0x2116 /* NUMERO SIGN */ - || ch == 0x2212 /* MINUS SIGN */ - || ch == 0x2213 /* MINUS-OR-PLUS SIGN */) - if (!(attr & (1 << LBP_PO))) - attr |= 1 << LBP_PR; + && unicode_attributes[ch].category[1] == 'c') + || ch == 0x002B /* PLUS SIGN */ + || ch == 0x005C /* REVERSE SOLIDUS */ + || ch == 0x00B1 /* PLUS-MINUS SIGN */ + || ch == 0x2116 /* NUMERO SIGN */ + || ch == 0x2212 /* MINUS SIGN */ + || ch == 0x2213 /* MINUS-OR-PLUS SIGN */) + if (!(attr & (1 << LBP_PO))) + attr |= 1 << LBP_PR; /* symbols allowing breaks */ if (ch == 0x002F /* SOLIDUS */) - attr |= 1 << LBP_SY; + attr |= 1 << LBP_SY; if (ch >= 0xAC00 && ch <= 0xD7A3 && ((ch - 0xAC00) % 28) == 0) - attr |= 1 << LBP_H2; + attr |= 1 << LBP_H2; if (ch >= 0xAC00 && ch <= 0xD7A3 && ((ch - 0xAC00) % 28) != 0) - attr |= 1 << LBP_H3; + attr |= 1 << LBP_H3; if ((ch >= 0x1100 && ch <= 0x1159) || ch == 0x115F) - attr |= 1 << LBP_JL; + attr |= 1 << LBP_JL; if (ch >= 0x1160 && ch <= 0x11A2) - attr |= 1 << LBP_JV; + attr |= 1 << LBP_JV; if (ch >= 0x11A8 && ch <= 0x11F9) - attr |= 1 << LBP_JT; + attr |= 1 << LBP_JT; /* complex context (South East Asian) */ if (((unicode_attributes[ch].category[0] == 'C' - && unicode_attributes[ch].category[1] == 'f') - || (unicode_attributes[ch].category[0] == 'L' - && (unicode_attributes[ch].category[1] == 'm' - || unicode_attributes[ch].category[1] == 'o')) - || (unicode_attributes[ch].category[0] == 'M' - && (unicode_attributes[ch].category[1] == 'c' - || unicode_attributes[ch].category[1] == 'n')) - /* Extra characters for compatibility with Unicode LineBreak.txt. */ - || ch == 0x109E /* MYANMAR SYMBOL SHAN ONE */ - || ch == 0x109F /* MYANMAR SYMBOL SHAN EXCLAMATION */ - || ch == 0x19DE /* NEW TAI LUE SIGN LAE */ - || ch == 0x19DF /* NEW TAI LUE SIGN LAEV */) - && ((ch >= 0x0E00 && ch <= 0x0EFF) - || (ch >= 0x1000 && ch <= 0x109F) - || (ch >= 0x1780 && ch <= 0x17FF) - || (ch >= 0x1950 && ch <= 0x19DF))) - attr |= 1 << LBP_SA; + && unicode_attributes[ch].category[1] == 'f') + || (unicode_attributes[ch].category[0] == 'L' + && (unicode_attributes[ch].category[1] == 'm' + || unicode_attributes[ch].category[1] == 'o')) + || (unicode_attributes[ch].category[0] == 'M' + && (unicode_attributes[ch].category[1] == 'c' + || unicode_attributes[ch].category[1] == 'n')) + /* Extra characters for compatibility with Unicode LineBreak.txt. */ + || ch == 0x109E /* MYANMAR SYMBOL SHAN ONE */ + || ch == 0x109F /* MYANMAR SYMBOL SHAN EXCLAMATION */ + || ch == 0x19DE /* NEW TAI LUE SIGN LAE */ + || ch == 0x19DF /* NEW TAI LUE SIGN LAEV */) + && ((ch >= 0x0E00 && ch <= 0x0EFF) + || (ch >= 0x1000 && ch <= 0x109F) + || (ch >= 0x1780 && ch <= 0x17FF) + || (ch >= 0x1950 && ch <= 0x19DF))) + attr |= 1 << LBP_SA; /* attached characters and combining marks */ if ((unicode_attributes[ch].category[0] == 'M' - && (unicode_attributes[ch].category[1] == 'c' - || unicode_attributes[ch].category[1] == 'e' - || unicode_attributes[ch].category[1] == 'n')) - || (unicode_attributes[ch].category[0] == 'C' - && (unicode_attributes[ch].category[1] == 'c' - || unicode_attributes[ch].category[1] == 'f'))) - if (!(attr & ((1 << LBP_BK) | (1 << LBP_BA) | (1 << LBP_GL) | (1 << LBP_SA) | (1 << LBP_WJ) | (1 << LBP_ZW)))) - attr |= 1 << LBP_CM; + && (unicode_attributes[ch].category[1] == 'c' + || unicode_attributes[ch].category[1] == 'e' + || unicode_attributes[ch].category[1] == 'n')) + || (unicode_attributes[ch].category[0] == 'C' + && (unicode_attributes[ch].category[1] == 'c' + || unicode_attributes[ch].category[1] == 'f'))) + if (!(attr & ((1 << LBP_BK) | (1 << LBP_BA) | (1 << LBP_GL) | (1 << LBP_SA) | (1 << LBP_WJ) | (1 << LBP_ZW)))) + attr |= 1 << LBP_CM; /* ideographic */ if ((ch >= 0x2E80 && ch <= 0x2FFF) /* CJK RADICAL, KANGXI RADICAL, IDEOGRAPHIC DESCRIPTION */ - || ch == 0x3000 /* IDEOGRAPHIC SPACE */ - || (ch >= 0x3040 && ch <= 0x309F) /* HIRAGANA */ - || (ch >= 0x30A0 && ch <= 0x30FF) /* KATAKANA */ - || (ch >= 0x3400 && ch <= 0x4DB5) /* CJK Ideograph Extension A */ - || (ch >= 0x4E00 && ch <= 0x9FC3) /* CJK Ideograph */ - || (ch >= 0xF900 && ch <= 0xFAD9) /* CJK COMPATIBILITY IDEOGRAPH */ - || (ch >= 0xA000 && ch <= 0xA48F) /* YI SYLLABLE */ - || (ch >= 0xA490 && ch <= 0xA4CF) /* YI RADICAL */ - || ch == 0xFE62 /* SMALL PLUS SIGN */ - || ch == 0xFE63 /* SMALL HYPHEN-MINUS */ - || ch == 0xFE64 /* SMALL LESS-THAN SIGN */ - || ch == 0xFE65 /* SMALL GREATER-THAN SIGN */ - || ch == 0xFE66 /* SMALL EQUALS SIGN */ - || (ch >= 0xFF10 && ch <= 0xFF19) /* FULLWIDTH DIGIT */ - || (ch >= 0x20000 && ch <= 0x2A6D6) /* CJK Ideograph Extension B */ - || (ch >= 0x2F800 && ch <= 0x2FA1D) /* CJK COMPATIBILITY IDEOGRAPH */ - || strstr (unicode_attributes[ch].name, "FULLWIDTH LATIN ") != NULL - || (ch >= 0x3000 && ch <= 0x33FF - && !(attr & ((1 << LBP_CM) | (1 << LBP_NS) | (1 << LBP_OP) | (1 << LBP_CL)))) - /* Extra characters for compatibility with Unicode LineBreak.txt. */ - || ch == 0xFE30 /* PRESENTATION FORM FOR VERTICAL TWO DOT LEADER */ - || ch == 0xFE31 /* PRESENTATION FORM FOR VERTICAL EM DASH */ - || ch == 0xFE32 /* PRESENTATION FORM FOR VERTICAL EN DASH */ - || ch == 0xFE33 /* PRESENTATION FORM FOR VERTICAL LOW LINE */ - || ch == 0xFE34 /* PRESENTATION FORM FOR VERTICAL WAVY LOW LINE */ - || ch == 0xFE45 /* SESAME DOT */ - || ch == 0xFE46 /* WHITE SESAME DOT */ - || ch == 0xFE49 /* DASHED OVERLINE */ - || ch == 0xFE4A /* CENTRELINE OVERLINE */ - || ch == 0xFE4B /* WAVY OVERLINE */ - || ch == 0xFE4C /* DOUBLE WAVY OVERLINE */ - || ch == 0xFE4D /* DASHED LOW LINE */ - || ch == 0xFE4E /* CENTRELINE LOW LINE */ - || ch == 0xFE4F /* WAVY LOW LINE */ - || ch == 0xFE51 /* SMALL IDEOGRAPHIC COMMA */ - || ch == 0xFE58 /* SMALL EM DASH */ - || ch == 0xFE5F /* SMALL NUMBER SIGN */ - || ch == 0xFE60 /* SMALL AMPERSAND */ - || ch == 0xFE61 /* SMALL ASTERISK */ - || ch == 0xFE68 /* SMALL REVERSE SOLIDUS */ - || ch == 0xFE6B /* SMALL COMMERCIAL AT */ - || ch == 0xFF02 /* FULLWIDTH QUOTATION MARK */ - || ch == 0xFF03 /* FULLWIDTH NUMBER SIGN */ - || ch == 0xFF06 /* FULLWIDTH AMPERSAND */ - || ch == 0xFF07 /* FULLWIDTH APOSTROPHE */ - || ch == 0xFF0A /* FULLWIDTH ASTERISK */ - || ch == 0xFF0B /* FULLWIDTH PLUS SIGN */ - || ch == 0xFF0D /* FULLWIDTH HYPHEN-MINUS */ - || ch == 0xFF0F /* FULLWIDTH SOLIDUS */ - || ch == 0xFF1C /* FULLWIDTH LESS-THAN SIGN */ - || ch == 0xFF1D /* FULLWIDTH EQUALS SIGN */ - || ch == 0xFF1E /* FULLWIDTH GREATER-THAN SIGN */ - || ch == 0xFF20 /* FULLWIDTH COMMERCIAL AT */ - || ch == 0xFF3C /* FULLWIDTH REVERSE SOLIDUS */ - || ch == 0xFF3E /* FULLWIDTH CIRCUMFLEX ACCENT */ - || ch == 0xFF3F /* FULLWIDTH LOW LINE */ - || ch == 0xFF40 /* FULLWIDTH GRAVE ACCENT */ - || ch == 0xFF5C /* FULLWIDTH VERTICAL LINE */ - || ch == 0xFF5E /* FULLWIDTH TILDE */ - || ch == 0xFFE2 /* FULLWIDTH NOT SIGN */ - || ch == 0xFFE3 /* FULLWIDTH MACRON */ - || ch == 0xFFE4 /* FULLWIDTH BROKEN BAR */) - if (!(attr & ((1 << LBP_NS) | (1 << LBP_CM)))) - { - /* ambiguous (ideograph) ? */ - if ((unicode_width[ch] != NULL - && unicode_width[ch][0] == 'A' - && ch >= 0x2000) - || ch == 0x24EA /* CIRCLED DIGIT ZERO */ - || (ch >= 0x2780 && ch <= 0x2793) /* DINGBAT ... CIRCLED DIGIT ... */) - attr |= 1 << LBP_AI; - else - attr |= 1 << LBP_ID; - } + || ch == 0x3000 /* IDEOGRAPHIC SPACE */ + || (ch >= 0x3040 && ch <= 0x309F) /* HIRAGANA */ + || (ch >= 0x30A0 && ch <= 0x30FF) /* KATAKANA */ + || (ch >= 0x3400 && ch <= 0x4DB5) /* CJK Ideograph Extension A */ + || (ch >= 0x4E00 && ch <= 0x9FC3) /* CJK Ideograph */ + || (ch >= 0xF900 && ch <= 0xFAD9) /* CJK COMPATIBILITY IDEOGRAPH */ + || (ch >= 0xA000 && ch <= 0xA48F) /* YI SYLLABLE */ + || (ch >= 0xA490 && ch <= 0xA4CF) /* YI RADICAL */ + || ch == 0xFE62 /* SMALL PLUS SIGN */ + || ch == 0xFE63 /* SMALL HYPHEN-MINUS */ + || ch == 0xFE64 /* SMALL LESS-THAN SIGN */ + || ch == 0xFE65 /* SMALL GREATER-THAN SIGN */ + || ch == 0xFE66 /* SMALL EQUALS SIGN */ + || (ch >= 0xFF10 && ch <= 0xFF19) /* FULLWIDTH DIGIT */ + || (ch >= 0x20000 && ch <= 0x2A6D6) /* CJK Ideograph Extension B */ + || (ch >= 0x2F800 && ch <= 0x2FA1D) /* CJK COMPATIBILITY IDEOGRAPH */ + || strstr (unicode_attributes[ch].name, "FULLWIDTH LATIN ") != NULL + || (ch >= 0x3000 && ch <= 0x33FF + && !(attr & ((1 << LBP_CM) | (1 << LBP_NS) | (1 << LBP_OP) | (1 << LBP_CL)))) + /* Extra characters for compatibility with Unicode LineBreak.txt. */ + || ch == 0xFE30 /* PRESENTATION FORM FOR VERTICAL TWO DOT LEADER */ + || ch == 0xFE31 /* PRESENTATION FORM FOR VERTICAL EM DASH */ + || ch == 0xFE32 /* PRESENTATION FORM FOR VERTICAL EN DASH */ + || ch == 0xFE33 /* PRESENTATION FORM FOR VERTICAL LOW LINE */ + || ch == 0xFE34 /* PRESENTATION FORM FOR VERTICAL WAVY LOW LINE */ + || ch == 0xFE45 /* SESAME DOT */ + || ch == 0xFE46 /* WHITE SESAME DOT */ + || ch == 0xFE49 /* DASHED OVERLINE */ + || ch == 0xFE4A /* CENTRELINE OVERLINE */ + || ch == 0xFE4B /* WAVY OVERLINE */ + || ch == 0xFE4C /* DOUBLE WAVY OVERLINE */ + || ch == 0xFE4D /* DASHED LOW LINE */ + || ch == 0xFE4E /* CENTRELINE LOW LINE */ + || ch == 0xFE4F /* WAVY LOW LINE */ + || ch == 0xFE51 /* SMALL IDEOGRAPHIC COMMA */ + || ch == 0xFE58 /* SMALL EM DASH */ + || ch == 0xFE5F /* SMALL NUMBER SIGN */ + || ch == 0xFE60 /* SMALL AMPERSAND */ + || ch == 0xFE61 /* SMALL ASTERISK */ + || ch == 0xFE68 /* SMALL REVERSE SOLIDUS */ + || ch == 0xFE6B /* SMALL COMMERCIAL AT */ + || ch == 0xFF02 /* FULLWIDTH QUOTATION MARK */ + || ch == 0xFF03 /* FULLWIDTH NUMBER SIGN */ + || ch == 0xFF06 /* FULLWIDTH AMPERSAND */ + || ch == 0xFF07 /* FULLWIDTH APOSTROPHE */ + || ch == 0xFF0A /* FULLWIDTH ASTERISK */ + || ch == 0xFF0B /* FULLWIDTH PLUS SIGN */ + || ch == 0xFF0D /* FULLWIDTH HYPHEN-MINUS */ + || ch == 0xFF0F /* FULLWIDTH SOLIDUS */ + || ch == 0xFF1C /* FULLWIDTH LESS-THAN SIGN */ + || ch == 0xFF1D /* FULLWIDTH EQUALS SIGN */ + || ch == 0xFF1E /* FULLWIDTH GREATER-THAN SIGN */ + || ch == 0xFF20 /* FULLWIDTH COMMERCIAL AT */ + || ch == 0xFF3C /* FULLWIDTH REVERSE SOLIDUS */ + || ch == 0xFF3E /* FULLWIDTH CIRCUMFLEX ACCENT */ + || ch == 0xFF3F /* FULLWIDTH LOW LINE */ + || ch == 0xFF40 /* FULLWIDTH GRAVE ACCENT */ + || ch == 0xFF5C /* FULLWIDTH VERTICAL LINE */ + || ch == 0xFF5E /* FULLWIDTH TILDE */ + || ch == 0xFFE2 /* FULLWIDTH NOT SIGN */ + || ch == 0xFFE3 /* FULLWIDTH MACRON */ + || ch == 0xFFE4 /* FULLWIDTH BROKEN BAR */) + if (!(attr & ((1 << LBP_NS) | (1 << LBP_CM)))) + { + /* ambiguous (ideograph) ? */ + if ((unicode_width[ch] != NULL + && unicode_width[ch][0] == 'A' + && ch >= 0x2000) + || ch == 0x24EA /* CIRCLED DIGIT ZERO */ + || (ch >= 0x2780 && ch <= 0x2793) /* DINGBAT ... CIRCLED DIGIT ... */) + attr |= 1 << LBP_AI; + else + attr |= 1 << LBP_ID; + } /* ordinary alphabetic and symbol characters */ if ((unicode_attributes[ch].category[0] == 'L' - && (unicode_attributes[ch].category[1] == 'u' - || unicode_attributes[ch].category[1] == 'l' - || unicode_attributes[ch].category[1] == 't' - || unicode_attributes[ch].category[1] == 'm' - || unicode_attributes[ch].category[1] == 'o')) - || (unicode_attributes[ch].category[0] == 'S' - && (unicode_attributes[ch].category[1] == 'm' - || unicode_attributes[ch].category[1] == 'k' - || unicode_attributes[ch].category[1] == 'o')) - || (unicode_attributes[ch].category[0] == 'N' - && (unicode_attributes[ch].category[1] == 'l' - || unicode_attributes[ch].category[1] == 'o')) - || (unicode_attributes[ch].category[0] == 'P' - && (unicode_attributes[ch].category[1] == 'c' - || unicode_attributes[ch].category[1] == 'd' - || unicode_attributes[ch].category[1] == 'o')) - || ch == 0x0600 /* ARABIC NUMBER SIGN */ - || ch == 0x0601 /* ARABIC SIGN SANAH */ - || ch == 0x0602 /* ARABIC FOOTNOTE MARKER */ - || ch == 0x0603 /* ARABIC SIGN SAFHA */ - || ch == 0x06DD /* ARABIC END OF AYAH */ - || ch == 0x070F /* SYRIAC ABBREVIATION MARK */ - || ch == 0x2061 /* FUNCTION APPLICATION */ - || ch == 0x2062 /* INVISIBLE TIMES */ - || ch == 0x2063 /* INVISIBLE SEPARATOR */ - || ch == 0x2064 /* INVISIBLE PLUS */) - if (!(attr & ((1 << LBP_GL) | (1 << LBP_B2) | (1 << LBP_BA) | (1 << LBP_BB) | (1 << LBP_HY) | (1 << LBP_CB) | (1 << LBP_CL) | (1 << LBP_EX) | (1 << LBP_IN) | (1 << LBP_NS) | (1 << LBP_OP) | (1 << LBP_QU) | (1 << LBP_IS) | (1 << LBP_NU) | (1 << LBP_PO) | (1 << LBP_PR) | (1 << LBP_SY) | (1 << LBP_H2) | (1 << LBP_H3) | (1 << LBP_JL) | (1 << LBP_JV) | (1 << LBP_JT) | (1 << LBP_SA) | (1 << LBP_ID)))) - { - /* ambiguous (alphabetic) ? */ - if ((unicode_width[ch] != NULL - && unicode_width[ch][0] == 'A' - && ch >= 0x2000 - /* Extra exceptions for compatibility with Unicode LineBreak.txt. */ - && ch != 0x2022 /* BULLET */ - && ch != 0x203E /* OVERLINE */ - && ch != 0x2126 /* OHM SIGN */ - && ch != 0x2153 /* VULGAR FRACTION ONE THIRD */ - && ch != 0x215C /* VULGAR FRACTION THREE EIGHTHS */ - && ch != 0x215D /* VULGAR FRACTION FIVE EIGHTHS */ - && ch != 0x21B8 /* NORTH WEST ARROW TO LONG BAR */ - && ch != 0x21B9 /* LEFTWARDS ARROW TO BAR OVER RIGHTWARDS ARROW TO BAR */ - && ch != 0x21E7 /* UPWARDS WHITE ARROW */ - && ch != 0x24FF /* NEGATIVE CIRCLED DIGIT ZERO */ - && ch != 0x273D /* HEAVY TEARDROP-SPOKED ASTERISK */) + && (unicode_attributes[ch].category[1] == 'u' + || unicode_attributes[ch].category[1] == 'l' + || unicode_attributes[ch].category[1] == 't' + || unicode_attributes[ch].category[1] == 'm' + || unicode_attributes[ch].category[1] == 'o')) + || (unicode_attributes[ch].category[0] == 'S' + && (unicode_attributes[ch].category[1] == 'm' + || unicode_attributes[ch].category[1] == 'k' + || unicode_attributes[ch].category[1] == 'o')) + || (unicode_attributes[ch].category[0] == 'N' + && (unicode_attributes[ch].category[1] == 'l' + || unicode_attributes[ch].category[1] == 'o')) + || (unicode_attributes[ch].category[0] == 'P' + && (unicode_attributes[ch].category[1] == 'c' + || unicode_attributes[ch].category[1] == 'd' + || unicode_attributes[ch].category[1] == 'o')) + || ch == 0x0600 /* ARABIC NUMBER SIGN */ + || ch == 0x0601 /* ARABIC SIGN SANAH */ + || ch == 0x0602 /* ARABIC FOOTNOTE MARKER */ + || ch == 0x0603 /* ARABIC SIGN SAFHA */ + || ch == 0x06DD /* ARABIC END OF AYAH */ + || ch == 0x070F /* SYRIAC ABBREVIATION MARK */ + || ch == 0x2061 /* FUNCTION APPLICATION */ + || ch == 0x2062 /* INVISIBLE TIMES */ + || ch == 0x2063 /* INVISIBLE SEPARATOR */ + || ch == 0x2064 /* INVISIBLE PLUS */) + if (!(attr & ((1 << LBP_GL) | (1 << LBP_B2) | (1 << LBP_BA) | (1 << LBP_BB) | (1 << LBP_HY) | (1 << LBP_CB) | (1 << LBP_CL) | (1 << LBP_EX) | (1 << LBP_IN) | (1 << LBP_NS) | (1 << LBP_OP) | (1 << LBP_QU) | (1 << LBP_IS) | (1 << LBP_NU) | (1 << LBP_PO) | (1 << LBP_PR) | (1 << LBP_SY) | (1 << LBP_H2) | (1 << LBP_H3) | (1 << LBP_JL) | (1 << LBP_JV) | (1 << LBP_JT) | (1 << LBP_SA) | (1 << LBP_ID)))) + { + /* ambiguous (alphabetic) ? */ + if ((unicode_width[ch] != NULL + && unicode_width[ch][0] == 'A' + && ch >= 0x2000 + /* Extra exceptions for compatibility with Unicode LineBreak.txt. */ + && ch != 0x2022 /* BULLET */ + && ch != 0x203E /* OVERLINE */ + && ch != 0x2126 /* OHM SIGN */ + && ch != 0x2153 /* VULGAR FRACTION ONE THIRD */ + && ch != 0x215C /* VULGAR FRACTION THREE EIGHTHS */ + && ch != 0x215D /* VULGAR FRACTION FIVE EIGHTHS */ + && ch != 0x21B8 /* NORTH WEST ARROW TO LONG BAR */ + && ch != 0x21B9 /* LEFTWARDS ARROW TO BAR OVER RIGHTWARDS ARROW TO BAR */ + && ch != 0x21E7 /* UPWARDS WHITE ARROW */ + && ch != 0x24FF /* NEGATIVE CIRCLED DIGIT ZERO */ + && ch != 0x273D /* HEAVY TEARDROP-SPOKED ASTERISK */) #if !REVISION_22 - || ch == 0x00A1 /* INVERTED EXCLAMATION MARK */ - || ch == 0x00A7 /* SECTION SIGN */ - || ch == 0x00A8 /* DIAERESIS */ - || ch == 0x00AA /* FEMININE ORDINAL INDICATOR */ - || ch == 0x00B2 /* SUPERSCRIPT TWO */ - || ch == 0x00B3 /* SUPERSCRIPT THREE */ - || ch == 0x00B6 /* PILCROW SIGN */ - || ch == 0x00B7 /* MIDDLE DOT */ - || ch == 0x00B8 /* CEDILLA */ - || ch == 0x00B9 /* SUPERSCRIPT ONE */ - || ch == 0x00BA /* MASCULINE ORDINAL INDICATOR */ - || ch == 0x00BC /* VULGAR FRACTION ONE QUARTER */ - || ch == 0x00BD /* VULGAR FRACTION ONE HALF */ - || ch == 0x00BE /* VULGAR FRACTION THREE QUARTERS */ - || ch == 0x00BF /* INVERTED QUESTION MARK */ - || ch == 0x00D7 /* MULTIPLICATION SIGN */ - || ch == 0x00F7 /* DIVISION SIGN */ - || ch == 0x02C7 /* CARON */ - || ch == 0x02C9 /* MODIFIER LETTER MACRON */ - || ch == 0x02CA /* MODIFIER LETTER ACUTE ACCENT */ - || ch == 0x02CB /* MODIFIER LETTER GRAVE ACCENT */ - || ch == 0x02CD /* MODIFIER LETTER LOW MACRON */ - || ch == 0x02D0 /* MODIFIER LETTER TRIANGULAR COLON */ - || ch == 0x02D8 /* BREVE */ - || ch == 0x02D9 /* DOT ABOVE */ - || ch == 0x02DA /* RING ABOVE */ - || ch == 0x02DB /* OGONEK */ - || ch == 0x02DD /* DOUBLE ACUTE ACCENT */ + || ch == 0x00A1 /* INVERTED EXCLAMATION MARK */ + || ch == 0x00A7 /* SECTION SIGN */ + || ch == 0x00A8 /* DIAERESIS */ + || ch == 0x00AA /* FEMININE ORDINAL INDICATOR */ + || ch == 0x00B2 /* SUPERSCRIPT TWO */ + || ch == 0x00B3 /* SUPERSCRIPT THREE */ + || ch == 0x00B6 /* PILCROW SIGN */ + || ch == 0x00B7 /* MIDDLE DOT */ + || ch == 0x00B8 /* CEDILLA */ + || ch == 0x00B9 /* SUPERSCRIPT ONE */ + || ch == 0x00BA /* MASCULINE ORDINAL INDICATOR */ + || ch == 0x00BC /* VULGAR FRACTION ONE QUARTER */ + || ch == 0x00BD /* VULGAR FRACTION ONE HALF */ + || ch == 0x00BE /* VULGAR FRACTION THREE QUARTERS */ + || ch == 0x00BF /* INVERTED QUESTION MARK */ + || ch == 0x00D7 /* MULTIPLICATION SIGN */ + || ch == 0x00F7 /* DIVISION SIGN */ + || ch == 0x02C7 /* CARON */ + || ch == 0x02C9 /* MODIFIER LETTER MACRON */ + || ch == 0x02CA /* MODIFIER LETTER ACUTE ACCENT */ + || ch == 0x02CB /* MODIFIER LETTER GRAVE ACCENT */ + || ch == 0x02CD /* MODIFIER LETTER LOW MACRON */ + || ch == 0x02D0 /* MODIFIER LETTER TRIANGULAR COLON */ + || ch == 0x02D8 /* BREVE */ + || ch == 0x02D9 /* DOT ABOVE */ + || ch == 0x02DA /* RING ABOVE */ + || ch == 0x02DB /* OGONEK */ + || ch == 0x02DD /* DOUBLE ACUTE ACCENT */ #endif - || ch == 0x24EA /* CIRCLED DIGIT ZERO */ - || (ch >= 0x2780 && ch <= 0x2793) /* DINGBAT ... CIRCLED DIGIT ... */ - /* Extra characters for compatibility with Unicode LineBreak.txt. */ - || ch == 0x2155 /* VULGAR FRACTION ONE FIFTH */ - || ch == 0x2574 /* BOX DRAWINGS LIGHT LEFT */ - || ch == 0x2616 /* WHITE SHOGI PIECE */ - || ch == 0x2617 /* BLACK SHOGI PIECE */) - attr |= 1 << LBP_AI; - else - attr |= 1 << LBP_AL; - attr &= ~(1 << LBP_CM); - } + || ch == 0x24EA /* CIRCLED DIGIT ZERO */ + || (ch >= 0x2780 && ch <= 0x2793) /* DINGBAT ... CIRCLED DIGIT ... */ + /* Extra characters for compatibility with Unicode LineBreak.txt. */ + || ch == 0x2155 /* VULGAR FRACTION ONE FIFTH */ + || ch == 0x2574 /* BOX DRAWINGS LIGHT LEFT */ + || ch == 0x2616 /* WHITE SHOGI PIECE */ + || ch == 0x2617 /* BLACK SHOGI PIECE */) + attr |= 1 << LBP_AI; + else + attr |= 1 << LBP_AL; + attr &= ~(1 << LBP_CM); + } } if (attr == 0) @@ -5787,45 +5787,45 @@ debug_output_lbp (FILE *stream) { int attr = get_lbp (i); if (attr != 1 << LBP_XX) - { - fprintf (stream, "0x%04X", i); + { + fprintf (stream, "0x%04X", i); #define PRINT_BIT(attr,bit) \ if (attr & (1 << bit)) fprintf (stream, " " #bit); - PRINT_BIT(attr,LBP_BK); - PRINT_BIT(attr,LBP_CM); - PRINT_BIT(attr,LBP_WJ); - PRINT_BIT(attr,LBP_ZW); - PRINT_BIT(attr,LBP_GL); - PRINT_BIT(attr,LBP_SP); - PRINT_BIT(attr,LBP_B2); - PRINT_BIT(attr,LBP_BA); - PRINT_BIT(attr,LBP_BB); - PRINT_BIT(attr,LBP_HY); - PRINT_BIT(attr,LBP_CB); - PRINT_BIT(attr,LBP_CL); - PRINT_BIT(attr,LBP_EX); - PRINT_BIT(attr,LBP_IN); - PRINT_BIT(attr,LBP_NS); - PRINT_BIT(attr,LBP_OP); - PRINT_BIT(attr,LBP_QU); - PRINT_BIT(attr,LBP_IS); - PRINT_BIT(attr,LBP_NU); - PRINT_BIT(attr,LBP_PO); - PRINT_BIT(attr,LBP_PR); - PRINT_BIT(attr,LBP_SY); - PRINT_BIT(attr,LBP_AI); - PRINT_BIT(attr,LBP_AL); - PRINT_BIT(attr,LBP_H2); - PRINT_BIT(attr,LBP_H3); - PRINT_BIT(attr,LBP_ID); - PRINT_BIT(attr,LBP_JL); - PRINT_BIT(attr,LBP_JV); - PRINT_BIT(attr,LBP_JT); - PRINT_BIT(attr,LBP_SA); - PRINT_BIT(attr,LBP_XX); + PRINT_BIT(attr,LBP_BK); + PRINT_BIT(attr,LBP_CM); + PRINT_BIT(attr,LBP_WJ); + PRINT_BIT(attr,LBP_ZW); + PRINT_BIT(attr,LBP_GL); + PRINT_BIT(attr,LBP_SP); + PRINT_BIT(attr,LBP_B2); + PRINT_BIT(attr,LBP_BA); + PRINT_BIT(attr,LBP_BB); + PRINT_BIT(attr,LBP_HY); + PRINT_BIT(attr,LBP_CB); + PRINT_BIT(attr,LBP_CL); + PRINT_BIT(attr,LBP_EX); + PRINT_BIT(attr,LBP_IN); + PRINT_BIT(attr,LBP_NS); + PRINT_BIT(attr,LBP_OP); + PRINT_BIT(attr,LBP_QU); + PRINT_BIT(attr,LBP_IS); + PRINT_BIT(attr,LBP_NU); + PRINT_BIT(attr,LBP_PO); + PRINT_BIT(attr,LBP_PR); + PRINT_BIT(attr,LBP_SY); + PRINT_BIT(attr,LBP_AI); + PRINT_BIT(attr,LBP_AL); + PRINT_BIT(attr,LBP_H2); + PRINT_BIT(attr,LBP_H3); + PRINT_BIT(attr,LBP_ID); + PRINT_BIT(attr,LBP_JL); + PRINT_BIT(attr,LBP_JV); + PRINT_BIT(attr,LBP_JT); + PRINT_BIT(attr,LBP_SA); + PRINT_BIT(attr,LBP_XX); #undef PRINT_BIT - fprintf (stream, "\n"); - } + fprintf (stream, "\n"); + } } } @@ -5884,24 +5884,24 @@ fill_org_lbp (const char *linebreak_filename) lineno++; c = getc (stream); if (c == EOF) - break; + break; if (c == '#') - { - do c = getc (stream); while (c != EOF && c != '\n'); - continue; - } + { + do c = getc (stream); while (c != EOF && c != '\n'); + continue; + } ungetc (c, stream); n = getfield (stream, field0, ';'); n += getfield (stream, field1, ' '); n += getfield (stream, field2, '\n'); if (n == 0) - break; + break; if (n != 3) - { - fprintf (stderr, "short line in '%s':%d\n", linebreak_filename, - lineno); - exit (1); - } + { + fprintf (stderr, "short line in '%s':%d\n", linebreak_filename, + lineno); + exit (1); + } #define TRY(bit) else if (strcmp (field1, #bit + 4) == 0) value = bit; if (false) {} TRY(LBP_BK) @@ -5942,24 +5942,24 @@ fill_org_lbp (const char *linebreak_filename) else if (strcmp (field1, "NL") == 0) value = LBP_BK; else if (strcmp (field1, "SG") == 0) value = LBP_XX; else - { - fprintf (stderr, "unknown property value \"%s\" in '%s':%d\n", - field1, linebreak_filename, lineno); - exit (1); - } + { + fprintf (stderr, "unknown property value \"%s\" in '%s':%d\n", + field1, linebreak_filename, lineno); + exit (1); + } i = strtoul (field0, NULL, 16); if (strstr (field0, "..") != NULL) - { - /* Deal with a range. */ - j = strtoul (strstr (field0, "..") + 2, NULL, 16); - for (; i <= j; i++) - unicode_org_lbp[i] = value; - } + { + /* Deal with a range. */ + j = strtoul (strstr (field0, "..") + 2, NULL, 16); + for (; i <= j; i++) + unicode_org_lbp[i] = value; + } else - { - /* Single character line. */ - unicode_org_lbp[i] = value; - } + { + /* Single character line. */ + unicode_org_lbp[i] = value; + } } if (ferror (stream) || fclose (stream)) { @@ -5978,45 +5978,45 @@ debug_output_org_lbp (FILE *stream) { int attr = unicode_org_lbp[i]; if (attr != LBP_XX) - { - fprintf (stream, "0x%04X", i); + { + fprintf (stream, "0x%04X", i); #define PRINT_BIT(attr,bit) \ if (attr == bit) fprintf (stream, " " #bit); - PRINT_BIT(attr,LBP_BK); - PRINT_BIT(attr,LBP_CM); - PRINT_BIT(attr,LBP_WJ); - PRINT_BIT(attr,LBP_ZW); - PRINT_BIT(attr,LBP_GL); - PRINT_BIT(attr,LBP_SP); - PRINT_BIT(attr,LBP_B2); - PRINT_BIT(attr,LBP_BA); - PRINT_BIT(attr,LBP_BB); - PRINT_BIT(attr,LBP_HY); - PRINT_BIT(attr,LBP_CB); - PRINT_BIT(attr,LBP_CL); - PRINT_BIT(attr,LBP_EX); - PRINT_BIT(attr,LBP_IN); - PRINT_BIT(attr,LBP_NS); - PRINT_BIT(attr,LBP_OP); - PRINT_BIT(attr,LBP_QU); - PRINT_BIT(attr,LBP_IS); - PRINT_BIT(attr,LBP_NU); - PRINT_BIT(attr,LBP_PO); - PRINT_BIT(attr,LBP_PR); - PRINT_BIT(attr,LBP_SY); - PRINT_BIT(attr,LBP_AI); - PRINT_BIT(attr,LBP_AL); - PRINT_BIT(attr,LBP_H2); - PRINT_BIT(attr,LBP_H3); - PRINT_BIT(attr,LBP_ID); - PRINT_BIT(attr,LBP_JL); - PRINT_BIT(attr,LBP_JV); - PRINT_BIT(attr,LBP_JT); - PRINT_BIT(attr,LBP_SA); - PRINT_BIT(attr,LBP_XX); + PRINT_BIT(attr,LBP_BK); + PRINT_BIT(attr,LBP_CM); + PRINT_BIT(attr,LBP_WJ); + PRINT_BIT(attr,LBP_ZW); + PRINT_BIT(attr,LBP_GL); + PRINT_BIT(attr,LBP_SP); + PRINT_BIT(attr,LBP_B2); + PRINT_BIT(attr,LBP_BA); + PRINT_BIT(attr,LBP_BB); + PRINT_BIT(attr,LBP_HY); + PRINT_BIT(attr,LBP_CB); + PRINT_BIT(attr,LBP_CL); + PRINT_BIT(attr,LBP_EX); + PRINT_BIT(attr,LBP_IN); + PRINT_BIT(attr,LBP_NS); + PRINT_BIT(attr,LBP_OP); + PRINT_BIT(attr,LBP_QU); + PRINT_BIT(attr,LBP_IS); + PRINT_BIT(attr,LBP_NU); + PRINT_BIT(attr,LBP_PO); + PRINT_BIT(attr,LBP_PR); + PRINT_BIT(attr,LBP_SY); + PRINT_BIT(attr,LBP_AI); + PRINT_BIT(attr,LBP_AL); + PRINT_BIT(attr,LBP_H2); + PRINT_BIT(attr,LBP_H3); + PRINT_BIT(attr,LBP_ID); + PRINT_BIT(attr,LBP_JL); + PRINT_BIT(attr,LBP_JV); + PRINT_BIT(attr,LBP_JT); + PRINT_BIT(attr,LBP_SA); + PRINT_BIT(attr,LBP_XX); #undef PRINT_BIT - fprintf (stream, "\n"); - } + fprintf (stream, "\n"); + } } } @@ -6066,15 +6066,15 @@ output_lbp (FILE *stream1, FILE *stream2) /* Now attr should contain exactly one bit. */ if (attr == 0 || ((attr & (attr - 1)) != 0)) - abort (); + abort (); if (attr != 1 << LBP_XX) - { - unsigned int log2_attr; - for (log2_attr = 0; attr > 1; attr >>= 1, log2_attr++); + { + unsigned int log2_attr; + for (log2_attr = 0; attr > 1; attr >>= 1, log2_attr++); - lbp_table_add (&t, i, log2_attr); - } + lbp_table_add (&t, i, log2_attr); + } } lbp_table_finalize (&t); @@ -6091,7 +6091,7 @@ output_lbp (FILE *stream1, FILE *stream2) for (i = 0; i < 5; i++) fprintf (stream1, "#define lbrkprop_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream1, "\n"); fprintf (stream1, "typedef struct\n"); fprintf (stream1, " {\n"); @@ -6111,15 +6111,15 @@ output_lbp (FILE *stream1, FILE *stream2) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream2, "\n "); + fprintf (stream2, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream2, " %5d", -1); + fprintf (stream2, " %5d", -1); else - fprintf (stream2, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream2, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream2, ","); + fprintf (stream2, ","); } if (t.level1_size > 8) fprintf (stream2, "\n "); @@ -6131,15 +6131,15 @@ output_lbp (FILE *stream1, FILE *stream2) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream2, "\n "); + fprintf (stream2, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream2, " %5d", -1); + fprintf (stream2, " %5d", -1); else - fprintf (stream2, " %5zu", - (offset - level3_offset) / sizeof (unsigned char)); + fprintf (stream2, " %5zu", + (offset - level3_offset) / sizeof (unsigned char)); if (i+1 < t.level2_size << t.q) - fprintf (stream2, ","); + fprintf (stream2, ","); } if (t.level2_size << t.q > 8) fprintf (stream2, "\n "); @@ -6152,48 +6152,48 @@ output_lbp (FILE *stream1, FILE *stream2) unsigned char value = ((unsigned char *) (t.result + level3_offset))[i]; const char *value_string; switch (value) - { + { #define CASE(x) case x: value_string = #x; break; - CASE(LBP_BK); - CASE(LBP_CM); - CASE(LBP_WJ); - CASE(LBP_ZW); - CASE(LBP_GL); - CASE(LBP_SP); - CASE(LBP_B2); - CASE(LBP_BA); - CASE(LBP_BB); - CASE(LBP_HY); - CASE(LBP_CB); - CASE(LBP_CL); - CASE(LBP_EX); - CASE(LBP_IN); - CASE(LBP_NS); - CASE(LBP_OP); - CASE(LBP_QU); - CASE(LBP_IS); - CASE(LBP_NU); - CASE(LBP_PO); - CASE(LBP_PR); - CASE(LBP_SY); - CASE(LBP_AI); - CASE(LBP_AL); - CASE(LBP_H2); - CASE(LBP_H3); - CASE(LBP_ID); - CASE(LBP_JL); - CASE(LBP_JV); - CASE(LBP_JT); - CASE(LBP_SA); - CASE(LBP_XX); + CASE(LBP_BK); + CASE(LBP_CM); + CASE(LBP_WJ); + CASE(LBP_ZW); + CASE(LBP_GL); + CASE(LBP_SP); + CASE(LBP_B2); + CASE(LBP_BA); + CASE(LBP_BB); + CASE(LBP_HY); + CASE(LBP_CB); + CASE(LBP_CL); + CASE(LBP_EX); + CASE(LBP_IN); + CASE(LBP_NS); + CASE(LBP_OP); + CASE(LBP_QU); + CASE(LBP_IS); + CASE(LBP_NU); + CASE(LBP_PO); + CASE(LBP_PR); + CASE(LBP_SY); + CASE(LBP_AI); + CASE(LBP_AL); + CASE(LBP_H2); + CASE(LBP_H3); + CASE(LBP_ID); + CASE(LBP_JL); + CASE(LBP_JV); + CASE(LBP_JT); + CASE(LBP_SA); + CASE(LBP_XX); #undef CASE - default: - abort (); - } + default: + abort (); + } if (i > 0 && (i % 8) == 0) - fprintf (stream2, "\n "); + fprintf (stream2, "\n "); fprintf (stream2, " %s%s", value_string, - (i+1 < t.level3_size << t.p ? "," : "")); + (i+1 < t.level3_size << t.p ? "," : "")); } if (t.level3_size << t.p > 8) fprintf (stream2, "\n "); @@ -6215,10 +6215,10 @@ output_lbrk_tables (const char *filename1, const char *filename2, const char *ve { streams[i] = fopen (filenames[i], "w"); if (streams[i] == NULL) - { - fprintf (stderr, "cannot open '%s' for writing\n", filenames[i]); - exit (1); - } + { + fprintf (stderr, "cannot open '%s' for writing\n", filenames[i]); + exit (1); + } } for (i = 0; i < 2; i++) @@ -6228,12 +6228,12 @@ output_lbrk_tables (const char *filename1, const char *filename2, const char *ve fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Line breaking properties of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-lbrk for Unicode %s. */\n", - version); + version); fprintf (stream, "\n"); /* Put a GPL header on it. The gnulib module is under LGPL (although it - still carries the GPL header), and it's gnulib-tool which replaces the - GPL header with an LGPL header. */ + still carries the GPL header), and it's gnulib-tool which replaces the + GPL header with an LGPL header. */ fprintf (stream, "/* Copyright (C) 2000-2002, 2004, 2008 Free Software Foundation, Inc.\n"); fprintf (stream, "\n"); fprintf (stream, " This program is free software: you can redistribute it and/or modify\n"); @@ -6256,10 +6256,10 @@ output_lbrk_tables (const char *filename1, const char *filename2, const char *ve for (i = 0; i < 2; i++) { if (ferror (streams[i]) || fclose (streams[i])) - { - fprintf (stderr, "error writing to '%s'\n", filenames[i]); - exit (1); - } + { + fprintf (stderr, "error writing to '%s'\n", filenames[i]); + exit (1); + } } } @@ -6294,64 +6294,64 @@ get_wbp (unsigned int ch) if (unicode_attributes[ch].name != NULL) { if (ch == 0x000D) - attr |= 1 << WBP_CR; + attr |= 1 << WBP_CR; if (ch == 0x000A) - attr |= 1 << WBP_LF; + attr |= 1 << WBP_LF; if (ch == 0x000B || ch == 0x000C - || ch == 0x0085 - || ch == 0x2028 || ch == 0x2029) - attr |= 1 << WBP_NEWLINE; + || ch == 0x0085 + || ch == 0x2028 || ch == 0x2029) + attr |= 1 << WBP_NEWLINE; if (((unicode_properties[ch] >> PROP_GRAPHEME_EXTEND) & 1) != 0 - || (unicode_attributes[ch].category != NULL - && strcmp (unicode_attributes[ch].category, "Mc") == 0)) - attr |= 1 << WBP_EXTEND; + || (unicode_attributes[ch].category != NULL + && strcmp (unicode_attributes[ch].category, "Mc") == 0)) + attr |= 1 << WBP_EXTEND; if (unicode_attributes[ch].category != NULL - && strcmp (unicode_attributes[ch].category, "Cf") == 0 - && ch != 0x200C && ch != 0x200D) - attr |= 1 << WBP_FORMAT; + && strcmp (unicode_attributes[ch].category, "Cf") == 0 + && ch != 0x200C && ch != 0x200D) + attr |= 1 << WBP_FORMAT; if ((unicode_scripts[ch] < numscripts - && strcmp (scripts[unicode_scripts[ch]], "Katakana") == 0) - || (ch >= 0x3031 && ch <= 0x3035) - || ch == 0x309B || ch == 0x309C || ch == 0x30A0 || ch == 0x30FC - || ch == 0xFF70) - attr |= 1 << WBP_KATAKANA; + && strcmp (scripts[unicode_scripts[ch]], "Katakana") == 0) + || (ch >= 0x3031 && ch <= 0x3035) + || ch == 0x309B || ch == 0x309C || ch == 0x30A0 || ch == 0x30FC + || ch == 0xFF70) + attr |= 1 << WBP_KATAKANA; if ((((unicode_properties[ch] >> PROP_ALPHABETIC) & 1) != 0 - || ch == 0x05F3) - && ((unicode_properties[ch] >> PROP_IDEOGRAPHIC) & 1) == 0 - && (attr & (1 << WBP_KATAKANA)) == 0 - && ((get_lbp (ch) >> LBP_SA) & 1) == 0 - && !(unicode_scripts[ch] < numscripts - && strcmp (scripts[unicode_scripts[ch]], "Hiragana") == 0) - && (attr & (1 << WBP_EXTEND)) == 0) - attr |= 1 << WBP_ALETTER; + || ch == 0x05F3) + && ((unicode_properties[ch] >> PROP_IDEOGRAPHIC) & 1) == 0 + && (attr & (1 << WBP_KATAKANA)) == 0 + && ((get_lbp (ch) >> LBP_SA) & 1) == 0 + && !(unicode_scripts[ch] < numscripts + && strcmp (scripts[unicode_scripts[ch]], "Hiragana") == 0) + && (attr & (1 << WBP_EXTEND)) == 0) + attr |= 1 << WBP_ALETTER; if (ch == 0x0027 || ch == 0x002E || ch == 0x2018 || ch == 0x2019 - || ch == 0x2024 || ch == 0xFE52 || ch == 0xFF07 || ch == 0xFF0E) - attr |= 1 << WBP_MIDNUMLET; + || ch == 0x2024 || ch == 0xFE52 || ch == 0xFF07 || ch == 0xFF0E) + attr |= 1 << WBP_MIDNUMLET; if (ch == 0x00B7 || ch == 0x05F4 || ch == 0x2027 || ch == 0x003A - || ch == 0x0387 || ch == 0xFE13 || ch == 0xFE55 || ch == 0xFF1A) - attr |= 1 << WBP_MIDLETTER; + || ch == 0x0387 || ch == 0xFE13 || ch == 0xFE55 || ch == 0xFF1A) + attr |= 1 << WBP_MIDLETTER; if ((((get_lbp (ch) >> LBP_IS) & 1) != 0 - || ch == 0x066C || ch == 0xFE50 || ch == 0xFE54 || ch == 0xFF0C - || ch == 0xFF1B) - && ch != 0x003A && ch != 0xFE13 && ch != 0x002E) - attr |= 1 << WBP_MIDNUM; + || ch == 0x066C || ch == 0xFE50 || ch == 0xFE54 || ch == 0xFF0C + || ch == 0xFF1B) + && ch != 0x003A && ch != 0xFE13 && ch != 0x002E) + attr |= 1 << WBP_MIDNUM; if (((get_lbp (ch) >> LBP_NU) & 1) != 0 - && ch != 0x066C) - attr |= 1 << WBP_NUMERIC; + && ch != 0x066C) + attr |= 1 << WBP_NUMERIC; if (unicode_attributes[ch].category != NULL - && strcmp (unicode_attributes[ch].category, "Pc") == 0) - attr |= 1 << WBP_EXTENDNUMLET; + && strcmp (unicode_attributes[ch].category, "Pc") == 0) + attr |= 1 << WBP_EXTENDNUMLET; } if (attr == 0) @@ -6371,34 +6371,34 @@ debug_output_wbp (FILE *stream) { int attr = get_wbp (i); if (attr != 1 << WBP_OTHER) - { - fprintf (stream, "0x%04X", i); - if (attr & (1 << WBP_CR)) - fprintf (stream, " CR"); - if (attr & (1 << WBP_LF)) - fprintf (stream, " LF"); - if (attr & (1 << WBP_NEWLINE)) - fprintf (stream, " Newline"); - if (attr & (1 << WBP_EXTEND)) - fprintf (stream, " Extend"); - if (attr & (1 << WBP_FORMAT)) - fprintf (stream, " Format"); - if (attr & (1 << WBP_KATAKANA)) - fprintf (stream, " Katakana"); - if (attr & (1 << WBP_ALETTER)) - fprintf (stream, " ALetter"); - if (attr & (1 << WBP_MIDNUMLET)) - fprintf (stream, " MidNumLet"); - if (attr & (1 << WBP_MIDLETTER)) - fprintf (stream, " MidLetter"); - if (attr & (1 << WBP_MIDNUM)) - fprintf (stream, " MidNum"); - if (attr & (1 << WBP_NUMERIC)) - fprintf (stream, " Numeric"); - if (attr & (1 << WBP_EXTENDNUMLET)) - fprintf (stream, " ExtendNumLet"); - fprintf (stream, "\n"); - } + { + fprintf (stream, "0x%04X", i); + if (attr & (1 << WBP_CR)) + fprintf (stream, " CR"); + if (attr & (1 << WBP_LF)) + fprintf (stream, " LF"); + if (attr & (1 << WBP_NEWLINE)) + fprintf (stream, " Newline"); + if (attr & (1 << WBP_EXTEND)) + fprintf (stream, " Extend"); + if (attr & (1 << WBP_FORMAT)) + fprintf (stream, " Format"); + if (attr & (1 << WBP_KATAKANA)) + fprintf (stream, " Katakana"); + if (attr & (1 << WBP_ALETTER)) + fprintf (stream, " ALetter"); + if (attr & (1 << WBP_MIDNUMLET)) + fprintf (stream, " MidNumLet"); + if (attr & (1 << WBP_MIDLETTER)) + fprintf (stream, " MidLetter"); + if (attr & (1 << WBP_MIDNUM)) + fprintf (stream, " MidNum"); + if (attr & (1 << WBP_NUMERIC)) + fprintf (stream, " Numeric"); + if (attr & (1 << WBP_EXTENDNUMLET)) + fprintf (stream, " ExtendNumLet"); + fprintf (stream, "\n"); + } } } @@ -6453,21 +6453,21 @@ fill_org_wbp (const char *wordbreakproperty_filename) int propvalue; if (fscanf (stream, "%200[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; if (sscanf (buf, "%X..%X%[ ;]%[^ ]", &i1, &i2, padding, propname) != 4) - { - if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, propname) != 3) - { - fprintf (stderr, "parse error in '%s'\n", - wordbreakproperty_filename); - exit (1); - } - i2 = i1; - } + { + if (sscanf (buf, "%X%[ ;]%[^ ]", &i1, padding, propname) != 3) + { + fprintf (stderr, "parse error in '%s'\n", + wordbreakproperty_filename); + exit (1); + } + i2 = i1; + } #define PROP(name,value) \ if (strcmp (propname, name) == 0) propvalue = value; else PROP ("CR", WBP_CR) @@ -6483,16 +6483,16 @@ fill_org_wbp (const char *wordbreakproperty_filename) PROP ("Numeric", WBP_NUMERIC) PROP ("ExtendNumLet", WBP_EXTENDNUMLET) #undef PROP - { - fprintf (stderr, "unknown property value '%s' in '%s'\n", propname, - wordbreakproperty_filename); - exit (1); - } + { + fprintf (stderr, "unknown property value '%s' in '%s'\n", propname, + wordbreakproperty_filename); + exit (1); + } if (!(i1 <= i2 && i2 < 0x110000)) - abort (); + abort (); for (i = i1; i <= i2; i++) - unicode_org_wbp[i] = propvalue; + unicode_org_wbp[i] = propvalue; } if (ferror (stream) || fclose (stream)) @@ -6512,26 +6512,26 @@ debug_output_org_wbp (FILE *stream) { int propvalue = unicode_org_wbp[i]; if (propvalue != WBP_OTHER) - { - fprintf (stream, "0x%04X", i); + { + fprintf (stream, "0x%04X", i); #define PROP(name,value) \ - if (propvalue == value) fprintf (stream, " " name); else - PROP ("CR", WBP_CR) - PROP ("LF", WBP_LF) - PROP ("Newline", WBP_NEWLINE) - PROP ("Extend", WBP_EXTEND) - PROP ("Format", WBP_FORMAT) - PROP ("Katakana", WBP_KATAKANA) - PROP ("ALetter", WBP_ALETTER) - PROP ("MidNumLet", WBP_MIDNUMLET) - PROP ("MidLetter", WBP_MIDLETTER) - PROP ("MidNum", WBP_MIDNUM) - PROP ("Numeric", WBP_NUMERIC) - PROP ("ExtendNumLet", WBP_EXTENDNUMLET) + if (propvalue == value) fprintf (stream, " " name); else + PROP ("CR", WBP_CR) + PROP ("LF", WBP_LF) + PROP ("Newline", WBP_NEWLINE) + PROP ("Extend", WBP_EXTEND) + PROP ("Format", WBP_FORMAT) + PROP ("Katakana", WBP_KATAKANA) + PROP ("ALetter", WBP_ALETTER) + PROP ("MidNumLet", WBP_MIDNUMLET) + PROP ("MidLetter", WBP_MIDLETTER) + PROP ("MidNum", WBP_MIDNUM) + PROP ("Numeric", WBP_NUMERIC) + PROP ("ExtendNumLet", WBP_EXTENDNUMLET) #undef PROP - fprintf (stream, " ??"); - fprintf (stream, "\n"); - } + fprintf (stream, " ??"); + fprintf (stream, "\n"); + } } } @@ -6581,15 +6581,15 @@ output_wbp (FILE *stream) /* Now attr should contain exactly one bit. */ if (attr == 0 || ((attr & (attr - 1)) != 0)) - abort (); + abort (); if (attr != 1 << WBP_OTHER) - { - unsigned int log2_attr; - for (log2_attr = 0; attr > 1; attr >>= 1, log2_attr++); + { + unsigned int log2_attr; + for (log2_attr = 0; attr > 1; attr >>= 1, log2_attr++); - wbp_table_add (&t, i, log2_attr); - } + wbp_table_add (&t, i, log2_attr); + } } wbp_table_finalize (&t); @@ -6606,7 +6606,7 @@ output_wbp (FILE *stream) for (i = 0; i < 5; i++) fprintf (stream, "#define wbrkprop_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "\n"); fprintf (stream, "typedef struct\n"); fprintf (stream, " {\n"); @@ -6624,15 +6624,15 @@ output_wbp (FILE *stream) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -6644,15 +6644,15 @@ output_wbp (FILE *stream) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (unsigned char)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (unsigned char)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -6665,29 +6665,29 @@ output_wbp (FILE *stream) unsigned char value = ((unsigned char *) (t.result + level3_offset))[i]; const char *value_string; switch (value) - { + { #define CASE(x) case x: value_string = #x; break; - CASE(WBP_OTHER); - CASE(WBP_CR); - CASE(WBP_LF); - CASE(WBP_NEWLINE); - CASE(WBP_EXTEND); - CASE(WBP_FORMAT); - CASE(WBP_KATAKANA); - CASE(WBP_ALETTER); - CASE(WBP_MIDNUMLET); - CASE(WBP_MIDLETTER); - CASE(WBP_MIDNUM); - CASE(WBP_NUMERIC); - CASE(WBP_EXTENDNUMLET); + CASE(WBP_OTHER); + CASE(WBP_CR); + CASE(WBP_LF); + CASE(WBP_NEWLINE); + CASE(WBP_EXTEND); + CASE(WBP_FORMAT); + CASE(WBP_KATAKANA); + CASE(WBP_ALETTER); + CASE(WBP_MIDNUMLET); + CASE(WBP_MIDLETTER); + CASE(WBP_MIDNUM); + CASE(WBP_NUMERIC); + CASE(WBP_EXTENDNUMLET); #undef CASE - default: - abort (); - } + default: + abort (); + } if (i > 0 && (i % 4) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " %s%s", value_string, - (i+1 < t.level3_size << t.p ? "," : "")); + (i+1 < t.level3_size << t.p ? "," : "")); } if (t.level3_size << t.p > 4) fprintf (stream, "\n "); @@ -6710,7 +6710,7 @@ output_wbrk_tables (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Line breaking properties of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-uni-tables for Unicode %s. */\n", - version); + version); fprintf (stream, "\n"); /* Put a GPL header on it. The gnulib module is under LGPL (although it @@ -6772,7 +6772,7 @@ enum decompositions). Return the type, or -1 for none. */ static int get_decomposition (unsigned int ch, - unsigned int *lengthp, unsigned int decomposed[MAX_DECOMP_LENGTH]) + unsigned int *lengthp, unsigned int decomposed[MAX_DECOMP_LENGTH]) { const char *decomposition = unicode_attributes[ch].decomposition; @@ -6783,55 +6783,55 @@ get_decomposition (unsigned int ch, char *endptr; if (decomposition[0] == '<') - { - const char *rangle; - size_t typelen; - - rangle = strchr (decomposition + 1, '>'); - if (rangle == NULL) - abort (); - typelen = rangle + 1 - decomposition; + { + const char *rangle; + size_t typelen; + + rangle = strchr (decomposition + 1, '>'); + if (rangle == NULL) + abort (); + typelen = rangle + 1 - decomposition; #define TYPE(t1,t2) \ - if (typelen == (sizeof (t1) - 1) && memcmp (decomposition, t1, typelen) == 0) \ - type = t2; \ - else - TYPE ("", UC_DECOMP_FONT) - TYPE ("", UC_DECOMP_NOBREAK) - TYPE ("", UC_DECOMP_INITIAL) - TYPE ("", UC_DECOMP_MEDIAL) - TYPE ("", UC_DECOMP_FINAL) - TYPE ("", UC_DECOMP_ISOLATED) - TYPE ("", UC_DECOMP_CIRCLE) - TYPE ("", UC_DECOMP_SUPER) - TYPE ("", UC_DECOMP_SUB) - TYPE ("", UC_DECOMP_VERTICAL) - TYPE ("", UC_DECOMP_WIDE) - TYPE ("", UC_DECOMP_NARROW) - TYPE ("", UC_DECOMP_SMALL) - TYPE ("", UC_DECOMP_SQUARE) - TYPE ("", UC_DECOMP_FRACTION) - TYPE ("", UC_DECOMP_COMPAT) - { - fprintf (stderr, "unknown decomposition type %*s\n", (int)typelen, decomposition); - exit (1); - } + if (typelen == (sizeof (t1) - 1) && memcmp (decomposition, t1, typelen) == 0) \ + type = t2; \ + else + TYPE ("", UC_DECOMP_FONT) + TYPE ("", UC_DECOMP_NOBREAK) + TYPE ("", UC_DECOMP_INITIAL) + TYPE ("", UC_DECOMP_MEDIAL) + TYPE ("", UC_DECOMP_FINAL) + TYPE ("", UC_DECOMP_ISOLATED) + TYPE ("", UC_DECOMP_CIRCLE) + TYPE ("", UC_DECOMP_SUPER) + TYPE ("", UC_DECOMP_SUB) + TYPE ("", UC_DECOMP_VERTICAL) + TYPE ("", UC_DECOMP_WIDE) + TYPE ("", UC_DECOMP_NARROW) + TYPE ("", UC_DECOMP_SMALL) + TYPE ("", UC_DECOMP_SQUARE) + TYPE ("", UC_DECOMP_FRACTION) + TYPE ("", UC_DECOMP_COMPAT) + { + fprintf (stderr, "unknown decomposition type %*s\n", (int)typelen, decomposition); + exit (1); + } #undef TYPE - decomposition = rangle + 1; - if (decomposition[0] == ' ') - decomposition++; - } + decomposition = rangle + 1; + if (decomposition[0] == ' ') + decomposition++; + } for (length = 0; length < MAX_DECOMP_LENGTH; length++) - { - decomposed[length] = strtoul (decomposition, &endptr, 16); - if (endptr == decomposition) - break; - decomposition = endptr; - if (decomposition[0] == ' ') - decomposition++; - } + { + decomposed[length] = strtoul (decomposition, &endptr, 16); + if (endptr == decomposition) + break; + decomposition = endptr; + if (decomposition[0] == ' ') + decomposition++; + } if (*decomposition != '\0') - /* MAX_DECOMP_LENGTH is too small. */ - abort (); + /* MAX_DECOMP_LENGTH is too small. */ + abort (); *lengthp = length; return type; @@ -6873,32 +6873,32 @@ output_decomposition (FILE *stream1, FILE *stream2) int type = get_decomposition (ch, &length, decomposed); if (type >= 0) - { - if (!(offset < (1 << 15))) - abort (); - decomp_table_add (&t, ch, ((type == UC_DECOMP_CANONICAL ? 0 : 1) << 15) | offset); - - /* Produce length 3-bytes entries. */ - if (length == 0) - /* We would need a special representation of zero-length entries. */ - abort (); - for (i = 0; i < length; i++) - { - if (offset > 0) - fprintf (stream2, ","); - if ((offset % 4) == 0) - fprintf (stream2, "\n "); - if (!(decomposed[i] < (1 << 18))) - abort (); - fprintf (stream2, " 0x%02X, 0x%02X, 0x%02X", - (((i+1 < length ? (1 << 23) : 0) - | (i == 0 ? (type << 18) : 0) - | decomposed[i]) >> 16) & 0xff, - (decomposed[i] >> 8) & 0xff, - decomposed[i] & 0xff); - offset++; - } - } + { + if (!(offset < (1 << 15))) + abort (); + decomp_table_add (&t, ch, ((type == UC_DECOMP_CANONICAL ? 0 : 1) << 15) | offset); + + /* Produce length 3-bytes entries. */ + if (length == 0) + /* We would need a special representation of zero-length entries. */ + abort (); + for (i = 0; i < length; i++) + { + if (offset > 0) + fprintf (stream2, ","); + if ((offset % 4) == 0) + fprintf (stream2, "\n "); + if (!(decomposed[i] < (1 << 18))) + abort (); + fprintf (stream2, " 0x%02X, 0x%02X, 0x%02X", + (((i+1 < length ? (1 << 23) : 0) + | (i == 0 ? (type << 18) : 0) + | decomposed[i]) >> 16) & 0xff, + (decomposed[i] >> 8) & 0xff, + decomposed[i] & 0xff); + offset++; + } + } } fprintf (stream2, "\n};\n"); @@ -6918,7 +6918,7 @@ output_decomposition (FILE *stream1, FILE *stream2) for (i = 0; i < 5; i++) fprintf (stream1, "#define decomp_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream1, "\n"); fprintf (stream1, "typedef struct\n"); fprintf (stream1, " {\n"); @@ -6937,15 +6937,15 @@ output_decomposition (FILE *stream1, FILE *stream2) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream2, "\n "); + fprintf (stream2, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream2, " %5d", -1); + fprintf (stream2, " %5d", -1); else - fprintf (stream2, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream2, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream2, ","); + fprintf (stream2, ","); } if (t.level1_size > 8) fprintf (stream2, "\n "); @@ -6957,15 +6957,15 @@ output_decomposition (FILE *stream1, FILE *stream2) { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream2, "\n "); + fprintf (stream2, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream2, " %5d", -1); + fprintf (stream2, " %5d", -1); else - fprintf (stream2, " %5zu", - (offset - level3_offset) / sizeof (uint16_t)); + fprintf (stream2, " %5zu", + (offset - level3_offset) / sizeof (uint16_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream2, ","); + fprintf (stream2, ","); } if (t.level2_size << t.q > 8) fprintf (stream2, "\n "); @@ -6977,10 +6977,10 @@ output_decomposition (FILE *stream1, FILE *stream2) { uint16_t value = ((uint16_t *) (t.result + level3_offset))[i]; if (i > 0 && (i % 8) == 0) - fprintf (stream2, "\n "); + fprintf (stream2, "\n "); fprintf (stream2, " %5d", value == (uint16_t)(-1) ? -1 : value); if (i+1 < t.level3_size << t.p) - fprintf (stream2, ","); + fprintf (stream2, ","); } if (t.level3_size << t.p > 8) fprintf (stream2, "\n "); @@ -7002,10 +7002,10 @@ output_decomposition_tables (const char *filename1, const char *filename2, const { streams[i] = fopen (filenames[i], "w"); if (streams[i] == NULL) - { - fprintf (stderr, "cannot open '%s' for writing\n", filenames[i]); - exit (1); - } + { + fprintf (stderr, "cannot open '%s' for writing\n", filenames[i]); + exit (1); + } } for (i = 0; i < 2; i++) @@ -7015,7 +7015,7 @@ output_decomposition_tables (const char *filename1, const char *filename2, const fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Decomposition of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-uni-tables.c for Unicode %s. */\n", - version); + version); fprintf (stream, "\n"); } @@ -7024,10 +7024,10 @@ output_decomposition_tables (const char *filename1, const char *filename2, const for (i = 0; i < 2; i++) { if (ferror (streams[i]) || fclose (streams[i])) - { - fprintf (stderr, "error writing to '%s'\n", filenames[i]); - exit (1); - } + { + fprintf (stderr, "error writing to '%s'\n", filenames[i]); + exit (1); + } } } @@ -7056,18 +7056,18 @@ fill_composition_exclusions (const char *compositionexclusions_filename) unsigned int i; if (fscanf (stream, "%200[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; if (sscanf (buf, "%X", &i) != 1) - { - fprintf (stderr, "parse error in '%s'\n", compositionexclusions_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", compositionexclusions_filename); + exit (1); + } if (!(i < 0x110000)) - abort (); + abort (); unicode_composition_exclusions[i] = 1; } @@ -7099,32 +7099,32 @@ debug_output_composition_tables (const char *filename) int type = get_decomposition (ch, &length, decomposed); if (type == UC_DECOMP_CANONICAL - /* Consider only binary decompositions. - Exclude singleton decompositions. */ - && length == 2) - { - unsigned int code1 = decomposed[0]; - unsigned int code2 = decomposed[1]; - unsigned int combined = ch; - - /* Exclude decompositions where the first part is not a starter, - i.e. is not of canonical combining class 0. */ - if (strcmp (unicode_attributes[code1].combining, "0") == 0 - /* Exclude characters listed in CompositionExclusions.txt. */ - && !unicode_composition_exclusions[combined]) - { - /* The combined character must now also be a starter. - Verify this. */ - if (strcmp (unicode_attributes[combined].combining, "0") != 0) - abort (); - - fprintf (stream, "0x%04X\t0x%04X\t0x%04X\t%s\n", - code1, - code2, - combined, - unicode_attributes[code2].combining); - } - } + /* Consider only binary decompositions. + Exclude singleton decompositions. */ + && length == 2) + { + unsigned int code1 = decomposed[0]; + unsigned int code2 = decomposed[1]; + unsigned int combined = ch; + + /* Exclude decompositions where the first part is not a starter, + i.e. is not of canonical combining class 0. */ + if (strcmp (unicode_attributes[code1].combining, "0") == 0 + /* Exclude characters listed in CompositionExclusions.txt. */ + && !unicode_composition_exclusions[combined]) + { + /* The combined character must now also be a starter. + Verify this. */ + if (strcmp (unicode_attributes[combined].combining, "0") != 0) + abort (); + + fprintf (stream, "0x%04X\t0x%04X\t0x%04X\t%s\n", + code1, + code2, + combined, + unicode_attributes[code2].combining); + } + } } if (ferror (stream) || fclose (stream)) @@ -7150,7 +7150,7 @@ output_composition_tables (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Canonical composition of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-uni-tables for Unicode %s. */\n", - version); + version); fprintf (stream, "\n"); /* Put a GPL header on it. The gnulib module is under LGPL (although it @@ -7210,38 +7210,38 @@ output_composition_tables (const char *filename, const char *version) int type = get_decomposition (ch, &length, decomposed); if (type == UC_DECOMP_CANONICAL - /* Consider only binary decompositions. - Exclude singleton decompositions. */ - && length == 2) - { - unsigned int code1 = decomposed[0]; - unsigned int code2 = decomposed[1]; - unsigned int combined = ch; - - /* Exclude decompositions where the first part is not a starter, - i.e. is not of canonical combining class 0. */ - if (strcmp (unicode_attributes[code1].combining, "0") == 0 - /* Exclude characters listed in CompositionExclusions.txt. */ - && !unicode_composition_exclusions[combined]) - { - /* The combined character must now also be a starter. - Verify this. */ - if (strcmp (unicode_attributes[combined].combining, "0") != 0) - abort (); - - if (!(code1 < 0x10000)) - abort (); - if (!(code2 < 0x10000)) - abort (); - if (!(combined < 0x10000)) - abort (); - - fprintf (stream, "\"\\x%02x\\x%02x\\x%02x\\x%02x\", 0x%04x\n", - (code1 >> 8) & 0xff, code1 & 0xff, - (code2 >> 8) & 0xff, code2 & 0xff, - combined); - } - } + /* Consider only binary decompositions. + Exclude singleton decompositions. */ + && length == 2) + { + unsigned int code1 = decomposed[0]; + unsigned int code2 = decomposed[1]; + unsigned int combined = ch; + + /* Exclude decompositions where the first part is not a starter, + i.e. is not of canonical combining class 0. */ + if (strcmp (unicode_attributes[code1].combining, "0") == 0 + /* Exclude characters listed in CompositionExclusions.txt. */ + && !unicode_composition_exclusions[combined]) + { + /* The combined character must now also be a starter. + Verify this. */ + if (strcmp (unicode_attributes[combined].combining, "0") != 0) + abort (); + + if (!(code1 < 0x10000)) + abort (); + if (!(code2 < 0x10000)) + abort (); + if (!(combined < 0x10000)) + abort (); + + fprintf (stream, "\"\\x%02x\\x%02x\\x%02x\\x%02x\", 0x%04x\n", + (code1 >> 8) & 0xff, code1 & 0xff, + (code2 >> 8) & 0xff, code2 & 0xff, + combined); + } + } } if (ferror (stream) || fclose (stream)) @@ -7257,9 +7257,9 @@ output_composition_tables (const char *filename, const char *version) static void output_simple_mapping_test (const char *filename, - const char *function_name, - unsigned int (*func) (unsigned int), - const char *version) + const char *function_name, + unsigned int (*func) (unsigned int), + const char *version) { FILE *stream; bool need_comma; @@ -7290,7 +7290,7 @@ output_simple_mapping_test (const char *filename, fprintf (stream, " along with this program. If not, see . */\n"); fprintf (stream, "\n"); fprintf (stream, "/* Generated automatically by gen-case.c for Unicode %s. */\n", - version); + version); fprintf (stream, "\n"); fprintf (stream, "#include \"test-mapping-part1.h\"\n"); fprintf (stream, "\n"); @@ -7301,12 +7301,12 @@ output_simple_mapping_test (const char *filename, unsigned int value = func (ch); if (value != ch) - { - if (need_comma) - fprintf (stream, ",\n"); - fprintf (stream, " { 0x%04X, 0x%04X }", ch, value); - need_comma = true; - } + { + if (need_comma) + fprintf (stream, ",\n"); + fprintf (stream, " { 0x%04X, 0x%04X }", ch, value); + need_comma = true; + } } if (need_comma) fprintf (stream, "\n"); @@ -7334,8 +7334,8 @@ output_simple_mapping_test (const char *filename, static void output_simple_mapping (const char *filename, - unsigned int (*func) (unsigned int), - const char *version) + unsigned int (*func) (unsigned int), + const char *version) { FILE *stream; unsigned int ch, i; @@ -7352,7 +7352,7 @@ output_simple_mapping (const char *filename, fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Simple character mapping of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-case.c for Unicode %s. */\n", - version); + version); t.p = 7; t.q = 9; @@ -7380,7 +7380,7 @@ output_simple_mapping (const char *filename, for (i = 0; i < 5; i++) fprintf (stream, "#define mapping_header_%d %d\n", i, - ((uint32_t *) t.result)[i]); + ((uint32_t *) t.result)[i]); fprintf (stream, "static const\n"); fprintf (stream, "struct\n"); fprintf (stream, " {\n"); @@ -7397,15 +7397,15 @@ output_simple_mapping (const char *filename, { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level1_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level2_offset) / sizeof (uint32_t)); + fprintf (stream, " %5zu", + (offset - level2_offset) / sizeof (uint32_t)); if (i+1 < t.level1_size) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level1_size > 8) fprintf (stream, "\n "); @@ -7417,15 +7417,15 @@ output_simple_mapping (const char *filename, { uint32_t offset; if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); offset = ((uint32_t *) (t.result + level2_offset))[i]; if (offset == 0) - fprintf (stream, " %5d", -1); + fprintf (stream, " %5d", -1); else - fprintf (stream, " %5zu", - (offset - level3_offset) / sizeof (int32_t)); + fprintf (stream, " %5zu", + (offset - level3_offset) / sizeof (int32_t)); if (i+1 < t.level2_size << t.q) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level2_size << t.q > 8) fprintf (stream, "\n "); @@ -7436,10 +7436,10 @@ output_simple_mapping (const char *filename, for (i = 0; i < t.level3_size << t.p; i++) { if (i > 0 && (i % 8) == 0) - fprintf (stream, "\n "); + fprintf (stream, "\n "); fprintf (stream, " %5d", ((int32_t *) (t.result + level3_offset))[i]); if (i+1 < t.level3_size << t.p) - fprintf (stream, ","); + fprintf (stream, ","); } if (t.level3_size << t.p > 8) fprintf (stream, "\n "); @@ -7491,10 +7491,10 @@ add_casing_rule (struct special_casing_rule *new_rule) { allocated_casing_rules = 2 * allocated_casing_rules; if (allocated_casing_rules < 16) - allocated_casing_rules = 16; + allocated_casing_rules = 16; casing_rules = - (struct special_casing_rule **) - realloc (casing_rules, allocated_casing_rules * sizeof (struct special_casing_rule *)); + (struct special_casing_rule **) + realloc (casing_rules, allocated_casing_rules * sizeof (struct special_casing_rule *)); } casing_rules[num_casing_rules++] = new_rule; } @@ -7532,179 +7532,179 @@ fill_casing_rules (const char *specialcasing_filename) int context; if (fscanf (stream, "%200[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; /* Scan code. */ scanptr = buf; code = strtoul (scanptr, &endptr, 16); if (endptr == scanptr) - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } scanptr = endptr; if (*scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } scanptr++; /* Scan lower mapping. */ for (i = 0; i < 3; i++) - lower_mapping[i] = 0; + lower_mapping[i] = 0; for (i = 0; i < 3; i++) - { - while (*scanptr == ' ') - scanptr++; - if (*scanptr == ';') - break; - lower_mapping[i] = strtoul (scanptr, &endptr, 16); - if (endptr == scanptr) - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } - scanptr = endptr; - } + { + while (*scanptr == ' ') + scanptr++; + if (*scanptr == ';') + break; + lower_mapping[i] = strtoul (scanptr, &endptr, 16); + if (endptr == scanptr) + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } + scanptr = endptr; + } if (*scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } scanptr++; /* Scan title mapping. */ for (i = 0; i < 3; i++) - title_mapping[i] = 0; + title_mapping[i] = 0; for (i = 0; i < 3; i++) - { - while (*scanptr == ' ') - scanptr++; - if (*scanptr == ';') - break; - title_mapping[i] = strtoul (scanptr, &endptr, 16); - if (endptr == scanptr) - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } - scanptr = endptr; - } + { + while (*scanptr == ' ') + scanptr++; + if (*scanptr == ';') + break; + title_mapping[i] = strtoul (scanptr, &endptr, 16); + if (endptr == scanptr) + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } + scanptr = endptr; + } if (*scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } scanptr++; /* Scan upper mapping. */ for (i = 0; i < 3; i++) - upper_mapping[i] = 0; + upper_mapping[i] = 0; for (i = 0; i < 3; i++) - { - while (*scanptr == ' ') - scanptr++; - if (*scanptr == ';') - break; - upper_mapping[i] = strtoul (scanptr, &endptr, 16); - if (endptr == scanptr) - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } - scanptr = endptr; - } + { + while (*scanptr == ' ') + scanptr++; + if (*scanptr == ';') + break; + upper_mapping[i] = strtoul (scanptr, &endptr, 16); + if (endptr == scanptr) + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } + scanptr = endptr; + } if (*scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } scanptr++; /* Scan language and context. */ language = NULL; context = SCC_ALWAYS; while (*scanptr == ' ') - scanptr++; + scanptr++; if (*scanptr != '\0' && *scanptr != '#') - { - const char *word_begin = scanptr; - const char *word_end; - - while (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';' && *scanptr != ' ') - scanptr++; - word_end = scanptr; - - while (*scanptr == ' ') - scanptr++; - - if (word_end - word_begin == 2) - { - language = (char *) malloc ((word_end - word_begin) + 1); - memcpy (language, word_begin, 2); - language[word_end - word_begin] = '\0'; - word_begin = word_end = NULL; - - if (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';') - { - word_begin = scanptr; - while (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';' && *scanptr != ' ') - scanptr++; - word_end = scanptr; - } - } - - if (word_end > word_begin) - { - bool negate = false; - - if (word_end - word_begin >= 4 && memcmp (word_begin, "Not_", 4) == 0) - { - word_begin += 4; - negate = true; - } - if (word_end - word_begin == 11 && memcmp (word_begin, "Final_Sigma", 11) == 0) - context = SCC_FINAL_SIGMA; - else if (word_end - word_begin == 17 && memcmp (word_begin, "After_Soft_Dotted", 17) == 0) - context = SCC_AFTER_SOFT_DOTTED; - else if (word_end - word_begin == 10 && memcmp (word_begin, "More_Above", 10) == 0) - context = SCC_MORE_ABOVE; - else if (word_end - word_begin == 10 && memcmp (word_begin, "Before_Dot", 10) == 0) - context = SCC_BEFORE_DOT; - else if (word_end - word_begin == 7 && memcmp (word_begin, "After_I", 7) == 0) - context = SCC_AFTER_I; - else - { - fprintf (stderr, "unknown context type in '%s'\n", specialcasing_filename); - exit (1); - } - if (negate) - context = - context; - } - - if (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); - exit (1); - } - } + { + const char *word_begin = scanptr; + const char *word_end; + + while (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';' && *scanptr != ' ') + scanptr++; + word_end = scanptr; + + while (*scanptr == ' ') + scanptr++; + + if (word_end - word_begin == 2) + { + language = (char *) malloc ((word_end - word_begin) + 1); + memcpy (language, word_begin, 2); + language[word_end - word_begin] = '\0'; + word_begin = word_end = NULL; + + if (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';') + { + word_begin = scanptr; + while (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';' && *scanptr != ' ') + scanptr++; + word_end = scanptr; + } + } + + if (word_end > word_begin) + { + bool negate = false; + + if (word_end - word_begin >= 4 && memcmp (word_begin, "Not_", 4) == 0) + { + word_begin += 4; + negate = true; + } + if (word_end - word_begin == 11 && memcmp (word_begin, "Final_Sigma", 11) == 0) + context = SCC_FINAL_SIGMA; + else if (word_end - word_begin == 17 && memcmp (word_begin, "After_Soft_Dotted", 17) == 0) + context = SCC_AFTER_SOFT_DOTTED; + else if (word_end - word_begin == 10 && memcmp (word_begin, "More_Above", 10) == 0) + context = SCC_MORE_ABOVE; + else if (word_end - word_begin == 10 && memcmp (word_begin, "Before_Dot", 10) == 0) + context = SCC_BEFORE_DOT; + else if (word_end - word_begin == 7 && memcmp (word_begin, "After_I", 7) == 0) + context = SCC_AFTER_I; + else + { + fprintf (stderr, "unknown context type in '%s'\n", specialcasing_filename); + exit (1); + } + if (negate) + context = - context; + } + + if (*scanptr != '\0' && *scanptr != '#' && *scanptr != ';') + { + fprintf (stderr, "parse error in '%s'\n", specialcasing_filename); + exit (1); + } + } /* Store the rule. */ { - struct special_casing_rule *new_rule = - (struct special_casing_rule *) malloc (sizeof (struct special_casing_rule)); - new_rule->code = code; - new_rule->language = language; - new_rule->context = context; - memcpy (new_rule->lower_mapping, lower_mapping, sizeof (new_rule->lower_mapping)); - memcpy (new_rule->title_mapping, title_mapping, sizeof (new_rule->title_mapping)); - memcpy (new_rule->upper_mapping, upper_mapping, sizeof (new_rule->upper_mapping)); - - add_casing_rule (new_rule); + struct special_casing_rule *new_rule = + (struct special_casing_rule *) malloc (sizeof (struct special_casing_rule)); + new_rule->code = code; + new_rule->language = language; + new_rule->context = context; + memcpy (new_rule->lower_mapping, lower_mapping, sizeof (new_rule->lower_mapping)); + memcpy (new_rule->title_mapping, title_mapping, sizeof (new_rule->title_mapping)); + memcpy (new_rule->upper_mapping, upper_mapping, sizeof (new_rule->upper_mapping)); + + add_casing_rule (new_rule); } } @@ -7758,115 +7758,115 @@ fill_casefolding_rules (const char *casefolding_filename) unsigned int mapping[3]; if (fscanf (stream, "%200[^\n]\n", buf) < 1) - break; + break; if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; /* Scan code. */ scanptr = buf; code = strtoul (scanptr, &endptr, 16); if (endptr == scanptr) - { - fprintf (stderr, "parse error in '%s'\n", casefolding_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", casefolding_filename); + exit (1); + } scanptr = endptr; if (*scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", casefolding_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", casefolding_filename); + exit (1); + } scanptr++; /* Scan type. */ while (*scanptr == ' ') - scanptr++; + scanptr++; switch (*scanptr) - { - case 'C': case 'F': case 'S': case 'T': - type = *scanptr; - break; - default: - fprintf (stderr, "parse error in '%s'\n", casefolding_filename); - exit (1); - } + { + case 'C': case 'F': case 'S': case 'T': + type = *scanptr; + break; + default: + fprintf (stderr, "parse error in '%s'\n", casefolding_filename); + exit (1); + } scanptr++; if (*scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", casefolding_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", casefolding_filename); + exit (1); + } scanptr++; /* Scan casefold mapping. */ for (i = 0; i < 3; i++) - mapping[i] = 0; + mapping[i] = 0; for (i = 0; i < 3; i++) - { - while (*scanptr == ' ') - scanptr++; - if (*scanptr == ';') - break; - mapping[i] = strtoul (scanptr, &endptr, 16); - if (endptr == scanptr) - { - fprintf (stderr, "parse error in '%s'\n", casefolding_filename); - exit (1); - } - scanptr = endptr; - } + { + while (*scanptr == ' ') + scanptr++; + if (*scanptr == ';') + break; + mapping[i] = strtoul (scanptr, &endptr, 16); + if (endptr == scanptr) + { + fprintf (stderr, "parse error in '%s'\n", casefolding_filename); + exit (1); + } + scanptr = endptr; + } if (*scanptr != ';') - { - fprintf (stderr, "parse error in '%s'\n", casefolding_filename); - exit (1); - } + { + fprintf (stderr, "parse error in '%s'\n", casefolding_filename); + exit (1); + } scanptr++; /* Ignore rules of type 'S'; we use the rules of type 'F' instead. */ if (type != 'S') - { - const char * const *languages; - unsigned int languages_count; - - /* Type 'T' indicates that the rule is applicable to Turkish - languages only. */ - if (type == 'T') - { - static const char * const turkish_languages[] = { "tr", "az" }; - languages = turkish_languages; - languages_count = 2; - } - else - { - static const char * const all_languages[] = { NULL }; - languages = all_languages; - languages_count = 1; - } - - for (i = 0; i < languages_count; i++) - { - /* Store a new rule. */ - struct casefold_rule *new_rule = - (struct casefold_rule *) malloc (sizeof (struct casefold_rule)); - new_rule->code = code; - memcpy (new_rule->mapping, mapping, sizeof (new_rule->mapping)); - new_rule->language = languages[i]; - - if (num_casefolding_rules == allocated_casefolding_rules) - { - allocated_casefolding_rules = 2 * allocated_casefolding_rules; - if (allocated_casefolding_rules < 16) - allocated_casefolding_rules = 16; - casefolding_rules = - (struct casefold_rule **) - realloc (casefolding_rules, - allocated_casefolding_rules * sizeof (struct casefold_rule *)); - } - casefolding_rules[num_casefolding_rules++] = new_rule; - } - } + { + const char * const *languages; + unsigned int languages_count; + + /* Type 'T' indicates that the rule is applicable to Turkish + languages only. */ + if (type == 'T') + { + static const char * const turkish_languages[] = { "tr", "az" }; + languages = turkish_languages; + languages_count = 2; + } + else + { + static const char * const all_languages[] = { NULL }; + languages = all_languages; + languages_count = 1; + } + + for (i = 0; i < languages_count; i++) + { + /* Store a new rule. */ + struct casefold_rule *new_rule = + (struct casefold_rule *) malloc (sizeof (struct casefold_rule)); + new_rule->code = code; + memcpy (new_rule->mapping, mapping, sizeof (new_rule->mapping)); + new_rule->language = languages[i]; + + if (num_casefolding_rules == allocated_casefolding_rules) + { + allocated_casefolding_rules = 2 * allocated_casefolding_rules; + if (allocated_casefolding_rules < 16) + allocated_casefolding_rules = 16; + casefolding_rules = + (struct casefold_rule **) + realloc (casefolding_rules, + allocated_casefolding_rules * sizeof (struct casefold_rule *)); + } + casefolding_rules[num_casefolding_rules++] = new_rule; + } + } } if (ferror (stream) || fclose (stream)) @@ -7902,12 +7902,12 @@ redistribute_casefolding_rules (void) struct casefold_rule *cfrule = casefolding_rules[i]; if (cfrule->language == NULL && cfrule->mapping[1] == 0) - { - ch = cfrule->code; - if (!(ch < 0x110000)) - abort (); - unicode_casefold[ch] = cfrule->mapping[0]; - } + { + ch = cfrule->code; + if (!(ch < 0x110000)) + abort (); + unicode_casefold[ch] = cfrule->mapping[0]; + } } /* Extend the special casing rules by filling in their casefold_mapping[] @@ -7919,7 +7919,7 @@ redistribute_casefolding_rules (void) rule->casefold_mapping[0] = to_casefold (rule->code); for (k = 1; k < 3; k++) - rule->casefold_mapping[k] = 0; + rule->casefold_mapping[k] = 0; } /* Now merge the other casefolding rules into casing_rules. */ @@ -7928,90 +7928,90 @@ redistribute_casefolding_rules (void) struct casefold_rule *cfrule = casefolding_rules[i]; if (!(cfrule->language == NULL && cfrule->mapping[1] == 0)) - { - /* Find a rule that applies to the same code, same language, and it - has context SCC_ALWAYS. At the same time, update all rules that - have the same code and same or more specific language. */ - struct special_casing_rule *found_rule = NULL; - - for (j = 0; j < num_casing_rules; j++) - { - struct special_casing_rule *rule = casing_rules[j]; - - if (rule->code == cfrule->code - && (cfrule->language == NULL - || (rule->language != NULL - && strcmp (rule->language, cfrule->language) == 0))) - { - memcpy (rule->casefold_mapping, cfrule->mapping, - sizeof (rule->casefold_mapping)); - - if ((cfrule->language == NULL - ? rule->language == NULL - : rule->language != NULL - && strcmp (rule->language, cfrule->language) == 0) - && rule->context == SCC_ALWAYS) - { - /* Found it. */ - found_rule = rule; - } - } - } - - if (found_rule == NULL) - { - /* Create a new rule. */ - struct special_casing_rule *new_rule = - (struct special_casing_rule *) malloc (sizeof (struct special_casing_rule)); - - /* Try to find a rule that applies to the same code, no language - restriction, and with context SCC_ALWAYS. */ - for (j = 0; j < num_casing_rules; j++) - { - struct special_casing_rule *rule = casing_rules[j]; - - if (rule->code == cfrule->code - && rule->context == SCC_ALWAYS - && rule->language == NULL) - { - /* Found it. */ - found_rule = rule; - break; - } - } - - new_rule->code = cfrule->code; - new_rule->language = cfrule->language; - new_rule->context = SCC_ALWAYS; - if (found_rule != NULL) - { - memcpy (new_rule->lower_mapping, found_rule->lower_mapping, - sizeof (new_rule->lower_mapping)); - memcpy (new_rule->title_mapping, found_rule->title_mapping, - sizeof (new_rule->title_mapping)); - memcpy (new_rule->upper_mapping, found_rule->upper_mapping, - sizeof (new_rule->upper_mapping)); - } - else - { - unsigned int k; - - new_rule->lower_mapping[0] = to_lower (cfrule->code); - for (k = 1; k < 3; k++) - new_rule->lower_mapping[k] = 0; - new_rule->title_mapping[0] = to_title (cfrule->code); - for (k = 1; k < 3; k++) - new_rule->title_mapping[k] = 0; - new_rule->upper_mapping[0] = to_upper (cfrule->code); - for (k = 1; k < 3; k++) - new_rule->upper_mapping[k] = 0; - } - memcpy (new_rule->casefold_mapping, cfrule->mapping, - sizeof (new_rule->casefold_mapping)); - - add_casing_rule (new_rule); - } - } + { + /* Find a rule that applies to the same code, same language, and it + has context SCC_ALWAYS. At the same time, update all rules that + have the same code and same or more specific language. */ + struct special_casing_rule *found_rule = NULL; + + for (j = 0; j < num_casing_rules; j++) + { + struct special_casing_rule *rule = casing_rules[j]; + + if (rule->code == cfrule->code + && (cfrule->language == NULL + || (rule->language != NULL + && strcmp (rule->language, cfrule->language) == 0))) + { + memcpy (rule->casefold_mapping, cfrule->mapping, + sizeof (rule->casefold_mapping)); + + if ((cfrule->language == NULL + ? rule->language == NULL + : rule->language != NULL + && strcmp (rule->language, cfrule->language) == 0) + && rule->context == SCC_ALWAYS) + { + /* Found it. */ + found_rule = rule; + } + } + } + + if (found_rule == NULL) + { + /* Create a new rule. */ + struct special_casing_rule *new_rule = + (struct special_casing_rule *) malloc (sizeof (struct special_casing_rule)); + + /* Try to find a rule that applies to the same code, no language + restriction, and with context SCC_ALWAYS. */ + for (j = 0; j < num_casing_rules; j++) + { + struct special_casing_rule *rule = casing_rules[j]; + + if (rule->code == cfrule->code + && rule->context == SCC_ALWAYS + && rule->language == NULL) + { + /* Found it. */ + found_rule = rule; + break; + } + } + + new_rule->code = cfrule->code; + new_rule->language = cfrule->language; + new_rule->context = SCC_ALWAYS; + if (found_rule != NULL) + { + memcpy (new_rule->lower_mapping, found_rule->lower_mapping, + sizeof (new_rule->lower_mapping)); + memcpy (new_rule->title_mapping, found_rule->title_mapping, + sizeof (new_rule->title_mapping)); + memcpy (new_rule->upper_mapping, found_rule->upper_mapping, + sizeof (new_rule->upper_mapping)); + } + else + { + unsigned int k; + + new_rule->lower_mapping[0] = to_lower (cfrule->code); + for (k = 1; k < 3; k++) + new_rule->lower_mapping[k] = 0; + new_rule->title_mapping[0] = to_title (cfrule->code); + for (k = 1; k < 3; k++) + new_rule->title_mapping[k] = 0; + new_rule->upper_mapping[0] = to_upper (cfrule->code); + for (k = 1; k < 3; k++) + new_rule->upper_mapping[k] = 0; + } + memcpy (new_rule->casefold_mapping, cfrule->mapping, + sizeof (new_rule->casefold_mapping)); + + add_casing_rule (new_rule); + } + } } } @@ -8030,7 +8030,7 @@ compare_casing_rules (const void *a, const void *b) /* Sort the more specific rules before the more general ones. */ return (- ((a_rule->language != NULL ? 1 : 0) + (a_rule->context != SCC_ALWAYS ? 1 : 0)) - + ((b_rule->language != NULL ? 1 : 0) + (b_rule->context != SCC_ALWAYS ? 1 : 0))); + + ((b_rule->language != NULL ? 1 : 0) + (b_rule->context != SCC_ALWAYS ? 1 : 0))); } static void @@ -8039,7 +8039,7 @@ sort_casing_rules (void) /* Sort the rules 1. by code, 2. by specificity. */ if (num_casing_rules > 1) qsort (casing_rules, num_casing_rules, sizeof (struct special_casing_rule *), - compare_casing_rules); + compare_casing_rules); } /* Output the special casing rules. */ @@ -8060,7 +8060,7 @@ output_casing_rules (const char *filename, const char *version) fprintf (stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n"); fprintf (stream, "/* Special casing rules of Unicode characters. */\n"); fprintf (stream, "/* Generated automatically by gen-uni-tables.c for Unicode %s. */\n", - version); + version); fprintf (stream, "struct special_casing_rule { char code[3]; };\n"); fprintf (stream, "%%struct-type\n"); fprintf (stream, "%%language=ANSI-C\n"); @@ -8080,124 +8080,124 @@ output_casing_rules (const char *filename, const char *version) int context; if (i > 0 && rule->code == casing_rules[i - 1]->code) - minor += 1; + minor += 1; else - minor = 0; + minor = 0; if (!(rule->code < 0x10000)) - { - fprintf (stderr, "special rule #%u: code %u out of range\n", i, rule->code); - exit (1); - } + { + fprintf (stderr, "special rule #%u: code %u out of range\n", i, rule->code); + exit (1); + } fprintf (stream, "\"\\x%02x\\x%02x\\x%02x\", ", - (rule->code >> 8) & 0xff, rule->code & 0xff, minor); + (rule->code >> 8) & 0xff, rule->code & 0xff, minor); fprintf (stream, "%d, ", - i + 1 < num_casing_rules && casing_rules[i + 1]->code == rule->code ? 1 : 0); + i + 1 < num_casing_rules && casing_rules[i + 1]->code == rule->code ? 1 : 0); context = rule->context; if (context < 0) - { - fprintf (stream, "-"); - context = - context; - } + { + fprintf (stream, "-"); + context = - context; + } else - fprintf (stream, " "); + fprintf (stream, " "); switch (context) - { - case SCC_ALWAYS: - fprintf (stream, "SCC_ALWAYS "); - break; - case SCC_FINAL_SIGMA: - fprintf (stream, "SCC_FINAL_SIGMA "); - break; - case SCC_AFTER_SOFT_DOTTED: - fprintf (stream, "SCC_AFTER_SOFT_DOTTED"); - break; - case SCC_MORE_ABOVE: - fprintf (stream, "SCC_MORE_ABOVE "); - break; - case SCC_BEFORE_DOT: - fprintf (stream, "SCC_BEFORE_DOT "); - break; - case SCC_AFTER_I: - fprintf (stream, "SCC_AFTER_I "); - break; - default: - abort (); - } + { + case SCC_ALWAYS: + fprintf (stream, "SCC_ALWAYS "); + break; + case SCC_FINAL_SIGMA: + fprintf (stream, "SCC_FINAL_SIGMA "); + break; + case SCC_AFTER_SOFT_DOTTED: + fprintf (stream, "SCC_AFTER_SOFT_DOTTED"); + break; + case SCC_MORE_ABOVE: + fprintf (stream, "SCC_MORE_ABOVE "); + break; + case SCC_BEFORE_DOT: + fprintf (stream, "SCC_BEFORE_DOT "); + break; + case SCC_AFTER_I: + fprintf (stream, "SCC_AFTER_I "); + break; + default: + abort (); + } fprintf (stream, ", "); if (rule->language != NULL) - { - if (strlen (rule->language) != 2) - abort (); - fprintf (stream, "{ '%c', '%c' }, ", rule->language[0], rule->language[1]); - } + { + if (strlen (rule->language) != 2) + abort (); + fprintf (stream, "{ '%c', '%c' }, ", rule->language[0], rule->language[1]); + } else - fprintf (stream, "{ '\\0', '\\0' }, "); + fprintf (stream, "{ '\\0', '\\0' }, "); fprintf (stream, "{ "); for (j = 0; j < 3; j++) - { - if (j > 0) - fprintf (stream, ", "); - if (!(rule->upper_mapping[j] < 0x10000)) - { - fprintf (stderr, "special rule #%u: upper mapping of code %u out of range\n", i, rule->code); - exit (1); - } - if (rule->upper_mapping[j] != 0) - fprintf (stream, "0x%04X", rule->upper_mapping[j]); - else - fprintf (stream, " 0"); - } + { + if (j > 0) + fprintf (stream, ", "); + if (!(rule->upper_mapping[j] < 0x10000)) + { + fprintf (stderr, "special rule #%u: upper mapping of code %u out of range\n", i, rule->code); + exit (1); + } + if (rule->upper_mapping[j] != 0) + fprintf (stream, "0x%04X", rule->upper_mapping[j]); + else + fprintf (stream, " 0"); + } fprintf (stream, " }, { "); for (j = 0; j < 3; j++) - { - if (j > 0) - fprintf (stream, ", "); - if (!(rule->lower_mapping[j] < 0x10000)) - { - fprintf (stderr, "special rule #%u: lower mapping of code %u out of range\n", i, rule->code); - exit (1); - } - if (rule->lower_mapping[j] != 0) - fprintf (stream, "0x%04X", rule->lower_mapping[j]); - else - fprintf (stream, " 0"); - } + { + if (j > 0) + fprintf (stream, ", "); + if (!(rule->lower_mapping[j] < 0x10000)) + { + fprintf (stderr, "special rule #%u: lower mapping of code %u out of range\n", i, rule->code); + exit (1); + } + if (rule->lower_mapping[j] != 0) + fprintf (stream, "0x%04X", rule->lower_mapping[j]); + else + fprintf (stream, " 0"); + } fprintf (stream, " }, { "); for (j = 0; j < 3; j++) - { - if (j > 0) - fprintf (stream, ", "); - if (!(rule->title_mapping[j] < 0x10000)) - { - fprintf (stderr, "special rule #%u: title mapping of code %u out of range\n", i, rule->code); - exit (1); - } - if (rule->title_mapping[j] != 0) - fprintf (stream, "0x%04X", rule->title_mapping[j]); - else - fprintf (stream, " 0"); - } + { + if (j > 0) + fprintf (stream, ", "); + if (!(rule->title_mapping[j] < 0x10000)) + { + fprintf (stderr, "special rule #%u: title mapping of code %u out of range\n", i, rule->code); + exit (1); + } + if (rule->title_mapping[j] != 0) + fprintf (stream, "0x%04X", rule->title_mapping[j]); + else + fprintf (stream, " 0"); + } fprintf (stream, " }, { "); for (j = 0; j < 3; j++) - { - if (j > 0) - fprintf (stream, ", "); - if (!(rule->casefold_mapping[j] < 0x10000)) - { - fprintf (stderr, "special rule #%u: casefold mapping of code %u out of range\n", i, rule->code); - exit (1); - } - if (rule->casefold_mapping[j] != 0) - fprintf (stream, "0x%04X", rule->casefold_mapping[j]); - else - fprintf (stream, " 0"); - } + { + if (j > 0) + fprintf (stream, ", "); + if (!(rule->casefold_mapping[j] < 0x10000)) + { + fprintf (stderr, "special rule #%u: casefold mapping of code %u out of range\n", i, rule->code); + exit (1); + } + if (rule->casefold_mapping[j] != 0) + fprintf (stream, "0x%04X", rule->casefold_mapping[j]); + else + fprintf (stream, " 0"); + } fprintf (stream, " }\n"); } @@ -8218,8 +8218,8 @@ static bool is_cased (unsigned int ch) { return (is_property_lowercase (ch) - || is_property_uppercase (ch) - || is_category_Lt (ch)); + || is_property_uppercase (ch) + || is_category_Lt (ch)); } /* Quoting the Unicode standard: @@ -8241,13 +8241,13 @@ static bool is_case_ignorable (unsigned int ch) { return (unicode_org_wbp[ch] == WBP_MIDLETTER - || unicode_org_wbp[ch] == WBP_MIDNUMLET - || is_category_Mn (ch) - || is_category_Me (ch) - || is_category_Cf (ch) - || is_category_Lm (ch) - || is_category_Sk (ch)) - && !is_cased (ch); + || unicode_org_wbp[ch] == WBP_MIDNUMLET + || is_category_Mn (ch) + || is_category_Me (ch) + || is_category_Cf (ch) + || is_category_Lm (ch) + || is_category_Sk (ch)) + && !is_cased (ch); } /* ------------------------------------------------------------------------- */ @@ -8287,7 +8287,7 @@ main (int argc, char * argv[]) if (argc != 14) { fprintf (stderr, "Usage: %s UnicodeData.txt PropList.txt DerivedCoreProperties.txt Scripts.txt Blocks.txt PropList-3.0.1.txt EastAsianWidth.txt LineBreak.txt WordBreakProperty.txt CompositionExclusions.txt SpecialCasing.txt CaseFolding.txt version\n", - argv[0]); + argv[0]); exit (1); } diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 6a36bf0fc..ee89fa29c 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -58,12 +58,12 @@ #ifdef WIN32_NATIVE typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, - const struct addrinfo*, - struct addrinfo**); + const struct addrinfo*, + struct addrinfo**); typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo*); typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr*, - socklen_t, char*, DWORD, - char*, DWORD, int); + socklen_t, char*, DWORD, + char*, DWORD, int); static getaddrinfo_func getaddrinfo_ptr = NULL; static freeaddrinfo_func freeaddrinfo_ptr = NULL; @@ -123,9 +123,9 @@ validate_family (int family) socket addresses. */ int getaddrinfo (const char *restrict nodename, - const char *restrict servname, - const struct addrinfo *restrict hints, - struct addrinfo **restrict res) + const char *restrict servname, + const struct addrinfo *restrict hints, + struct addrinfo **restrict res) { struct addrinfo *tmp; int port = 0; @@ -165,7 +165,7 @@ getaddrinfo (const char *restrict nodename, if (!nodename) { if (!(hints->ai_flags & AI_PASSIVE)) - return EAI_NONAME; + return EAI_NONAME; #ifdef HAVE_IPV6 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; @@ -178,24 +178,24 @@ getaddrinfo (const char *restrict nodename, { struct servent *se = NULL; const char *proto = - (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; + (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp"; if (hints == NULL || !(hints->ai_flags & AI_NUMERICSERV)) - /* FIXME: Use getservbyname_r if available. */ - se = getservbyname (servname, proto); + /* FIXME: Use getservbyname_r if available. */ + se = getservbyname (servname, proto); if (!se) - { - char *c; - if (!(*servname >= '0' && *servname <= '9')) - return EAI_NONAME; - port = strtoul (servname, &c, 10); - if (*c || port > 0xffff) - return EAI_NONAME; - port = htons (port); - } + { + char *c; + if (!(*servname >= '0' && *servname <= '9')) + return EAI_NONAME; + port = strtoul (servname, &c, 10); + if (*c || port > 0xffff) + return EAI_NONAME; + port = htons (port); + } else - port = se->s_port; + port = se->s_port; } /* FIXME: Use gethostbyname_r if available. */ @@ -230,23 +230,23 @@ getaddrinfo (const char *restrict nodename, #if HAVE_IPV6 case PF_INET6: { - struct v6_pair *p = storage; - struct sockaddr_in6 *sinp = &p->sockaddr_in6; - tmp = &p->addrinfo; + struct v6_pair *p = storage; + struct sockaddr_in6 *sinp = &p->sockaddr_in6; + tmp = &p->addrinfo; - if (port) - sinp->sin6_port = port; + if (port) + sinp->sin6_port = port; - if (he->h_length != sizeof (sinp->sin6_addr)) - { - free (storage); - return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ - } + if (he->h_length != sizeof (sinp->sin6_addr)) + { + free (storage); + return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ + } - memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr); + memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr); - tmp->ai_addr = (struct sockaddr *) sinp; - tmp->ai_addrlen = sizeof *sinp; + tmp->ai_addr = (struct sockaddr *) sinp; + tmp->ai_addrlen = sizeof *sinp; } break; #endif @@ -254,23 +254,23 @@ getaddrinfo (const char *restrict nodename, #if HAVE_IPV4 case PF_INET: { - struct v4_pair *p = storage; - struct sockaddr_in *sinp = &p->sockaddr_in; - tmp = &p->addrinfo; + struct v4_pair *p = storage; + struct sockaddr_in *sinp = &p->sockaddr_in; + tmp = &p->addrinfo; - if (port) - sinp->sin_port = port; + if (port) + sinp->sin_port = port; - if (he->h_length != sizeof (sinp->sin_addr)) - { - free (storage); - return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ - } + if (he->h_length != sizeof (sinp->sin_addr)) + { + free (storage); + return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */ + } - memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr); + memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr); - tmp->ai_addr = (struct sockaddr *) sinp; - tmp->ai_addrlen = sizeof *sinp; + tmp->ai_addr = (struct sockaddr *) sinp; + tmp->ai_addrlen = sizeof *sinp; } break; #endif @@ -284,16 +284,16 @@ getaddrinfo (const char *restrict nodename, { const char *cn; if (he->h_name) - cn = he->h_name; + cn = he->h_name; else - cn = nodename; + cn = nodename; tmp->ai_canonname = strdup (cn); if (!tmp->ai_canonname) - { - free (storage); - return EAI_MEMORY; - } + { + free (storage); + return EAI_MEMORY; + } } tmp->ai_protocol = (hints) ? hints->ai_protocol : 0; @@ -349,14 +349,14 @@ freeaddrinfo (struct addrinfo *ai) } int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, - char *restrict node, socklen_t nodelen, - char *restrict service, socklen_t servicelen, - int flags) + char *restrict node, socklen_t nodelen, + char *restrict service, socklen_t servicelen, + int flags) { #ifdef WIN32_NATIVE if (use_win32_p ()) return getnameinfo_ptr (sa, salen, node, nodelen, - service, servicelen, flags); + service, servicelen, flags); #endif /* FIXME: Support other flags. */ @@ -373,13 +373,13 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, #if HAVE_IPV4 case AF_INET: if (salen < sizeof (struct sockaddr_in)) - return EAI_FAMILY; + return EAI_FAMILY; break; #endif #if HAVE_IPV6 case AF_INET6: if (salen < sizeof (struct sockaddr_in6)) - return EAI_FAMILY; + return EAI_FAMILY; break; #endif default: @@ -389,28 +389,28 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, if (node && nodelen > 0 && flags & NI_NUMERICHOST) { switch (sa->sa_family) - { + { #if HAVE_IPV4 - case AF_INET: - if (!inet_ntop (AF_INET, - &(((const struct sockaddr_in *) sa)->sin_addr), - node, nodelen)) - return EAI_SYSTEM; - break; + case AF_INET: + if (!inet_ntop (AF_INET, + &(((const struct sockaddr_in *) sa)->sin_addr), + node, nodelen)) + return EAI_SYSTEM; + break; #endif #if HAVE_IPV6 - case AF_INET6: - if (!inet_ntop (AF_INET6, - &(((const struct sockaddr_in6 *) sa)->sin6_addr), - node, nodelen)) - return EAI_SYSTEM; - break; + case AF_INET6: + if (!inet_ntop (AF_INET6, + &(((const struct sockaddr_in6 *) sa)->sin6_addr), + node, nodelen)) + return EAI_SYSTEM; + break; #endif - default: - return EAI_FAMILY; - } + default: + return EAI_FAMILY; + } } if (service && servicelen > 0 && flags & NI_NUMERICSERV) @@ -422,13 +422,13 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, #if HAVE_IPV6 case AF_INET6: #endif - { - unsigned short int port - = ntohs (((const struct sockaddr_in *) sa)->sin_port); - if (servicelen <= snprintf (service, servicelen, "%u", port)) - return EAI_OVERFLOW; - } - break; + { + unsigned short int port + = ntohs (((const struct sockaddr_in *) sa)->sin_port); + if (servicelen <= snprintf (service, servicelen, "%u", port)) + return EAI_OVERFLOW; + } + break; } return 0; diff --git a/lib/getcwd.c b/lib/getcwd.c index 6658ed58c..37968df42 100644 --- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -67,7 +67,7 @@ #endif #ifndef PATH_MAX -# ifdef MAXPATHLEN +# ifdef MAXPATHLEN # define PATH_MAX MAXPATHLEN # else # define PATH_MAX 1024 @@ -157,10 +157,10 @@ __getcwd (char *buf, size_t size) if (size == 0) { if (buf != NULL) - { - __set_errno (EINVAL); - return NULL; - } + { + __set_errno (EINVAL); + return NULL; + } allocated = BIG_FILE_NAME_LENGTH + 1; } @@ -169,7 +169,7 @@ __getcwd (char *buf, size_t size) { dir = malloc (allocated); if (dir == NULL) - return NULL; + return NULL; } else dir = buf; @@ -202,7 +202,7 @@ __getcwd (char *buf, size_t size) #if HAVE_OPENAT_SUPPORT fd = openat (fd, "..", O_RDONLY); if (fd < 0) - goto lose; + goto lose; fd_needs_closing = true; parent_status = fstat (fd, &st); #else @@ -212,13 +212,13 @@ __getcwd (char *buf, size_t size) parent_status = __lstat (dotlist, &st); #endif if (parent_status != 0) - goto lose; + goto lose; if (dirstream && __closedir (dirstream) != 0) - { - dirstream = NULL; - goto lose; - } + { + dirstream = NULL; + goto lose; + } /* Figure out if this directory is a mount point. */ dotdev = st.st_dev; @@ -229,138 +229,138 @@ __getcwd (char *buf, size_t size) #if HAVE_OPENAT_SUPPORT dirstream = fdopendir (fd); if (dirstream == NULL) - goto lose; + goto lose; /* Reset fd. It may have been closed by fdopendir. */ fd = dirfd (dirstream); fd_needs_closing = false; #else dirstream = __opendir (dotlist); if (dirstream == NULL) - goto lose; + goto lose; dotlist[dotlen++] = '/'; #endif for (;;) - { - /* Clear errno to distinguish EOF from error if readdir returns - NULL. */ - __set_errno (0); - d = __readdir (dirstream); - - /* When we've iterated through all directory entries without finding - one with a matching d_ino, rewind the stream and consider each - name again, but this time, using lstat. This is necessary in a - chroot on at least one system (glibc-2.3.6 + linux 2.6.12), where - .., ../.., ../../.., etc. all had the same device number, yet the - d_ino values for entries in / did not match those obtained - via lstat. */ - if (d == NULL && errno == 0 && use_d_ino) - { - use_d_ino = false; - rewinddir (dirstream); - d = __readdir (dirstream); - } - - if (d == NULL) - { - if (errno == 0) - /* EOF on dirstream, which can mean e.g., that the current - directory has been removed. */ - __set_errno (ENOENT); - goto lose; - } - if (d->d_name[0] == '.' && - (d->d_name[1] == '\0' || - (d->d_name[1] == '.' && d->d_name[2] == '\0'))) - continue; - - if (use_d_ino) - { - bool match = (MATCHING_INO (d, thisino) || mount_point); - if (! match) - continue; - } - - { - int entry_status; + { + /* Clear errno to distinguish EOF from error if readdir returns + NULL. */ + __set_errno (0); + d = __readdir (dirstream); + + /* When we've iterated through all directory entries without finding + one with a matching d_ino, rewind the stream and consider each + name again, but this time, using lstat. This is necessary in a + chroot on at least one system (glibc-2.3.6 + linux 2.6.12), where + .., ../.., ../../.., etc. all had the same device number, yet the + d_ino values for entries in / did not match those obtained + via lstat. */ + if (d == NULL && errno == 0 && use_d_ino) + { + use_d_ino = false; + rewinddir (dirstream); + d = __readdir (dirstream); + } + + if (d == NULL) + { + if (errno == 0) + /* EOF on dirstream, which can mean e.g., that the current + directory has been removed. */ + __set_errno (ENOENT); + goto lose; + } + if (d->d_name[0] == '.' && + (d->d_name[1] == '\0' || + (d->d_name[1] == '.' && d->d_name[2] == '\0'))) + continue; + + if (use_d_ino) + { + bool match = (MATCHING_INO (d, thisino) || mount_point); + if (! match) + continue; + } + + { + int entry_status; #if HAVE_OPENAT_SUPPORT - entry_status = fstatat (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW); + entry_status = fstatat (fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW); #else - /* Compute size needed for this file name, or for the file - name ".." in the same directory, whichever is larger. - Room for ".." might be needed the next time through - the outer loop. */ - size_t name_alloc = _D_ALLOC_NAMLEN (d); - size_t filesize = dotlen + MAX (sizeof "..", name_alloc); - - if (filesize < dotlen) - goto memory_exhausted; - - if (dotsize < filesize) - { - /* My, what a deep directory tree you have, Grandma. */ - size_t newsize = MAX (filesize, dotsize * 2); - size_t i; - if (newsize < dotsize) - goto memory_exhausted; - if (dotlist != dots) - free (dotlist); - dotlist = malloc (newsize); - if (dotlist == NULL) - goto lose; - dotsize = newsize; - - i = 0; - do - { - dotlist[i++] = '.'; - dotlist[i++] = '.'; - dotlist[i++] = '/'; - } - while (i < dotlen); - } - - memcpy (dotlist + dotlen, d->d_name, _D_ALLOC_NAMLEN (d)); - entry_status = __lstat (dotlist, &st); + /* Compute size needed for this file name, or for the file + name ".." in the same directory, whichever is larger. + Room for ".." might be needed the next time through + the outer loop. */ + size_t name_alloc = _D_ALLOC_NAMLEN (d); + size_t filesize = dotlen + MAX (sizeof "..", name_alloc); + + if (filesize < dotlen) + goto memory_exhausted; + + if (dotsize < filesize) + { + /* My, what a deep directory tree you have, Grandma. */ + size_t newsize = MAX (filesize, dotsize * 2); + size_t i; + if (newsize < dotsize) + goto memory_exhausted; + if (dotlist != dots) + free (dotlist); + dotlist = malloc (newsize); + if (dotlist == NULL) + goto lose; + dotsize = newsize; + + i = 0; + do + { + dotlist[i++] = '.'; + dotlist[i++] = '.'; + dotlist[i++] = '/'; + } + while (i < dotlen); + } + + memcpy (dotlist + dotlen, d->d_name, _D_ALLOC_NAMLEN (d)); + entry_status = __lstat (dotlist, &st); #endif - /* We don't fail here if we cannot stat() a directory entry. - This can happen when (network) file systems fail. If this - entry is in fact the one we are looking for we will find - out soon as we reach the end of the directory without - having found anything. */ - if (entry_status == 0 && S_ISDIR (st.st_mode) - && st.st_dev == thisdev && st.st_ino == thisino) - break; - } - } + /* We don't fail here if we cannot stat() a directory entry. + This can happen when (network) file systems fail. If this + entry is in fact the one we are looking for we will find + out soon as we reach the end of the directory without + having found anything. */ + if (entry_status == 0 && S_ISDIR (st.st_mode) + && st.st_dev == thisdev && st.st_ino == thisino) + break; + } + } dirroom = dirp - dir; namlen = _D_EXACT_NAMLEN (d); if (dirroom <= namlen) - { - if (size != 0) - { - __set_errno (ERANGE); - goto lose; - } - else - { - char *tmp; - size_t oldsize = allocated; - - allocated += MAX (allocated, namlen); - if (allocated < oldsize - || ! (tmp = realloc (dir, allocated))) - goto memory_exhausted; - - /* Move current contents up to the end of the buffer. - This is guaranteed to be non-overlapping. */ - dirp = memcpy (tmp + allocated - (oldsize - dirroom), - tmp + dirroom, - oldsize - dirroom); - dir = tmp; - } - } + { + if (size != 0) + { + __set_errno (ERANGE); + goto lose; + } + else + { + char *tmp; + size_t oldsize = allocated; + + allocated += MAX (allocated, namlen); + if (allocated < oldsize + || ! (tmp = realloc (dir, allocated))) + goto memory_exhausted; + + /* Move current contents up to the end of the buffer. + This is guaranteed to be non-overlapping. */ + dirp = memcpy (tmp + allocated - (oldsize - dirroom), + tmp + dirroom, + oldsize - dirroom); + dir = tmp; + } + } dirp -= namlen; memcpy (dirp, d->d_name, namlen); *--dirp = '/'; diff --git a/lib/getdate.y b/lib/getdate.y index 94160b266..e61ffdfaf 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -88,9 +88,9 @@ implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift right in the usual way when A < 0, so SHR falls back on division if ordinary A >> B doesn't seem to be the usual signed shift. */ -#define SHR(a, b) \ - (-1 >> 1 == -1 \ - ? (a) >> (b) \ +#define SHR(a, b) \ + (-1 >> 1 == -1 \ + ? (a) >> (b) \ : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) #define EPOCH_YEAR 1970 @@ -218,30 +218,30 @@ digits_to_date_time (parser_control *pc, textint text_int) else { if (4 < text_int.digits) - { - pc->dates_seen++; - pc->day = text_int.value % 100; - pc->month = (text_int.value / 100) % 100; - pc->year.value = text_int.value / 10000; - pc->year.digits = text_int.digits - 4; - } + { + pc->dates_seen++; + pc->day = text_int.value % 100; + pc->month = (text_int.value / 100) % 100; + pc->year.value = text_int.value / 10000; + pc->year.digits = text_int.digits - 4; + } else - { - pc->times_seen++; - if (text_int.digits <= 2) - { - pc->hour = text_int.value; - pc->minutes = 0; - } - else - { - pc->hour = text_int.value / 100; - pc->minutes = text_int.value % 100; - } - pc->seconds.tv_sec = 0; - pc->seconds.tv_nsec = 0; - pc->meridian = MER24; - } + { + pc->times_seen++; + if (text_int.digits <= 2) + { + pc->hour = text_int.value; + pc->minutes = 0; + } + else + { + pc->hour = text_int.value / 100; + pc->minutes = text_int.value % 100; + } + pc->seconds.tv_sec = 0; + pc->seconds.tv_nsec = 0; + pc->meridian = MER24; + } } } @@ -262,7 +262,7 @@ apply_relative_time (parser_control *pc, relative_time rel, int factor) /* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */ static void set_hhmmss (parser_control *pc, long int hour, long int minutes, - time_t sec, long int nsec) + time_t sec, long int nsec) { pc->hour = hour; pc->minutes = minutes; @@ -315,8 +315,8 @@ spec: timespec: '@' seconds { - pc->seconds = $2; - pc->timespec_seen = true; + pc->seconds = $2; + pc->timespec_seen = true; } ; @@ -344,45 +344,45 @@ item: time: tUNUMBER tMERIDIAN { - set_hhmmss (pc, $1.value, 0, 0, 0); - pc->meridian = $2; + set_hhmmss (pc, $1.value, 0, 0, 0); + pc->meridian = $2; } | tUNUMBER ':' tUNUMBER o_merid { - set_hhmmss (pc, $1.value, $3.value, 0, 0); - pc->meridian = $4; + set_hhmmss (pc, $1.value, $3.value, 0, 0); + pc->meridian = $4; } | tUNUMBER ':' tUNUMBER tSNUMBER o_colon_minutes { - set_hhmmss (pc, $1.value, $3.value, 0, 0); - pc->meridian = MER24; - pc->zones_seen++; - pc->time_zone = time_zone_hhmm (pc, $4, $5); + set_hhmmss (pc, $1.value, $3.value, 0, 0); + pc->meridian = MER24; + pc->zones_seen++; + pc->time_zone = time_zone_hhmm (pc, $4, $5); } | tUNUMBER ':' tUNUMBER ':' unsigned_seconds o_merid { - set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); - pc->meridian = $6; + set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); + pc->meridian = $6; } | tUNUMBER ':' tUNUMBER ':' unsigned_seconds tSNUMBER o_colon_minutes { - set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); - pc->meridian = MER24; - pc->zones_seen++; - pc->time_zone = time_zone_hhmm (pc, $6, $7); + set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); + pc->meridian = MER24; + pc->zones_seen++; + pc->time_zone = time_zone_hhmm (pc, $6, $7); } ; local_zone: tLOCAL_ZONE { - pc->local_isdst = $1; - pc->dsts_seen += (0 < $1); + pc->local_isdst = $1; + pc->dsts_seen += (0 < $1); } | tLOCAL_ZONE tDST { - pc->local_isdst = 1; - pc->dsts_seen += (0 < $1) + 1; + pc->local_isdst = 1; + pc->dsts_seen += (0 < $1) + 1; } ; @@ -391,7 +391,7 @@ zone: { pc->time_zone = $1; } | tZONE relunit_snumber { pc->time_zone = $1; - apply_relative_time (pc, $2, 1); } + apply_relative_time (pc, $2, 1); } | tZONE tSNUMBER o_colon_minutes { pc->time_zone = $1 + time_zone_hhmm (pc, $2, $3); } | tDAYZONE @@ -403,96 +403,96 @@ zone: day: tDAY { - pc->day_ordinal = 0; - pc->day_number = $1; + pc->day_ordinal = 0; + pc->day_number = $1; } | tDAY ',' { - pc->day_ordinal = 0; - pc->day_number = $1; + pc->day_ordinal = 0; + pc->day_number = $1; } | tORDINAL tDAY { - pc->day_ordinal = $1; - pc->day_number = $2; + pc->day_ordinal = $1; + pc->day_number = $2; } | tUNUMBER tDAY { - pc->day_ordinal = $1.value; - pc->day_number = $2; + pc->day_ordinal = $1.value; + pc->day_number = $2; } ; date: tUNUMBER '/' tUNUMBER { - pc->month = $1.value; - pc->day = $3.value; + pc->month = $1.value; + pc->day = $3.value; } | tUNUMBER '/' tUNUMBER '/' tUNUMBER { - /* Interpret as YYYY/MM/DD if the first value has 4 or more digits, - otherwise as MM/DD/YY. - The goal in recognizing YYYY/MM/DD is solely to support legacy - machine-generated dates like those in an RCS log listing. If - you want portability, use the ISO 8601 format. */ - if (4 <= $1.digits) - { - pc->year = $1; - pc->month = $3.value; - pc->day = $5.value; - } - else - { - pc->month = $1.value; - pc->day = $3.value; - pc->year = $5; - } + /* Interpret as YYYY/MM/DD if the first value has 4 or more digits, + otherwise as MM/DD/YY. + The goal in recognizing YYYY/MM/DD is solely to support legacy + machine-generated dates like those in an RCS log listing. If + you want portability, use the ISO 8601 format. */ + if (4 <= $1.digits) + { + pc->year = $1; + pc->month = $3.value; + pc->day = $5.value; + } + else + { + pc->month = $1.value; + pc->day = $3.value; + pc->year = $5; + } } | tUNUMBER tSNUMBER tSNUMBER { - /* ISO 8601 format. YYYY-MM-DD. */ - pc->year = $1; - pc->month = -$2.value; - pc->day = -$3.value; + /* ISO 8601 format. YYYY-MM-DD. */ + pc->year = $1; + pc->month = -$2.value; + pc->day = -$3.value; } | tUNUMBER tMONTH tSNUMBER { - /* e.g. 17-JUN-1992. */ - pc->day = $1.value; - pc->month = $2; - pc->year.value = -$3.value; - pc->year.digits = $3.digits; + /* e.g. 17-JUN-1992. */ + pc->day = $1.value; + pc->month = $2; + pc->year.value = -$3.value; + pc->year.digits = $3.digits; } | tMONTH tSNUMBER tSNUMBER { - /* e.g. JUN-17-1992. */ - pc->month = $1; - pc->day = -$2.value; - pc->year.value = -$3.value; - pc->year.digits = $3.digits; + /* e.g. JUN-17-1992. */ + pc->month = $1; + pc->day = -$2.value; + pc->year.value = -$3.value; + pc->year.digits = $3.digits; } | tMONTH tUNUMBER { - pc->month = $1; - pc->day = $2.value; + pc->month = $1; + pc->day = $2.value; } | tMONTH tUNUMBER ',' tUNUMBER { - pc->month = $1; - pc->day = $2.value; - pc->year = $4; + pc->month = $1; + pc->day = $2.value; + pc->year = $4; } | tUNUMBER tMONTH { - pc->day = $1.value; - pc->month = $2; + pc->day = $1.value; + pc->month = $2; } | tUNUMBER tMONTH tUNUMBER { - pc->day = $1.value; - pc->month = $2; - pc->year = $3; + pc->day = $1.value; + pc->month = $2; + pc->year = $3; } ; @@ -591,10 +591,10 @@ number: hybrid: tUNUMBER relunit_snumber { - /* Hybrid all-digit and relative offset, so that we accept e.g., - "YYYYMMDD +N days" as well as "YYYYMMDD N days". */ - digits_to_date_time (pc, $1); - apply_relative_time (pc, $2, 1); + /* Hybrid all-digit and relative offset, so that we accept e.g., + "YYYYMMDD +N days" as well as "YYYYMMDD N days". */ + digits_to_date_time (pc, $1); + apply_relative_time (pc, $2, 1); } ; @@ -630,71 +630,71 @@ static table const dst_table[] = static table const month_and_day_table[] = { - { "JANUARY", tMONTH, 1 }, - { "FEBRUARY", tMONTH, 2 }, - { "MARCH", tMONTH, 3 }, - { "APRIL", tMONTH, 4 }, - { "MAY", tMONTH, 5 }, - { "JUNE", tMONTH, 6 }, - { "JULY", tMONTH, 7 }, - { "AUGUST", tMONTH, 8 }, - { "SEPTEMBER",tMONTH, 9 }, - { "SEPT", tMONTH, 9 }, - { "OCTOBER", tMONTH, 10 }, - { "NOVEMBER", tMONTH, 11 }, - { "DECEMBER", tMONTH, 12 }, - { "SUNDAY", tDAY, 0 }, - { "MONDAY", tDAY, 1 }, - { "TUESDAY", tDAY, 2 }, - { "TUES", tDAY, 2 }, - { "WEDNESDAY",tDAY, 3 }, - { "WEDNES", tDAY, 3 }, - { "THURSDAY", tDAY, 4 }, - { "THUR", tDAY, 4 }, - { "THURS", tDAY, 4 }, - { "FRIDAY", tDAY, 5 }, - { "SATURDAY", tDAY, 6 }, + { "JANUARY", tMONTH, 1 }, + { "FEBRUARY", tMONTH, 2 }, + { "MARCH", tMONTH, 3 }, + { "APRIL", tMONTH, 4 }, + { "MAY", tMONTH, 5 }, + { "JUNE", tMONTH, 6 }, + { "JULY", tMONTH, 7 }, + { "AUGUST", tMONTH, 8 }, + { "SEPTEMBER",tMONTH, 9 }, + { "SEPT", tMONTH, 9 }, + { "OCTOBER", tMONTH, 10 }, + { "NOVEMBER", tMONTH, 11 }, + { "DECEMBER", tMONTH, 12 }, + { "SUNDAY", tDAY, 0 }, + { "MONDAY", tDAY, 1 }, + { "TUESDAY", tDAY, 2 }, + { "TUES", tDAY, 2 }, + { "WEDNESDAY",tDAY, 3 }, + { "WEDNES", tDAY, 3 }, + { "THURSDAY", tDAY, 4 }, + { "THUR", tDAY, 4 }, + { "THURS", tDAY, 4 }, + { "FRIDAY", tDAY, 5 }, + { "SATURDAY", tDAY, 6 }, { NULL, 0, 0 } }; static table const time_units_table[] = { - { "YEAR", tYEAR_UNIT, 1 }, - { "MONTH", tMONTH_UNIT, 1 }, - { "FORTNIGHT",tDAY_UNIT, 14 }, - { "WEEK", tDAY_UNIT, 7 }, - { "DAY", tDAY_UNIT, 1 }, - { "HOUR", tHOUR_UNIT, 1 }, - { "MINUTE", tMINUTE_UNIT, 1 }, - { "MIN", tMINUTE_UNIT, 1 }, - { "SECOND", tSEC_UNIT, 1 }, - { "SEC", tSEC_UNIT, 1 }, + { "YEAR", tYEAR_UNIT, 1 }, + { "MONTH", tMONTH_UNIT, 1 }, + { "FORTNIGHT",tDAY_UNIT, 14 }, + { "WEEK", tDAY_UNIT, 7 }, + { "DAY", tDAY_UNIT, 1 }, + { "HOUR", tHOUR_UNIT, 1 }, + { "MINUTE", tMINUTE_UNIT, 1 }, + { "MIN", tMINUTE_UNIT, 1 }, + { "SECOND", tSEC_UNIT, 1 }, + { "SEC", tSEC_UNIT, 1 }, { NULL, 0, 0 } }; /* Assorted relative-time words. */ static table const relative_time_table[] = { - { "TOMORROW", tDAY_SHIFT, 1 }, - { "YESTERDAY",tDAY_SHIFT, -1 }, - { "TODAY", tDAY_SHIFT, 0 }, - { "NOW", tDAY_SHIFT, 0 }, - { "LAST", tORDINAL, -1 }, - { "THIS", tORDINAL, 0 }, - { "NEXT", tORDINAL, 1 }, - { "FIRST", tORDINAL, 1 }, -/*{ "SECOND", tORDINAL, 2 }, */ - { "THIRD", tORDINAL, 3 }, - { "FOURTH", tORDINAL, 4 }, - { "FIFTH", tORDINAL, 5 }, - { "SIXTH", tORDINAL, 6 }, - { "SEVENTH", tORDINAL, 7 }, - { "EIGHTH", tORDINAL, 8 }, - { "NINTH", tORDINAL, 9 }, - { "TENTH", tORDINAL, 10 }, - { "ELEVENTH", tORDINAL, 11 }, - { "TWELFTH", tORDINAL, 12 }, - { "AGO", tAGO, 1 }, + { "TOMORROW", tDAY_SHIFT, 1 }, + { "YESTERDAY",tDAY_SHIFT, -1 }, + { "TODAY", tDAY_SHIFT, 0 }, + { "NOW", tDAY_SHIFT, 0 }, + { "LAST", tORDINAL, -1 }, + { "THIS", tORDINAL, 0 }, + { "NEXT", tORDINAL, 1 }, + { "FIRST", tORDINAL, 1 }, +/*{ "SECOND", tORDINAL, 2 }, */ + { "THIRD", tORDINAL, 3 }, + { "FOURTH", tORDINAL, 4 }, + { "FIFTH", tORDINAL, 5 }, + { "SIXTH", tORDINAL, 6 }, + { "SEVENTH", tORDINAL, 7 }, + { "EIGHTH", tORDINAL, 8 }, + { "NINTH", tORDINAL, 9 }, + { "TENTH", tORDINAL, 10 }, + { "ELEVENTH", tORDINAL, 11 }, + { "TWELFTH", tORDINAL, 12 }, + { "AGO", tAGO, 1 }, { NULL, 0, 0 } }; @@ -703,9 +703,9 @@ static table const relative_time_table[] = stamps in London during summer. */ static table const universal_time_zone_table[] = { - { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */ - { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */ - { "UTC", tZONE, HOUR ( 0) }, + { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */ + { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */ + { "UTC", tZONE, HOUR ( 0) }, { NULL, 0, 0 } }; @@ -716,84 +716,84 @@ static table const universal_time_zone_table[] = abbreviations; use numeric abbreviations like `-0500' instead. */ static table const time_zone_table[] = { - { "WET", tZONE, HOUR ( 0) }, /* Western European */ - { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */ - { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */ - { "ART", tZONE, -HOUR ( 3) }, /* Argentina */ - { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */ - { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */ - { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */ - { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */ - { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */ - { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */ - { "CLT", tZONE, -HOUR ( 4) }, /* Chile */ - { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */ - { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */ - { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */ - { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */ - { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */ - { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */ - { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */ - { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */ - { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */ - { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */ - { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */ - { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */ - { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */ - { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */ - { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */ - { "WAT", tZONE, HOUR ( 1) }, /* West Africa */ - { "CET", tZONE, HOUR ( 1) }, /* Central European */ - { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */ - { "MET", tZONE, HOUR ( 1) }, /* Middle European */ - { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */ - { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */ - { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */ - { "EET", tZONE, HOUR ( 2) }, /* Eastern European */ - { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */ - { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */ - { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */ - { "EAT", tZONE, HOUR ( 3) }, /* East Africa */ - { "MSK", tZONE, HOUR ( 3) }, /* Moscow */ - { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */ - { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */ - { "SGT", tZONE, HOUR ( 8) }, /* Singapore */ - { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */ - { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */ - { "GST", tZONE, HOUR (10) }, /* Guam Standard */ - { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */ - { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */ + { "WET", tZONE, HOUR ( 0) }, /* Western European */ + { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */ + { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */ + { "ART", tZONE, -HOUR ( 3) }, /* Argentina */ + { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */ + { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */ + { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */ + { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */ + { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */ + { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */ + { "CLT", tZONE, -HOUR ( 4) }, /* Chile */ + { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */ + { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */ + { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */ + { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */ + { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */ + { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */ + { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */ + { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */ + { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */ + { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */ + { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */ + { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */ + { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */ + { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */ + { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */ + { "WAT", tZONE, HOUR ( 1) }, /* West Africa */ + { "CET", tZONE, HOUR ( 1) }, /* Central European */ + { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */ + { "MET", tZONE, HOUR ( 1) }, /* Middle European */ + { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */ + { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */ + { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */ + { "EET", tZONE, HOUR ( 2) }, /* Eastern European */ + { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */ + { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */ + { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */ + { "EAT", tZONE, HOUR ( 3) }, /* East Africa */ + { "MSK", tZONE, HOUR ( 3) }, /* Moscow */ + { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */ + { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */ + { "SGT", tZONE, HOUR ( 8) }, /* Singapore */ + { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */ + { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */ + { "GST", tZONE, HOUR (10) }, /* Guam Standard */ + { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */ + { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */ { NULL, 0, 0 } }; /* Military time zone table. */ static table const military_table[] = { - { "A", tZONE, -HOUR ( 1) }, - { "B", tZONE, -HOUR ( 2) }, - { "C", tZONE, -HOUR ( 3) }, - { "D", tZONE, -HOUR ( 4) }, - { "E", tZONE, -HOUR ( 5) }, - { "F", tZONE, -HOUR ( 6) }, - { "G", tZONE, -HOUR ( 7) }, - { "H", tZONE, -HOUR ( 8) }, - { "I", tZONE, -HOUR ( 9) }, - { "K", tZONE, -HOUR (10) }, - { "L", tZONE, -HOUR (11) }, - { "M", tZONE, -HOUR (12) }, - { "N", tZONE, HOUR ( 1) }, - { "O", tZONE, HOUR ( 2) }, - { "P", tZONE, HOUR ( 3) }, - { "Q", tZONE, HOUR ( 4) }, - { "R", tZONE, HOUR ( 5) }, - { "S", tZONE, HOUR ( 6) }, - { "T", tZONE, HOUR ( 7) }, - { "U", tZONE, HOUR ( 8) }, - { "V", tZONE, HOUR ( 9) }, - { "W", tZONE, HOUR (10) }, - { "X", tZONE, HOUR (11) }, - { "Y", tZONE, HOUR (12) }, - { "Z", tZONE, HOUR ( 0) }, + { "A", tZONE, -HOUR ( 1) }, + { "B", tZONE, -HOUR ( 2) }, + { "C", tZONE, -HOUR ( 3) }, + { "D", tZONE, -HOUR ( 4) }, + { "E", tZONE, -HOUR ( 5) }, + { "F", tZONE, -HOUR ( 6) }, + { "G", tZONE, -HOUR ( 7) }, + { "H", tZONE, -HOUR ( 8) }, + { "I", tZONE, -HOUR ( 9) }, + { "K", tZONE, -HOUR (10) }, + { "L", tZONE, -HOUR (11) }, + { "M", tZONE, -HOUR (12) }, + { "N", tZONE, HOUR ( 1) }, + { "O", tZONE, HOUR ( 2) }, + { "P", tZONE, HOUR ( 3) }, + { "Q", tZONE, HOUR ( 4) }, + { "R", tZONE, HOUR ( 5) }, + { "S", tZONE, HOUR ( 6) }, + { "T", tZONE, HOUR ( 7) }, + { "U", tZONE, HOUR ( 8) }, + { "V", tZONE, HOUR ( 9) }, + { "W", tZONE, HOUR (10) }, + { "X", tZONE, HOUR (11) }, + { "Y", tZONE, HOUR (12) }, + { "Z", tZONE, HOUR ( 0) }, { NULL, 0, 0 } }; @@ -903,10 +903,10 @@ tm_diff (struct tm const *a, struct tm const *b) long int ayear = a->tm_year; long int years = ayear - b->tm_year; long int days = (365 * years + intervening_leap_days - + (a->tm_yday - b->tm_yday)); + + (a->tm_yday - b->tm_yday)); return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) - + (a->tm_min - b->tm_min)) - + (a->tm_sec - b->tm_sec)); + + (a->tm_min - b->tm_min)) + + (a->tm_sec - b->tm_sec)); } #endif /* ! HAVE_TM_GMTOFF */ @@ -954,9 +954,9 @@ lookup_word (parser_control const *pc, char *word) { word[wordlen - 1] = '\0'; for (tp = time_units_table; tp->name; tp++) - if (strcmp (word, tp->name) == 0) - return tp; - word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */ + if (strcmp (word, tp->name) == 0) + return tp; + word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */ } for (tp = relative_time_table; tp->name; tp++) @@ -967,7 +967,7 @@ lookup_word (parser_control const *pc, char *word) if (wordlen == 1) for (tp = military_table; tp->name; tp++) if (word[0] == tp->name[0]) - return tp; + return tp; /* Drop out any periods and try the time zone table again. */ for (period_found = false, p = q = word; (*p = *q); q++) @@ -990,155 +990,155 @@ yylex (YYSTYPE *lvalp, parser_control *pc) for (;;) { while (c = *pc->input, c_isspace (c)) - pc->input++; + pc->input++; if (ISDIGIT (c) || c == '-' || c == '+') - { - char const *p; - int sign; - unsigned long int value; - if (c == '-' || c == '+') - { - sign = c == '-' ? -1 : 1; - while (c = *++pc->input, c_isspace (c)) - continue; - if (! ISDIGIT (c)) - /* skip the '-' sign */ - continue; - } - else - sign = 0; - p = pc->input; - for (value = 0; ; value *= 10) - { - unsigned long int value1 = value + (c - '0'); - if (value1 < value) - return '?'; - value = value1; - c = *++p; - if (! ISDIGIT (c)) - break; - if (ULONG_MAX / 10 < value) - return '?'; - } - if ((c == '.' || c == ',') && ISDIGIT (p[1])) - { - time_t s; - int ns; - int digits; - unsigned long int value1; - - /* Check for overflow when converting value to time_t. */ - if (sign < 0) - { - s = - value; - if (0 < s) - return '?'; - value1 = -s; - } - else - { - s = value; - if (s < 0) - return '?'; - value1 = s; - } - if (value != value1) - return '?'; - - /* Accumulate fraction, to ns precision. */ - p++; - ns = *p++ - '0'; - for (digits = 2; digits <= LOG10_BILLION; digits++) - { - ns *= 10; - if (ISDIGIT (*p)) - ns += *p++ - '0'; - } - - /* Skip excess digits, truncating toward -Infinity. */ - if (sign < 0) - for (; ISDIGIT (*p); p++) - if (*p != '0') - { - ns++; - break; - } - while (ISDIGIT (*p)) - p++; - - /* Adjust to the timespec convention, which is that - tv_nsec is always a positive offset even if tv_sec is - negative. */ - if (sign < 0 && ns) - { - s--; - if (! (s < 0)) - return '?'; - ns = BILLION - ns; - } - - lvalp->timespec.tv_sec = s; - lvalp->timespec.tv_nsec = ns; - pc->input = p; - return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER; - } - else - { - lvalp->textintval.negative = sign < 0; - if (sign < 0) - { - lvalp->textintval.value = - value; - if (0 < lvalp->textintval.value) - return '?'; - } - else - { - lvalp->textintval.value = value; - if (lvalp->textintval.value < 0) - return '?'; - } - lvalp->textintval.digits = p - pc->input; - pc->input = p; - return sign ? tSNUMBER : tUNUMBER; - } - } + { + char const *p; + int sign; + unsigned long int value; + if (c == '-' || c == '+') + { + sign = c == '-' ? -1 : 1; + while (c = *++pc->input, c_isspace (c)) + continue; + if (! ISDIGIT (c)) + /* skip the '-' sign */ + continue; + } + else + sign = 0; + p = pc->input; + for (value = 0; ; value *= 10) + { + unsigned long int value1 = value + (c - '0'); + if (value1 < value) + return '?'; + value = value1; + c = *++p; + if (! ISDIGIT (c)) + break; + if (ULONG_MAX / 10 < value) + return '?'; + } + if ((c == '.' || c == ',') && ISDIGIT (p[1])) + { + time_t s; + int ns; + int digits; + unsigned long int value1; + + /* Check for overflow when converting value to time_t. */ + if (sign < 0) + { + s = - value; + if (0 < s) + return '?'; + value1 = -s; + } + else + { + s = value; + if (s < 0) + return '?'; + value1 = s; + } + if (value != value1) + return '?'; + + /* Accumulate fraction, to ns precision. */ + p++; + ns = *p++ - '0'; + for (digits = 2; digits <= LOG10_BILLION; digits++) + { + ns *= 10; + if (ISDIGIT (*p)) + ns += *p++ - '0'; + } + + /* Skip excess digits, truncating toward -Infinity. */ + if (sign < 0) + for (; ISDIGIT (*p); p++) + if (*p != '0') + { + ns++; + break; + } + while (ISDIGIT (*p)) + p++; + + /* Adjust to the timespec convention, which is that + tv_nsec is always a positive offset even if tv_sec is + negative. */ + if (sign < 0 && ns) + { + s--; + if (! (s < 0)) + return '?'; + ns = BILLION - ns; + } + + lvalp->timespec.tv_sec = s; + lvalp->timespec.tv_nsec = ns; + pc->input = p; + return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER; + } + else + { + lvalp->textintval.negative = sign < 0; + if (sign < 0) + { + lvalp->textintval.value = - value; + if (0 < lvalp->textintval.value) + return '?'; + } + else + { + lvalp->textintval.value = value; + if (lvalp->textintval.value < 0) + return '?'; + } + lvalp->textintval.digits = p - pc->input; + pc->input = p; + return sign ? tSNUMBER : tUNUMBER; + } + } if (c_isalpha (c)) - { - char buff[20]; - char *p = buff; - table const *tp; - - do - { - if (p < buff + sizeof buff - 1) - *p++ = c; - c = *++pc->input; - } - while (c_isalpha (c) || c == '.'); - - *p = '\0'; - tp = lookup_word (pc, buff); - if (! tp) - return '?'; - lvalp->intval = tp->value; - return tp->type; - } + { + char buff[20]; + char *p = buff; + table const *tp; + + do + { + if (p < buff + sizeof buff - 1) + *p++ = c; + c = *++pc->input; + } + while (c_isalpha (c) || c == '.'); + + *p = '\0'; + tp = lookup_word (pc, buff); + if (! tp) + return '?'; + lvalp->intval = tp->value; + return tp->type; + } if (c != '(') - return *pc->input++; + return *pc->input++; count = 0; do - { - c = *pc->input++; - if (c == '\0') - return c; - if (c == '(') - count++; - else if (c == ')') - count--; - } + { + c = *pc->input++; + if (c == '\0') + return c; + if (c == '(') + count++; + else if (c == ')') + count--; + } while (count != 0); } } @@ -1146,7 +1146,7 @@ yylex (YYSTYPE *lvalp, parser_control *pc) /* Do nothing if the parser reports an error. */ static int yyerror (parser_control const *pc _UNUSED_PARAMETER_, - char const *s _UNUSED_PARAMETER_) + char const *s _UNUSED_PARAMETER_) { return 0; } @@ -1161,19 +1161,19 @@ mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t) if (t == (time_t) -1) { /* Guard against falsely reporting an error when parsing a time - stamp that happens to equal (time_t) -1, on a host that - supports such a time stamp. */ + stamp that happens to equal (time_t) -1, on a host that + supports such a time stamp. */ tm1 = localtime (&t); if (!tm1) - return false; + return false; } return ! ((tm0->tm_sec ^ tm1->tm_sec) - | (tm0->tm_min ^ tm1->tm_min) - | (tm0->tm_hour ^ tm1->tm_hour) - | (tm0->tm_mday ^ tm1->tm_mday) - | (tm0->tm_mon ^ tm1->tm_mon) - | (tm0->tm_year ^ tm1->tm_year)); + | (tm0->tm_min ^ tm1->tm_min) + | (tm0->tm_hour ^ tm1->tm_hour) + | (tm0->tm_mday ^ tm1->tm_mday) + | (tm0->tm_mon ^ tm1->tm_mon) + | (tm0->tm_year ^ tm1->tm_year)); } /* A reasonable upper bound for the size of ordinary TZ strings. @@ -1190,8 +1190,8 @@ get_tz (char tzbuf[TZBUFSIZE]) { size_t tzsize = strlen (tz) + 1; tz = (tzsize <= TZBUFSIZE - ? memcpy (tzbuf, tz, tzsize) - : xmemdup (tz, tzsize)); + ? memcpy (tzbuf, tz, tzsize) + : xmemdup (tz, tzsize)); } return tz; } @@ -1239,32 +1239,32 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) char const *s; for (s = tzbase; *s; s++, tzsize++) - if (*s == '\\') - { - s++; - if (! (*s == '\\' || *s == '"')) - break; - } - else if (*s == '"') - { - char *z; - char *tz1; - char tz1buf[TZBUFSIZE]; - bool large_tz = TZBUFSIZE < tzsize; - bool setenv_ok; - tz0 = get_tz (tz0buf); - z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf; - for (s = tzbase; *s != '"'; s++) - *z++ = *(s += *s == '\\'); - *z = '\0'; - setenv_ok = setenv ("TZ", tz1, 1) == 0; - if (large_tz) - free (tz1); - if (!setenv_ok) - goto fail; - tz_was_altered = true; - p = s + 1; - } + if (*s == '\\') + { + s++; + if (! (*s == '\\' || *s == '"')) + break; + } + else if (*s == '"') + { + char *z; + char *tz1; + char tz1buf[TZBUFSIZE]; + bool large_tz = TZBUFSIZE < tzsize; + bool setenv_ok; + tz0 = get_tz (tz0buf); + z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf; + for (s = tzbase; *s != '"'; s++) + *z++ = *(s += *s == '\\'); + *z = '\0'; + setenv_ok = setenv ("TZ", tz1, 1) == 0; + if (large_tz) + free (tz1); + if (!setenv_ok) + goto fail; + tz_was_altered = true; + p = s + 1; + } } /* As documented, be careful to treat the empty string just like @@ -1308,19 +1308,19 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) int quarter; for (quarter = 1; quarter <= 3; quarter++) { - time_t probe = Start + quarter * (90 * 24 * 60 * 60); - struct tm const *probe_tm = localtime (&probe); - if (probe_tm && probe_tm->tm_zone - && probe_tm->tm_isdst != pc.local_time_zone_table[0].value) - { - { - pc.local_time_zone_table[1].name = probe_tm->tm_zone; - pc.local_time_zone_table[1].type = tLOCAL_ZONE; - pc.local_time_zone_table[1].value = probe_tm->tm_isdst; - pc.local_time_zone_table[2].name = NULL; - } - break; - } + time_t probe = Start + quarter * (90 * 24 * 60 * 60); + struct tm const *probe_tm = localtime (&probe); + if (probe_tm && probe_tm->tm_zone + && probe_tm->tm_isdst != pc.local_time_zone_table[0].value) + { + { + pc.local_time_zone_table[1].name = probe_tm->tm_zone; + pc.local_time_zone_table[1].type = tLOCAL_ZONE; + pc.local_time_zone_table[1].value = probe_tm->tm_isdst; + pc.local_time_zone_table[2].name = NULL; + } + break; + } } } #else @@ -1332,9 +1332,9 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) int i; for (i = 0; i < 2; i++) { - pc.local_time_zone_table[i].name = tzname[i]; - pc.local_time_zone_table[i].type = tLOCAL_ZONE; - pc.local_time_zone_table[i].value = i; + pc.local_time_zone_table[i].name = tzname[i]; + pc.local_time_zone_table[i].type = tLOCAL_ZONE; + pc.local_time_zone_table[i].value = i; } pc.local_time_zone_table[i].name = NULL; } @@ -1345,11 +1345,11 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name && ! strcmp (pc.local_time_zone_table[0].name, - pc.local_time_zone_table[1].name)) + pc.local_time_zone_table[1].name)) { /* This locale uses the same abbrevation for standard and - daylight times. So if we see that abbreviation, we don't - know whether it's daylight time. */ + daylight times. So if we see that abbreviation, we don't + know whether it's daylight time. */ pc.local_time_zone_table[0].value = -1; pc.local_time_zone_table[1].name = NULL; } @@ -1362,162 +1362,162 @@ get_date (struct timespec *result, char const *p, struct timespec const *now) else { if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen - | (pc.local_zones_seen + pc.zones_seen))) - goto fail; + | (pc.local_zones_seen + pc.zones_seen))) + goto fail; tm.tm_year = to_year (pc.year) - TM_YEAR_BASE; tm.tm_mon = pc.month - 1; tm.tm_mday = pc.day; if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen)) - { - tm.tm_hour = to_hour (pc.hour, pc.meridian); - if (tm.tm_hour < 0) - goto fail; - tm.tm_min = pc.minutes; - tm.tm_sec = pc.seconds.tv_sec; - } + { + tm.tm_hour = to_hour (pc.hour, pc.meridian); + if (tm.tm_hour < 0) + goto fail; + tm.tm_min = pc.minutes; + tm.tm_sec = pc.seconds.tv_sec; + } else - { - tm.tm_hour = tm.tm_min = tm.tm_sec = 0; - pc.seconds.tv_nsec = 0; - } + { + tm.tm_hour = tm.tm_min = tm.tm_sec = 0; + pc.seconds.tv_nsec = 0; + } /* Let mktime deduce tm_isdst if we have an absolute time stamp. */ if (pc.dates_seen | pc.days_seen | pc.times_seen) - tm.tm_isdst = -1; + tm.tm_isdst = -1; /* But if the input explicitly specifies local time with or without - DST, give mktime that information. */ + DST, give mktime that information. */ if (pc.local_zones_seen) - tm.tm_isdst = pc.local_isdst; + tm.tm_isdst = pc.local_isdst; tm0 = tm; Start = mktime (&tm); if (! mktime_ok (&tm0, &tm, Start)) - { - if (! pc.zones_seen) - goto fail; - else - { - /* Guard against falsely reporting errors near the time_t - boundaries when parsing times in other time zones. For - example, suppose the input string "1969-12-31 23:00:00 -0100", - the current time zone is 8 hours ahead of UTC, and the min - time_t value is 1970-01-01 00:00:00 UTC. Then the min - localtime value is 1970-01-01 08:00:00, and mktime will - therefore fail on 1969-12-31 23:00:00. To work around the - problem, set the time zone to 1 hour behind UTC temporarily - by setting TZ="XXX1:00" and try mktime again. */ - - long int time_zone = pc.time_zone; - long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone; - long int abs_time_zone_hour = abs_time_zone / 60; - int abs_time_zone_min = abs_time_zone % 60; - char tz1buf[sizeof "XXX+0:00" - + sizeof pc.time_zone * CHAR_BIT / 3]; - if (!tz_was_altered) - tz0 = get_tz (tz0buf); - sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0), - abs_time_zone_hour, abs_time_zone_min); - if (setenv ("TZ", tz1buf, 1) != 0) - goto fail; - tz_was_altered = true; - tm = tm0; - Start = mktime (&tm); - if (! mktime_ok (&tm0, &tm, Start)) - goto fail; - } - } + { + if (! pc.zones_seen) + goto fail; + else + { + /* Guard against falsely reporting errors near the time_t + boundaries when parsing times in other time zones. For + example, suppose the input string "1969-12-31 23:00:00 -0100", + the current time zone is 8 hours ahead of UTC, and the min + time_t value is 1970-01-01 00:00:00 UTC. Then the min + localtime value is 1970-01-01 08:00:00, and mktime will + therefore fail on 1969-12-31 23:00:00. To work around the + problem, set the time zone to 1 hour behind UTC temporarily + by setting TZ="XXX1:00" and try mktime again. */ + + long int time_zone = pc.time_zone; + long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone; + long int abs_time_zone_hour = abs_time_zone / 60; + int abs_time_zone_min = abs_time_zone % 60; + char tz1buf[sizeof "XXX+0:00" + + sizeof pc.time_zone * CHAR_BIT / 3]; + if (!tz_was_altered) + tz0 = get_tz (tz0buf); + sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0), + abs_time_zone_hour, abs_time_zone_min); + if (setenv ("TZ", tz1buf, 1) != 0) + goto fail; + tz_was_altered = true; + tm = tm0; + Start = mktime (&tm); + if (! mktime_ok (&tm0, &tm, Start)) + goto fail; + } + } if (pc.days_seen && ! pc.dates_seen) - { - tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7 - + 7 * (pc.day_ordinal - - (0 < pc.day_ordinal - && tm.tm_wday != pc.day_number))); - tm.tm_isdst = -1; - Start = mktime (&tm); - if (Start == (time_t) -1) - goto fail; - } + { + tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7 + + 7 * (pc.day_ordinal + - (0 < pc.day_ordinal + && tm.tm_wday != pc.day_number))); + tm.tm_isdst = -1; + Start = mktime (&tm); + if (Start == (time_t) -1) + goto fail; + } /* Add relative date. */ if (pc.rel.year | pc.rel.month | pc.rel.day) - { - int year = tm.tm_year + pc.rel.year; - int month = tm.tm_mon + pc.rel.month; - int day = tm.tm_mday + pc.rel.day; - if (((year < tm.tm_year) ^ (pc.rel.year < 0)) - | ((month < tm.tm_mon) ^ (pc.rel.month < 0)) - | ((day < tm.tm_mday) ^ (pc.rel.day < 0))) - goto fail; - tm.tm_year = year; - tm.tm_mon = month; - tm.tm_mday = day; - tm.tm_hour = tm0.tm_hour; - tm.tm_min = tm0.tm_min; - tm.tm_sec = tm0.tm_sec; - tm.tm_isdst = tm0.tm_isdst; - Start = mktime (&tm); - if (Start == (time_t) -1) - goto fail; - } + { + int year = tm.tm_year + pc.rel.year; + int month = tm.tm_mon + pc.rel.month; + int day = tm.tm_mday + pc.rel.day; + if (((year < tm.tm_year) ^ (pc.rel.year < 0)) + | ((month < tm.tm_mon) ^ (pc.rel.month < 0)) + | ((day < tm.tm_mday) ^ (pc.rel.day < 0))) + goto fail; + tm.tm_year = year; + tm.tm_mon = month; + tm.tm_mday = day; + tm.tm_hour = tm0.tm_hour; + tm.tm_min = tm0.tm_min; + tm.tm_sec = tm0.tm_sec; + tm.tm_isdst = tm0.tm_isdst; + Start = mktime (&tm); + if (Start == (time_t) -1) + goto fail; + } /* The only "output" of this if-block is an updated Start value, - so this block must follow others that clobber Start. */ + so this block must follow others that clobber Start. */ if (pc.zones_seen) - { - long int delta = pc.time_zone * 60; - time_t t1; + { + long int delta = pc.time_zone * 60; + time_t t1; #ifdef HAVE_TM_GMTOFF - delta -= tm.tm_gmtoff; + delta -= tm.tm_gmtoff; #else - time_t t = Start; - struct tm const *gmt = gmtime (&t); - if (! gmt) - goto fail; - delta -= tm_diff (&tm, gmt); + time_t t = Start; + struct tm const *gmt = gmtime (&t); + if (! gmt) + goto fail; + delta -= tm_diff (&tm, gmt); #endif - t1 = Start - delta; - if ((Start < t1) != (delta < 0)) - goto fail; /* time_t overflow */ - Start = t1; - } + t1 = Start - delta; + if ((Start < t1) != (delta < 0)) + goto fail; /* time_t overflow */ + Start = t1; + } /* Add relative hours, minutes, and seconds. On hosts that support - leap seconds, ignore the possibility of leap seconds; e.g., - "+ 10 minutes" adds 600 seconds, even if one of them is a - leap second. Typically this is not what the user wants, but it's - too hard to do it the other way, because the time zone indicator - must be applied before relative times, and if mktime is applied - again the time zone will be lost. */ + leap seconds, ignore the possibility of leap seconds; e.g., + "+ 10 minutes" adds 600 seconds, even if one of them is a + leap second. Typically this is not what the user wants, but it's + too hard to do it the other way, because the time zone indicator + must be applied before relative times, and if mktime is applied + again the time zone will be lost. */ { - long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns; - long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION; - time_t t0 = Start; - long int d1 = 60 * 60 * pc.rel.hour; - time_t t1 = t0 + d1; - long int d2 = 60 * pc.rel.minutes; - time_t t2 = t1 + d2; - long_time_t d3 = pc.rel.seconds; - long_time_t t3 = t2 + d3; - long int d4 = (sum_ns - normalized_ns) / BILLION; - long_time_t t4 = t3 + d4; - time_t t5 = t4; - - if ((d1 / (60 * 60) ^ pc.rel.hour) - | (d2 / 60 ^ pc.rel.minutes) - | ((t1 < t0) ^ (d1 < 0)) - | ((t2 < t1) ^ (d2 < 0)) - | ((t3 < t2) ^ (d3 < 0)) - | ((t4 < t3) ^ (d4 < 0)) - | (t5 != t4)) - goto fail; - - result->tv_sec = t5; - result->tv_nsec = normalized_ns; + long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns; + long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION; + time_t t0 = Start; + long int d1 = 60 * 60 * pc.rel.hour; + time_t t1 = t0 + d1; + long int d2 = 60 * pc.rel.minutes; + time_t t2 = t1 + d2; + long_time_t d3 = pc.rel.seconds; + long_time_t t3 = t2 + d3; + long int d4 = (sum_ns - normalized_ns) / BILLION; + long_time_t t4 = t3 + d4; + time_t t5 = t4; + + if ((d1 / (60 * 60) ^ pc.rel.hour) + | (d2 / 60 ^ pc.rel.minutes) + | ((t1 < t0) ^ (d1 < 0)) + | ((t2 < t1) ^ (d2 < 0)) + | ((t3 < t2) ^ (d3 < 0)) + | ((t4 < t3) ^ (d4 < 0)) + | (t5 != t4)) + goto fail; + + result->tv_sec = t5; + result->tv_nsec = normalized_ns; } } @@ -1549,19 +1549,19 @@ main (int ac, char **av) struct timespec d; struct tm const *tm; if (! get_date (&d, buff, NULL)) - printf ("Bad format - couldn't convert.\n"); + printf ("Bad format - couldn't convert.\n"); else if (! (tm = localtime (&d.tv_sec))) - { - long int sec = d.tv_sec; - printf ("localtime (%ld) failed\n", sec); - } + { + long int sec = d.tv_sec; + printf ("localtime (%ld) failed\n", sec); + } else - { - int ns = d.tv_nsec; - printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n", - tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec, ns); - } + { + int ns = d.tv_nsec; + printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n", + tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec, ns); + } printf ("\t> "); fflush (stdout); } diff --git a/lib/getdelim.c b/lib/getdelim.c index 12f2167c9..cb8886d30 100644 --- a/lib/getdelim.c +++ b/lib/getdelim.c @@ -34,15 +34,15 @@ #if USE_UNLOCKED_IO # include "unlocked-io.h" -# define getc_maybe_unlocked(fp) getc(fp) +# define getc_maybe_unlocked(fp) getc(fp) #elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED # undef flockfile # undef funlockfile # define flockfile(x) ((void) 0) # define funlockfile(x) ((void) 0) -# define getc_maybe_unlocked(fp) getc(fp) +# define getc_maybe_unlocked(fp) getc(fp) #else -# define getc_maybe_unlocked(fp) getc_unlocked(fp) +# define getc_maybe_unlocked(fp) getc_unlocked(fp) #endif /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and @@ -71,10 +71,10 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) *n = 120; new_lineptr = (char *) realloc (*lineptr, *n); if (new_lineptr == NULL) - { - result = -1; - goto unlock_return; - } + { + result = -1; + goto unlock_return; + } *lineptr = new_lineptr; } @@ -84,44 +84,44 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) i = getc_maybe_unlocked (fp); if (i == EOF) - { - result = -1; - break; - } + { + result = -1; + break; + } /* Make enough space for len+1 (for final NUL) bytes. */ if (cur_len + 1 >= *n) - { - size_t needed_max = - SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX; - size_t needed = 2 * *n + 1; /* Be generous. */ - char *new_lineptr; - - if (needed_max < needed) - needed = needed_max; - if (cur_len + 1 >= needed) - { - result = -1; - errno = EOVERFLOW; - goto unlock_return; - } - - new_lineptr = (char *) realloc (*lineptr, needed); - if (new_lineptr == NULL) - { - result = -1; - goto unlock_return; - } - - *lineptr = new_lineptr; - *n = needed; - } + { + size_t needed_max = + SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX; + size_t needed = 2 * *n + 1; /* Be generous. */ + char *new_lineptr; + + if (needed_max < needed) + needed = needed_max; + if (cur_len + 1 >= needed) + { + result = -1; + errno = EOVERFLOW; + goto unlock_return; + } + + new_lineptr = (char *) realloc (*lineptr, needed); + if (new_lineptr == NULL) + { + result = -1; + goto unlock_return; + } + + *lineptr = new_lineptr; + *n = needed; + } (*lineptr)[cur_len] = i; cur_len++; if (i == delimiter) - break; + break; } (*lineptr)[cur_len] = '\0'; result = cur_len ? cur_len : result; diff --git a/lib/getdomainname.c b/lib/getdomainname.c index 658075320..c0041cc71 100644 --- a/lib/getdomainname.c +++ b/lib/getdomainname.c @@ -38,7 +38,7 @@ int getdomainname (char *name, size_t len) { - const char *result = ""; /* Hardcode your domain name if you want. */ + const char *result = ""; /* Hardcode your domain name if you want. */ size_t result_len = strlen (result); if (result_len > len) diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c index 5be1e8337..678ad14f1 100644 --- a/lib/getdtablesize.c +++ b/lib/getdtablesize.c @@ -33,27 +33,27 @@ 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. */ + 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. */ int orig_max_stdio = _getmaxstdio (); unsigned int bound; for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2) - ; + ; _setmaxstdio (orig_max_stdio); dtablesize = bound; } diff --git a/lib/gethostname.c b/lib/gethostname.c index 35d820685..dd895081f 100644 --- a/lib/gethostname.c +++ b/lib/gethostname.c @@ -54,7 +54,7 @@ gethostname (char *name, size_t len) } strncpy (name, uts.nodename, len); #else - strcpy (name, ""); /* Hardcode your system name if you want. */ + strcpy (name, ""); /* Hardcode your system name if you want. */ #endif return 0; } diff --git a/lib/getloadavg.c b/lib/getloadavg.c index a7bac4903..3bb589168 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c @@ -22,58 +22,58 @@ /* Compile-time symbols that this file uses: - HAVE_PSTAT_GETDYNAMIC Define this if your system has the + HAVE_PSTAT_GETDYNAMIC Define this if your system has the pstat_getdynamic function. I think it - is unique to HPUX9. The best way to get the - definition is through the AC_FUNC_GETLOADAVG - macro that comes with autoconf 2.13 or newer. - If that isn't an option, then just put - AC_CHECK_FUNCS(pstat_getdynamic) in your - configure.in file. + is unique to HPUX9. The best way to get the + definition is through the AC_FUNC_GETLOADAVG + macro that comes with autoconf 2.13 or newer. + If that isn't an option, then just put + AC_CHECK_FUNCS(pstat_getdynamic) in your + configure.in file. HAVE_LIBPERFSTAT Define this if your system has the - perfstat_cpu_total function in libperfstat (AIX). - FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. - KERNEL_FILE Name of the kernel file to nlist. - LDAV_CVT() Scale the load average from the kernel. - Returns a double. - LDAV_SYMBOL Name of kernel symbol giving load average. - LOAD_AVE_TYPE Type of the load average array in the kernel. - Must be defined unless one of - apollo, DGUX, NeXT, or UMAX is defined; + perfstat_cpu_total function in libperfstat (AIX). + FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. + KERNEL_FILE Name of the kernel file to nlist. + LDAV_CVT() Scale the load average from the kernel. + Returns a double. + LDAV_SYMBOL Name of kernel symbol giving load average. + LOAD_AVE_TYPE Type of the load average array in the kernel. + Must be defined unless one of + apollo, DGUX, NeXT, or UMAX is defined; or we have libkstat; - otherwise, no load average is available. + otherwise, no load average is available. HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults to this. - NLIST_STRUCT Include nlist.h, not a.out.h. - N_NAME_POINTER The nlist n_name element is a pointer, - not an array. + NLIST_STRUCT Include nlist.h, not a.out.h. + N_NAME_POINTER The nlist n_name element is a pointer, + not an array. HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'. - LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing - load averages. + LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing + load averages. Specific system predefines this file uses, aside from setting default values if not emacs: apollo - BSD Real BSD, not just BSD-like. + BSD Real BSD, not just BSD-like. convex DGUX - eunice UNIX emulator under VMS. + eunice UNIX emulator under VMS. hpux - __MSDOS__ No-op for MSDOS. + __MSDOS__ No-op for MSDOS. NeXT sgi - sequent Sequent Dynix 3.x.x (BSD) - _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) + sequent Sequent Dynix 3.x.x (BSD) + _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) sony_news NEWS-OS (works at least for 4.1C) UMAX UMAX4_3 VMS - WINDOWS32 No-op for Windows95/NT. - __linux__ Linux: assumes /proc file system mounted. - Support from Michael K. Johnson. - __CYGWIN__ Cygwin emulates linux /proc/loadavg. - __NetBSD__ NetBSD: assumes /kern file system mounted. + WINDOWS32 No-op for Windows95/NT. + __linux__ Linux: assumes /proc file system mounted. + Support from Michael K. Johnson. + __CYGWIN__ Cygwin emulates linux /proc/loadavg. + __NetBSD__ NetBSD: assumes /kern file system mounted. In addition, to avoid nesting many #ifdefs, we internally set LDAV_DONE to indicate that the load average has been computed. @@ -203,7 +203,7 @@ default, but _MACH_IND_SYS_TYPES is defined in . Combine that with a couple of other things and we'll have a unique match. */ # if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES) -# define tek4300 /* Define by emacs, but not by other users. */ +# define tek4300 /* Define by emacs, but not by other users. */ # endif @@ -317,7 +317,7 @@ # define FSCALE 65536.0 # endif -# endif /* Not FSCALE. */ +# endif /* Not FSCALE. */ # if !defined (LDAV_CVT) && defined (FSCALE) # define LDAV_CVT(n) (((double) (n)) / FSCALE) @@ -478,7 +478,7 @@ static unsigned int samples; # endif /* UMAX */ # ifdef DGUX -static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ +static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ # endif /* DGUX */ # if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE) @@ -507,7 +507,7 @@ static kvm_t *kd; int getloadavg (double loadavg[], int nelem) { - int elem = 0; /* Return value. */ + int elem = 0; /* Return value. */ # ifdef NO_GET_LOAD_AVG # define LDAV_DONE @@ -549,16 +549,16 @@ getloadavg (double loadavg[], int nelem) { kn = kstat_data_lookup (ksp, "avenrun_5min"); if (kn != 0) - { - loadavg[elem++] = (double) kn->value.ul / FSCALE; - - if (nelem >= 3) - { - kn = kstat_data_lookup (ksp, "avenrun_15min"); - if (kn != 0) - loadavg[elem++] = (double) kn->value.ul / FSCALE; - } - } + { + loadavg[elem++] = (double) kn->value.ul / FSCALE; + + if (nelem >= 3) + { + kn = kstat_data_lookup (ksp, "avenrun_15min"); + if (kn != 0) + loadavg[elem++] = (double) kn->value.ul / FSCALE; + } + } } kstat_close (kc); @@ -626,11 +626,11 @@ getloadavg (double loadavg[], int nelem) errno = 0; d = c_strtod (ptr, &endptr); if (ptr == endptr || (d == 0 && errno != 0)) - { - if (elem == 0) - return -1; - break; - } + { + if (elem == 0) + return -1; + break; + } loadavg[elem] = d; ptr = endptr; } @@ -655,8 +655,8 @@ getloadavg (double loadavg[], int nelem) if (fp == NULL) return -1; count = fscanf (fp, "%lu %lu %lu %lu\n", - &load_ave[0], &load_ave[1], &load_ave[2], - &scale); + &load_ave[0], &load_ave[1], &load_ave[2], + &scale); (void) fclose (fp); if (count != 4) return -1; @@ -682,21 +682,21 @@ getloadavg (double loadavg[], int nelem) if (!getloadavg_initialized) { if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS) - getloadavg_initialized = true; + getloadavg_initialized = true; } if (getloadavg_initialized) { info_count = PROCESSOR_SET_BASIC_INFO_COUNT; if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, - (processor_set_info_t) &info, &info_count) - != KERN_SUCCESS) - getloadavg_initialized = false; + (processor_set_info_t) &info, &info_count) + != KERN_SUCCESS) + getloadavg_initialized = false; else - { - if (nelem > 0) - loadavg[elem++] = (double) info.load_average / LOAD_SCALE; - } + { + if (nelem > 0) + loadavg[elem++] = (double) info.load_average / LOAD_SCALE; + } } if (!getloadavg_initialized) @@ -728,24 +728,24 @@ getloadavg (double loadavg[], int nelem) desc.sd_size = sizeof conf; if (inq_stats (1, &desc)) - return -1; + return -1; c = 0; for (i = 0; i < conf.config_maxclass; ++i) - { - struct class_stats stats; - bzero ((char *) &stats, sizeof stats); + { + struct class_stats stats; + bzero ((char *) &stats, sizeof stats); - desc.sd_type = CPUTYPE_CLASS; - desc.sd_objid = i; - desc.sd_addr = (char *) &stats; - desc.sd_size = sizeof stats; + desc.sd_type = CPUTYPE_CLASS; + desc.sd_objid = i; + desc.sd_addr = (char *) &stats; + desc.sd_size = sizeof stats; - if (inq_stats (1, &desc)) - return -1; + if (inq_stats (1, &desc)) + return -1; - c += stats.class_numcpus; - } + c += stats.class_numcpus; + } cpus = c; samples = cpus < 2 ? 3 : (2 * cpus / 3); } @@ -766,7 +766,7 @@ getloadavg (double loadavg[], int nelem) { load += proc_sum_data.ps_nrun[j]; if (j++ == PS_NRUNSIZE) - j = 0; + j = 0; } if (nelem > 0) @@ -779,8 +779,8 @@ getloadavg (double loadavg[], int nelem) it's not supposed to fail. The first argument is for no apparent reason of type `long int *'. */ dg_sys_info ((long int *) &load_info, - DG_SYS_INFO_LOAD_INFO_TYPE, - DG_SYS_INFO_LOAD_VERSION_0); + DG_SYS_INFO_LOAD_INFO_TYPE, + DG_SYS_INFO_LOAD_VERSION_0); if (nelem > 0) loadavg[elem++] = load_info.one_minute; @@ -824,7 +824,7 @@ getloadavg (double loadavg[], int nelem) = (load_ave.tl_lscale == 0 ? load_ave.tl_avenrun.d[0] : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); -# endif /* OSF_MIPS */ +# endif /* OSF_MIPS */ # if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32)) # define LDAV_DONE @@ -844,8 +844,8 @@ getloadavg (double loadavg[], int nelem) for (elem = 0; elem < nelem; elem++) loadavg[elem] = (load_ave.tl_lscale == 0 - ? load_ave.tl_avenrun.d[elem] - : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); + ? load_ave.tl_avenrun.d[elem] + : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); # endif /* OSF_ALPHA */ # if ! defined LDAV_DONE && defined __VMS @@ -872,13 +872,13 @@ getloadavg (double loadavg[], int nelem) $DESCRIPTOR (descriptor, "LAV0:"); # endif if (sys$assign (&descriptor, &channel, 0, 0) & 1) - getloadavg_initialized = true; + getloadavg_initialized = true; } /* Read the load average vector. */ if (getloadavg_initialized && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0, - load_ave, 12, 0, 0, 0, 0) & 1)) + load_ave, 12, 0, 0, 0, 0) & 1)) { sys$dassgn (channel); getloadavg_initialized = false; @@ -892,7 +892,7 @@ getloadavg (double loadavg[], int nelem) /* UNIX-specific code -- read the average from /dev/kmem. */ -# define LDAV_PRIVILEGED /* This code requires special installation. */ +# define LDAV_PRIVILEGED /* This code requires special installation. */ LOAD_AVE_TYPE load_ave[3]; @@ -916,25 +916,25 @@ getloadavg (double loadavg[], int nelem) # ifndef SUNOS_5 if ( # if !(defined (_AIX) && !defined (ps2)) - nlist (KERNEL_FILE, nl) + nlist (KERNEL_FILE, nl) # else /* _AIX */ - knlist (nl, 1, sizeof (nl[0])) + knlist (nl, 1, sizeof (nl[0])) # endif - >= 0) - /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ - { + >= 0) + /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ + { # ifdef FIXUP_KERNEL_SYMBOL_ADDR - FIXUP_KERNEL_SYMBOL_ADDR (nl); + FIXUP_KERNEL_SYMBOL_ADDR (nl); # endif - offset = nl[0].n_value; - } + offset = nl[0].n_value; + } # endif /* !SUNOS_5 */ # else /* sgi */ int ldav_off; ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); if (ldav_off != -1) - offset = (long int) ldav_off & 0x7fffffff; + offset = (long int) ldav_off & 0x7fffffff; # endif /* sgi */ } @@ -944,23 +944,23 @@ getloadavg (double loadavg[], int nelem) # ifndef SUNOS_5 channel = open ("/dev/kmem", O_RDONLY); if (channel >= 0) - { - /* Set the channel to close on exec, so it does not - litter any child's descriptor table. */ - set_cloexec_flag (channel, true); - getloadavg_initialized = true; - } + { + /* Set the channel to close on exec, so it does not + litter any child's descriptor table. */ + set_cloexec_flag (channel, true); + getloadavg_initialized = true; + } # else /* SUNOS_5 */ /* We pass 0 for the kernel, corefile, and swapfile names - to use the currently running kernel. */ + to use the currently running kernel. */ kd = kvm_open (0, 0, 0, O_RDONLY, 0); if (kd != 0) - { - /* nlist the currently running kernel. */ - kvm_nlist (kd, nl); - offset = nl[0].n_value; - getloadavg_initialized = true; - } + { + /* nlist the currently running kernel. */ + kvm_nlist (kd, nl); + offset = nl[0].n_value; + getloadavg_initialized = true; + } # endif /* SUNOS_5 */ } @@ -970,19 +970,19 @@ getloadavg (double loadavg[], int nelem) /* Try to read the load. */ # ifndef SUNOS_5 if (lseek (channel, offset, 0) == -1L - || read (channel, (char *) load_ave, sizeof (load_ave)) - != sizeof (load_ave)) - { - close (channel); - getloadavg_initialized = false; - } + || read (channel, (char *) load_ave, sizeof (load_ave)) + != sizeof (load_ave)) + { + close (channel); + getloadavg_initialized = false; + } # else /* SUNOS_5 */ if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) - != sizeof (load_ave)) - { - kvm_close (kd); - getloadavg_initialized = false; - } + != sizeof (load_ave)) + { + kvm_close (kd); + getloadavg_initialized = false; + } # endif /* SUNOS_5 */ } @@ -1026,24 +1026,24 @@ main (int argc, char **argv) double avg[3]; int loads; - errno = 0; /* Don't be misled if it doesn't set errno. */ + errno = 0; /* Don't be misled if it doesn't set errno. */ loads = getloadavg (avg, 3); if (loads == -1) - { - perror ("Error getting load average"); - return EXIT_FAILURE; - } + { + perror ("Error getting load average"); + return EXIT_FAILURE; + } if (loads > 0) - printf ("1-minute: %f ", avg[0]); + printf ("1-minute: %f ", avg[0]); if (loads > 1) - printf ("5-minute: %f ", avg[1]); + printf ("5-minute: %f ", avg[1]); if (loads > 2) - printf ("15-minute: %f ", avg[2]); + printf ("15-minute: %f ", avg[2]); if (loads > 0) - putchar ('\n'); + putchar ('\n'); if (naptime == 0) - break; + break; sleep (naptime); } diff --git a/lib/getndelim2.c b/lib/getndelim2.c index 9dcb9feb4..7515e18a8 100644 --- a/lib/getndelim2.c +++ b/lib/getndelim2.c @@ -71,8 +71,8 @@ ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax, int delim1, int delim2, FILE *stream) { - size_t nbytes_avail; /* Allocated but unused bytes in *LINEPTR. */ - char *read_pos; /* Where we're reading into *LINEPTR. */ + size_t nbytes_avail; /* Allocated but unused bytes in *LINEPTR. */ + char *read_pos; /* Where we're reading into *LINEPTR. */ ssize_t bytes_stored = -1; char *ptr = *lineptr; size_t size = *linesize; @@ -83,7 +83,7 @@ getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax, size = nmax < MIN_CHUNK ? nmax : MIN_CHUNK; ptr = malloc (size); if (!ptr) - return -1; + return -1; } if (size < offset) @@ -107,7 +107,7 @@ getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax, do { /* Here always ptr + size == read_pos + nbytes_avail. - Also nbytes_avail > 0 || size < nmax. */ + Also nbytes_avail > 0 || size < nmax. */ int c IF_LINT (= 0); const char *buffer; @@ -115,89 +115,89 @@ getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax, buffer = freadptr (stream, &buffer_len); if (buffer) - { - if (delim1 != EOF) - { - const char *end = memchr2 (buffer, delim1, delim2, buffer_len); - if (end) - { - buffer_len = end - buffer + 1; - found_delimiter = true; - } - } - } + { + if (delim1 != EOF) + { + const char *end = memchr2 (buffer, delim1, delim2, buffer_len); + if (end) + { + buffer_len = end - buffer + 1; + found_delimiter = true; + } + } + } else - { - c = getc (stream); - if (c == EOF) - { - /* Return partial line, if any. */ - if (read_pos == ptr) - goto unlock_done; - else - break; - } - if (c == delim1 || c == delim2) - found_delimiter = true; - buffer_len = 1; - } + { + c = getc (stream); + if (c == EOF) + { + /* Return partial line, if any. */ + if (read_pos == ptr) + goto unlock_done; + else + break; + } + if (c == delim1 || c == delim2) + found_delimiter = true; + buffer_len = 1; + } /* We always want at least one byte left in the buffer, since we - always (unless we get an error while reading the first byte) - NUL-terminate the line buffer. */ + always (unless we get an error while reading the first byte) + NUL-terminate the line buffer. */ if (nbytes_avail < buffer_len + 1 && size < nmax) - { - /* Grow size proportionally, not linearly, to avoid O(n^2) - running time. */ - size_t newsize = size < MIN_CHUNK ? size + MIN_CHUNK : 2 * size; - char *newptr; - - /* Increase newsize so that it becomes - >= (read_pos - ptr) + buffer_len. */ - if (newsize - (read_pos - ptr) < buffer_len + 1) - newsize = (read_pos - ptr) + buffer_len + 1; - /* Respect nmax. This handles possible integer overflow. */ - if (! (size < newsize && newsize <= nmax)) - newsize = nmax; - - if (GETNDELIM2_MAXIMUM < newsize - offset) - { - size_t newsizemax = offset + GETNDELIM2_MAXIMUM + 1; - if (size == newsizemax) - goto unlock_done; - newsize = newsizemax; - } - - nbytes_avail = newsize - (read_pos - ptr); - newptr = realloc (ptr, newsize); - if (!newptr) - goto unlock_done; - ptr = newptr; - size = newsize; - read_pos = size - nbytes_avail + ptr; - } + { + /* Grow size proportionally, not linearly, to avoid O(n^2) + running time. */ + size_t newsize = size < MIN_CHUNK ? size + MIN_CHUNK : 2 * size; + char *newptr; + + /* Increase newsize so that it becomes + >= (read_pos - ptr) + buffer_len. */ + if (newsize - (read_pos - ptr) < buffer_len + 1) + newsize = (read_pos - ptr) + buffer_len + 1; + /* Respect nmax. This handles possible integer overflow. */ + if (! (size < newsize && newsize <= nmax)) + newsize = nmax; + + if (GETNDELIM2_MAXIMUM < newsize - offset) + { + size_t newsizemax = offset + GETNDELIM2_MAXIMUM + 1; + if (size == newsizemax) + goto unlock_done; + newsize = newsizemax; + } + + nbytes_avail = newsize - (read_pos - ptr); + newptr = realloc (ptr, newsize); + if (!newptr) + goto unlock_done; + ptr = newptr; + size = newsize; + read_pos = size - nbytes_avail + ptr; + } /* Here, if size < nmax, nbytes_avail >= buffer_len + 1. - If size == nmax, nbytes_avail > 0. */ + If size == nmax, nbytes_avail > 0. */ if (1 < nbytes_avail) - { - size_t copy_len = nbytes_avail - 1; - if (buffer_len < copy_len) - copy_len = buffer_len; - if (buffer) - memcpy (read_pos, buffer, copy_len); - else - *read_pos = c; - read_pos += copy_len; - nbytes_avail -= copy_len; - } + { + size_t copy_len = nbytes_avail - 1; + if (buffer_len < copy_len) + copy_len = buffer_len; + if (buffer) + memcpy (read_pos, buffer, copy_len); + else + *read_pos = c; + read_pos += copy_len; + nbytes_avail -= copy_len; + } /* Here still nbytes_avail > 0. */ if (buffer && freadseek (stream, buffer_len)) - goto unlock_done; + goto unlock_done; } while (!found_delimiter); diff --git a/lib/getnline.c b/lib/getnline.c index c53177b03..66a4f878a 100644 --- a/lib/getnline.c +++ b/lib/getnline.c @@ -24,7 +24,7 @@ ssize_t getndelim (char **lineptr, size_t *linesize, size_t nmax, - int delimiter, FILE *stream) + int delimiter, FILE *stream) { return getndelim2 (lineptr, linesize, 0, nmax, delimiter, EOF, stream); } diff --git a/lib/getnline.h b/lib/getnline.h index 84e6a1787..429248b5e 100644 --- a/lib/getnline.h +++ b/lib/getnline.h @@ -31,7 +31,7 @@ Return the number of bytes read and stored at *LINEPTR (not including the NUL terminator), or -1 on error or EOF. */ extern ssize_t getnline (char **lineptr, size_t *linesize, size_t nmax, - FILE *stream); + FILE *stream); /* Read a line, up to the next occurrence of DELIMITER, from STREAM, and store it in *LINEPTR. @@ -42,6 +42,6 @@ extern ssize_t getnline (char **lineptr, size_t *linesize, size_t nmax, Return the number of bytes read and stored at *LINEPTR (not including the NUL terminator), or -1 on error or EOF. */ extern ssize_t getndelim (char **lineptr, size_t *linesize, size_t nmax, - int delimiter, FILE *stream); + int delimiter, FILE *stream); #endif /* GETNLINE_H */ diff --git a/lib/getopt.c b/lib/getopt.c index 797d166f1..fbe7b5b3e 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -3,7 +3,7 @@ "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006,2008,2009 - Free Software Foundation, Inc. + 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 @@ -121,18 +121,18 @@ extern char *__getopt_nonoption_flags; # 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; \ + 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 */ +#else /* !_LIBC */ # define SWAP_FLAGS(ch1, ch2) -#endif /* _LIBC */ +#endif /* _LIBC */ /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) @@ -163,57 +163,57 @@ exchange (char **argv, struct _getopt_data *d) 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. */ + presents new arguments. */ char *new_str = malloc (top + 1); if (new_str == NULL) - d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0; + 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; - } + { + 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; - register 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; - } + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register 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; - register 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; - } + { + /* Top segment is the short one. */ + int len = top - middle; + register 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. */ @@ -226,8 +226,8 @@ exchange (char **argv, struct _getopt_data *d) static const char * _getopt_initialize (int argc _UNUSED_PARAMETER_, - char **argv _UNUSED_PARAMETER_, const char *optstring, - int posixly_correct, struct _getopt_data *d) + char **argv _UNUSED_PARAMETER_, const char *optstring, + int posixly_correct, struct _getopt_data *d) { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped @@ -261,25 +261,25 @@ _getopt_initialize (int argc _UNUSED_PARAMETER_, && 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); - } - } + { + 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 @@ -346,8 +346,8 @@ _getopt_initialize (int argc _UNUSED_PARAMETER_, int _getopt_internal_r (int argc, char **argv, const char *optstring, - const struct option *longopts, int *longind, - int long_only, int posixly_correct, struct _getopt_data *d) + const struct option *longopts, int *longind, + int long_only, int posixly_correct, struct _getopt_data *d) { int print_errors = d->opterr; if (optstring[0] == ':') @@ -361,9 +361,9 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, if (d->optind == 0 || !d->__initialized) { if (d->optind == 0) - d->optind = 1; /* Don't scan ARGV[0], the program name. */ + d->optind = 1; /* Don't scan ARGV[0], the program name. */ optstring = _getopt_initialize (argc, argv, optstring, - posixly_correct, d); + posixly_correct, d); d->__initialized = 1; } @@ -373,8 +373,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, 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')) + || (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 @@ -384,78 +384,78 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, /* 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). */ + moved back by the user (who may also have changed the arguments). */ if (d->__last_nonopt > d->optind) - d->__last_nonopt = d->optind; + d->__last_nonopt = d->optind; if (d->__first_nonopt > d->optind) - 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 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; + 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. */ + /* 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; - } + 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. */ + 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++; + { + 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; + 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; - } + 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. */ + 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; - } + { + /* 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. */ + 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; - } + { + 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. */ + Skip the initial punctuation. */ d->__nextchar = (argv[d->optind] + 1 - + (longopts != NULL && argv[d->optind][1] == '-')); + + (longopts != NULL && argv[d->optind][1] == '-')); } /* Decode the current option-ARGV-element. */ @@ -475,8 +475,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, if (longopts != NULL && (argv[d->optind][1] == '-' - || (long_only && (argv[d->optind][2] - || !strchr (optstring, argv[d->optind][1]))))) + || (long_only && (argv[d->optind][2] + || !strchr (optstring, argv[d->optind][1]))))) { char *nameend; const struct option *p; @@ -487,251 +487,251 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int option_index; for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; + /* Do nothing. */ ; /* Test all long options for either exact match - or abbreviated matches. */ + 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) - == (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. */ - ambig = 1; - } + if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar)) + { + if ((unsigned int) (nameend - d->__nextchar) + == (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. */ + ambig = 1; + } if (ambig && !exact) - { - if (print_errors) - { + { + if (print_errors) + { #if defined _LIBC && defined USE_IN_LIBIO - char *buf; + char *buf; - if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[d->optind]) >= 0) - { - _IO_flockfile (stderr); + if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[d->optind]) >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #else - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[d->optind]); + fprintf (stderr, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[d->optind]); #endif - } - d->__nextchar += strlen (d->__nextchar); - d->optind++; - d->optopt = 0; - return '?'; - } + } + d->__nextchar += strlen (d->__nextchar); + d->optind++; + d->optopt = 0; + return '?'; + } 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) - { + { + 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; + char *buf; + int n; #endif - if (argv[d->optind - 1][1] == '-') - { - /* --option */ + if (argv[d->optind - 1][1] == '-') + { + /* --option */ #if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("\ + n = __asprintf (&buf, _("\ %s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); + argv[0], pfound->name); #else - fprintf (stderr, _("\ + fprintf (stderr, _("\ %s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); + argv[0], pfound->name); #endif - } - else - { - /* +option or -option */ + } + else + { + /* +option or -option */ #if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("\ + n = __asprintf (&buf, _("\ %s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[d->optind - 1][0], - pfound->name); + argv[0], argv[d->optind - 1][0], + pfound->name); #else - fprintf (stderr, _("\ + fprintf (stderr, _("\ %s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[d->optind - 1][0], - pfound->name); + argv[0], argv[d->optind - 1][0], + pfound->name); #endif - } + } #if defined _LIBC && defined USE_IN_LIBIO - if (n >= 0) - { - _IO_flockfile (stderr); + if (n >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + 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) - { + } + + 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; + char *buf; - if (__asprintf (&buf, _("\ + if (__asprintf (&buf, _("\ %s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]) >= 0) - { - _IO_flockfile (stderr); + argv[0], argv[d->optind - 1]) >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #else - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]); + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[d->optind - 1]); #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; - } + } + 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. */ + 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) - { + || strchr (optstring, *d->__nextchar) == NULL) + { + if (print_errors) + { #if defined _LIBC && defined USE_IN_LIBIO - char *buf; - int n; + char *buf; + int n; #endif - if (argv[d->optind][1] == '-') - { - /* --option */ + 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); + n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), + argv[0], d->__nextchar); #else - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], d->__nextchar); + fprintf (stderr, _("%s: unrecognized option `--%s'\n"), + argv[0], d->__nextchar); #endif - } - else - { - /* +option or -option */ + } + 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); + 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); + 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); + if (n >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #endif - } - d->__nextchar = (char *) ""; - d->optind++; - d->optopt = 0; - return '?'; - } + } + d->__nextchar = (char *) ""; + d->optind++; + d->optopt = 0; + return '?'; + } } /* Look at and handle the next short option-character. */ @@ -746,335 +746,335 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, if (temp == NULL || c == ':') { - if (print_errors) - { + if (print_errors) + { #if defined _LIBC && defined USE_IN_LIBIO - char *buf; - int n; + char *buf; + int n; #endif - if (d->__posixly_correct) - { - /* 1003.2 specifies the format of this message. */ + if (d->__posixly_correct) + { + /* 1003.2 specifies the format of this message. */ #if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("%s: illegal option -- %c\n"), - argv[0], c); + n = __asprintf (&buf, _("%s: illegal option -- %c\n"), + argv[0], c); #else - fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); + fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); #endif - } - else - { + } + else + { #if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("%s: invalid option -- %c\n"), - argv[0], c); + n = __asprintf (&buf, _("%s: invalid option -- %c\n"), + argv[0], c); #else - fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); + fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); #endif - } + } #if defined _LIBC && defined USE_IN_LIBIO - if (n >= 0) - { - _IO_flockfile (stderr); + if (n >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #endif - } - d->optopt = c; - return '?'; + } + 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; - - /* 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) - { - /* 1003.2 specifies the format of this message. */ + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + + /* 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) + { + /* 1003.2 specifies the format of this message. */ #if defined _LIBC && defined USE_IN_LIBIO - char *buf; + char *buf; - if (__asprintf (&buf, - _("%s: option requires an argument -- %c\n"), - argv[0], c) >= 0) - { - _IO_flockfile (stderr); + 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; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #else - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); + 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 - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (print_errors) - { + } + 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 + /* Second or later nonexact match found. */ + ambig = 1; + } + if (ambig && !exact) + { + if (print_errors) + { #if defined _LIBC && defined USE_IN_LIBIO - char *buf; + char *buf; - if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[d->optind]) >= 0) - { - _IO_flockfile (stderr); + if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[d->optind]) >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #else - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[d->optind]); + fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[d->optind]); #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) - { + } + 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; + char *buf; - if (__asprintf (&buf, _("\ + if (__asprintf (&buf, _("\ %s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name) >= 0) - { - _IO_flockfile (stderr); + argv[0], pfound->name) >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #else - fprintf (stderr, _("\ + fprintf (stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); + 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) - { + } + + 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; + char *buf; - if (__asprintf (&buf, _("\ + if (__asprintf (&buf, _("\ %s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]) >= 0) - { - _IO_flockfile (stderr); + argv[0], argv[d->optind - 1]) >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 + |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #else - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]); + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[d->optind - 1]); #endif - } - d->__nextchar += strlen (d->__nextchar); - 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; - } - d->__nextchar = NULL; - return 'W'; /* Let the application handle it. */ + } + d->__nextchar += strlen (d->__nextchar); + 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; + } + 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) - { - /* 1003.2 specifies the format of this message. */ + 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) + { + /* 1003.2 specifies the format of this message. */ #if defined _LIBC && defined USE_IN_LIBIO - char *buf; + char *buf; - if (__asprintf (&buf, _("\ + if (__asprintf (&buf, _("\ %s: option requires an argument -- %c\n"), - argv[0], c) >= 0) - { - _IO_flockfile (stderr); + argv[0], c) >= 0) + { + _IO_flockfile (stderr); - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; + int old_flags2 = ((_IO_FILE *) stderr)->_flags2; + ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - __fxprintf (NULL, "%s", buf); + __fxprintf (NULL, "%s", buf); - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); + ((_IO_FILE *) stderr)->_flags2 = old_flags2; + _IO_funlockfile (stderr); - free (buf); - } + free (buf); + } #else - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); + 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; - } + } + 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; } @@ -1082,8 +1082,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, int _getopt_internal (int argc, char **argv, const char *optstring, - const struct option *longopts, int *longind, - int long_only, int posixly_correct) + const struct option *longopts, int *longind, + int long_only, int posixly_correct) { int result; @@ -1091,7 +1091,7 @@ _getopt_internal (int argc, char **argv, const char *optstring, getopt_data.opterr = opterr; result = _getopt_internal_r (argc, argv, optstring, longopts, longind, - long_only, posixly_correct, &getopt_data); + long_only, posixly_correct, &getopt_data); optind = getopt_data.optind; optarg = getopt_data.optarg; @@ -1112,7 +1112,7 @@ int getopt (int argc, char *const *argv, const char *optstring) { return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0, - POSIXLY_CORRECT); + POSIXLY_CORRECT); } @@ -1133,51 +1133,51 @@ main (int argc, char **argv) c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) - break; + 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); - } + { + 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 ("%s ", argv[optind++]); printf ("\n"); } diff --git a/lib/getopt.in.h b/lib/getopt.in.h index 7377f3cfb..ed9689cb1 100644 --- a/lib/getopt.in.h +++ b/lib/getopt.in.h @@ -115,7 +115,7 @@ # define __GNUC_PREREQ(maj, min) (0) # endif # if defined __cplusplus && __GNUC_PREREQ (2,8) -# define __THROW throw () +# define __THROW throw () # else # define __THROW # endif @@ -163,9 +163,9 @@ extern int optopt; 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. + 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 @@ -190,10 +190,10 @@ struct option /* 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 */ +# define no_argument 0 +# define required_argument 1 +# define optional_argument 2 +#endif /* need getopt */ /* Get definitions and prototypes for functions to process the @@ -226,12 +226,12 @@ extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) #ifndef __need_getopt extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind) + const char *__shortopts, + const struct option *__longopts, int *__longind) __THROW; extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind) + const char *__shortopts, + const struct option *__longopts, int *__longind) __THROW; #endif diff --git a/lib/getopt1.c b/lib/getopt1.c index ba115c472..c3179c5e5 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -32,25 +32,25 @@ #include #endif -#ifndef NULL +#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) + const struct option *long_options, int *opt_index) { return _getopt_internal (argc, (char **) argv, options, long_options, - opt_index, 0, 0); + 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) + const struct option *long_options, int *opt_index, + struct _getopt_data *d) { return _getopt_internal_r (argc, argv, options, long_options, opt_index, - 0, 0, d); + 0, 0, d); } /* Like getopt_long, but '-' as well as '--' can indicate a long option. @@ -60,20 +60,20 @@ _getopt_long_r (int argc, char **argv, const char *options, int getopt_long_only (int argc, char *__getopt_argv_const *argv, - const char *options, - const struct option *long_options, int *opt_index) + const char *options, + const struct option *long_options, int *opt_index) { return _getopt_internal (argc, (char **) argv, options, long_options, - opt_index, 1, 0); + 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) + const struct option *long_options, int *opt_index, + struct _getopt_data *d) { return _getopt_internal_r (argc, argv, options, long_options, opt_index, - 1, 0, d); + 1, 0, d); } @@ -93,74 +93,74 @@ main (int argc, char **argv) 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} + {"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); + long_options, &option_index); if (c == -1) - break; + 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); - } + { + 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 ("%s ", argv[optind++]); printf ("\n"); } diff --git a/lib/getopt_int.h b/lib/getopt_int.h index 69cdf0de4..18465bcb6 100644 --- a/lib/getopt_int.h +++ b/lib/getopt_int.h @@ -17,14 +17,14 @@ along with this program. If not, see . */ #ifndef _GETOPT_INT_H -#define _GETOPT_INT_H 1 +#define _GETOPT_INT_H 1 #include extern int _getopt_internal (int ___argc, char **___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - int __long_only, int __posixly_correct); + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only, int __posixly_correct); /* Reentrant versions which can handle parsing multiple argument @@ -110,23 +110,23 @@ struct _getopt_data /* 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 } +#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, int __posixly_correct, - struct _getopt_data *__data); + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only, int __posixly_correct, + struct _getopt_data *__data); extern int _getopt_long_r (int ___argc, char **___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - struct _getopt_data *__data); + 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); + const char *__shortopts, + const struct option *__longopts, + int *__longind, + struct _getopt_data *__data); #endif /* getopt_int.h */ diff --git a/lib/getpass.c b/lib/getpass.c index 17d513720..86a3ad0e2 100644 --- a/lib/getpass.c +++ b/lib/getpass.c @@ -34,7 +34,7 @@ # include # endif #else -# define __fsetlocking(stream, type) /* empty */ +# define __fsetlocking(stream, type) /* empty */ #endif #if HAVE_TERMIOS_H @@ -145,17 +145,17 @@ getpass (const char *prompt) if (buf != NULL) { if (nread < 0) - buf[0] = '\0'; + buf[0] = '\0'; else if (buf[nread - 1] == '\n') - { - /* Remove the newline. */ - buf[nread - 1] = '\0'; - if (tty_changed) - { - /* Write the newline that was not echoed. */ - putc_unlocked ('\n', out); - } - } + { + /* Remove the newline. */ + buf[nread - 1] = '\0'; + if (tty_changed) + { + /* Write the newline that was not echoed. */ + putc_unlocked ('\n', out); + } + } } /* Restore the original setting. */ @@ -204,20 +204,20 @@ getpass (const char *prompt) { c = _getch (); if (c == '\r') - { - getpassbuf[i] = '\0'; - break; - } + { + getpassbuf[i] = '\0'; + break; + } else if (i < PASS_MAX) - { - getpassbuf[i++] = c; - } + { + getpassbuf[i++] = c; + } if (i >= PASS_MAX) - { - getpassbuf[i] = '\0'; - break; - } + { + getpassbuf[i] = '\0'; + break; + } } if (prompt) diff --git a/lib/getsockopt.c b/lib/getsockopt.c index 128edd6df..49bcccdea 100644 --- a/lib/getsockopt.c +++ b/lib/getsockopt.c @@ -51,7 +51,7 @@ rpl_getsockopt (int fd, int level, int optname, void *optval, socklen_t *optlen) tv.tv_usec = (milliseconds - 1000 * tv.tv_sec) * 1000; n = sizeof (struct timeval); if (n > *optlen) - n = *optlen; + n = *optlen; memcpy (optval, &tv, n); *optlen = n; } diff --git a/lib/getsubopt.c b/lib/getsubopt.c index f29f35935..b8199f142 100644 --- a/lib/getsubopt.c +++ b/lib/getsubopt.c @@ -58,16 +58,16 @@ getsubopt (char **optionp, char *const *tokens, char **valuep) one of the TOKENS. */ for (cnt = 0; tokens[cnt] != NULL; ++cnt) if (strncmp (*optionp, tokens[cnt], vstart - *optionp) == 0 - && tokens[cnt][vstart - *optionp] == '\0') + && tokens[cnt][vstart - *optionp] == '\0') { - /* We found the current option in TOKENS. */ - *valuep = vstart != endp ? vstart + 1 : NULL; + /* We found the current option in TOKENS. */ + *valuep = vstart != endp ? vstart + 1 : NULL; - if (*endp != '\0') - *endp++ = '\0'; - *optionp = endp; + if (*endp != '\0') + *endp++ = '\0'; + *optionp = endp; - return cnt; + return cnt; } /* The current suboption does not match any option. */ diff --git a/lib/gettext.h b/lib/gettext.h index a5b85c741..0afa76131 100644 --- a/lib/gettext.h +++ b/lib/gettext.h @@ -140,8 +140,8 @@ inline #endif static const char * pgettext_aux (const char *domain, - const char *msg_ctxt_id, const char *msgid, - int category) + const char *msg_ctxt_id, const char *msgid, + int category) { const char *translation = dcgettext (domain, msg_ctxt_id, category); if (translation == msg_ctxt_id) @@ -159,9 +159,9 @@ inline #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 *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); @@ -199,8 +199,8 @@ inline #endif static const char * dcpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - int category) + const char *msgctxt, const char *msgid, + int category) { size_t msgctxt_len = strlen (msgctxt) + 1; size_t msgid_len = strlen (msgid) + 1; @@ -222,10 +222,10 @@ dcpgettext_expr (const char *domain, translation = dcgettext (domain, msg_ctxt_id, category); #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS if (msg_ctxt_id != buf) - free (msg_ctxt_id); + free (msg_ctxt_id); #endif if (translation != msg_ctxt_id) - return translation; + return translation; } return msgid; } @@ -244,9 +244,9 @@ inline #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) + 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; @@ -268,10 +268,10 @@ dcnpgettext_expr (const char *domain, 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); + free (msg_ctxt_id); #endif if (!(translation == msg_ctxt_id || translation == msgid_plural)) - return translation; + return translation; } return (n == 1 ? msgid : msgid_plural); } diff --git a/lib/getugroups.c b/lib/getugroups.c index 8605ab1a1..b17563e89 100644 --- a/lib/getugroups.c +++ b/lib/getugroups.c @@ -56,14 +56,14 @@ getugroups (int maxcount _UNUSED_PARAMETER_, int getugroups (int maxcount, gid_t *grouplist, char const *username, - gid_t gid) + gid_t gid) { int count = 0; if (gid != (gid_t) -1) { if (maxcount != 0) - grouplist[count] = gid; + grouplist[count] = gid; ++count; } @@ -76,37 +76,37 @@ getugroups (int maxcount, gid_t *grouplist, char const *username, errno = 0; grp = getgrent (); if (grp == NULL) - break; + break; for (cp = grp->gr_mem; *cp; ++cp) - { - int n; - - if ( ! STREQ (username, *cp)) - continue; - - /* See if this group number is already on the list. */ - for (n = 0; n < count; ++n) - if (grouplist && grouplist[n] == grp->gr_gid) - break; - - /* If it's a new group number, then try to add it to the list. */ - if (n == count) - { - if (maxcount != 0) - { - if (count >= maxcount) - goto done; - grouplist[count] = grp->gr_gid; - } - if (count == INT_MAX) - { - errno = EOVERFLOW; - goto done; - } - count++; - } - } + { + int n; + + if ( ! STREQ (username, *cp)) + continue; + + /* See if this group number is already on the list. */ + for (n = 0; n < count; ++n) + if (grouplist && grouplist[n] == grp->gr_gid) + break; + + /* If it's a new group number, then try to add it to the list. */ + if (n == count) + { + if (maxcount != 0) + { + if (count >= maxcount) + goto done; + grouplist[count] = grp->gr_gid; + } + if (count == INT_MAX) + { + errno = EOVERFLOW; + goto done; + } + count++; + } + } } if (errno != 0) diff --git a/lib/getusershell.c b/lib/getusershell.c index bea62a07a..ca2121d22 100644 --- a/lib/getusershell.c +++ b/lib/getusershell.c @@ -83,8 +83,8 @@ getusershell (void) if (default_index > 0) { if (default_shells[default_index]) - /* Not at the end of the list yet. */ - return xstrdup (default_shells[default_index++]); + /* Not at the end of the list yet. */ + return xstrdup (default_shells[default_index++]); return NULL; } @@ -92,19 +92,19 @@ getusershell (void) { shellstream = fopen (SHELLS_FILE, "r"); if (shellstream == NULL) - { - /* No shells file. Use the default list. */ - default_index = 1; - return xstrdup (default_shells[0]); - } + { + /* No shells file. Use the default list. */ + default_index = 1; + return xstrdup (default_shells[0]); + } } while (readname (&line, &line_size, shellstream)) { if (*line != '#') - return line; + return line; } - return NULL; /* End of file. */ + return NULL; /* End of file. */ } /* Rewind the shells file. */ @@ -150,9 +150,9 @@ readname (char **name, size_t *size, FILE *stream) for (;;) { if (*size <= name_index) - *name = x2nrealloc (*name, size, sizeof **name); + *name = x2nrealloc (*name, size, sizeof **name); if (c == EOF || isspace (c)) - break; + break; (*name)[name_index++] = c; c = getc (stream); } diff --git a/lib/git-merge-changelog.c b/lib/git-merge-changelog.c index a199f32d5..2affd9f1d 100644 --- a/lib/git-merge-changelog.c +++ b/lib/git-merge-changelog.c @@ -143,11 +143,11 @@ #include "fwriteerror.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - abort (); \ - } \ + do \ + { \ + if (!(expr)) \ + abort (); \ + } \ while (0) #define FSTRCMP_THRESHOLD 0.6 @@ -185,7 +185,7 @@ entry_equals (const void *elt1, const void *elt2) const struct entry *entry1 = (const struct entry *) elt1; const struct entry *entry2 = (const struct entry *) elt2; return entry1->length == entry2->length - && memcmp (entry1->string, entry2->string, entry1->length) == 0; + && memcmp (entry1->string, entry2->string, entry1->length) == 0; } /* Return a hash code of the contents of a ChangeLog entry. */ @@ -201,7 +201,7 @@ entry_hashcode (const void *elt) size_t h = 0; for (s = entry->string, n = entry->length; n > 0; s++, n--) - h = (unsigned char) *s + ((h << 9) | (h >> (sizeof (size_t) * CHAR_BIT - 9))); + h = (unsigned char) *s + ((h << 9) | (h >> (sizeof (size_t) * CHAR_BIT - 9))); entry->hashcode = h; entry->hashcode_cached = true; @@ -216,7 +216,7 @@ entry_hashcode (const void *elt) be returned. */ static double entry_fstrcmp (const struct entry *entry1, const struct entry *entry2, - double lower_bound) + double lower_bound) { /* fstrcmp works only on NUL terminated strings. */ char *memory; @@ -272,10 +272,10 @@ read_changelog_file (const char *filename, struct changelog_file *result) result->entries_list = gl_list_create_empty (GL_LINKEDHASH_LIST, entry_equals, entry_hashcode, - NULL, true); + NULL, true); result->entries_reversed = gl_list_create_empty (GL_RBTREEHASH_LIST, entry_equals, entry_hashcode, - NULL, true); + NULL, true); /* A ChangeLog file consists of ChangeLog entries. A ChangeLog entry starts at a line following a blank line and that starts with a non-whitespace character, or at the beginning of a file. @@ -285,33 +285,33 @@ read_changelog_file (const char *filename, struct changelog_file *result) char *start = contents; while (start < contents_end) { - /* Search the end of the current entry. */ - char *ptr = start; - struct entry *curr; - - while (ptr < contents_end) - { - ptr = memchr (ptr, '\n', contents_end - ptr); - if (ptr == NULL) - { - ptr = contents_end; - break; - } - ptr++; - if (contents_end - ptr >= 2 - && ptr[0] == '\n' - && !(ptr[1] == '\n' || ptr[1] == '\t' || ptr[1] == ' ')) - { - ptr++; - break; - } - } - - curr = entry_create (start, ptr - start); - gl_list_add_last (result->entries_list, curr); - gl_list_add_first (result->entries_reversed, curr); - - start = ptr; + /* Search the end of the current entry. */ + char *ptr = start; + struct entry *curr; + + while (ptr < contents_end) + { + ptr = memchr (ptr, '\n', contents_end - ptr); + if (ptr == NULL) + { + ptr = contents_end; + break; + } + ptr++; + if (contents_end - ptr >= 2 + && ptr[0] == '\n' + && !(ptr[1] == '\n' || ptr[1] == '\t' || ptr[1] == ' ')) + { + ptr++; + break; + } + } + + curr = entry_create (start, ptr - start); + gl_list_add_last (result->entries_list, curr); + gl_list_add_first (result->entries_reversed, curr); + + start = ptr; } } @@ -363,46 +363,46 @@ entries_mapping_get (struct entries_mapping *mapping, ssize_t i) ssize_t best_j = -1; double best_j_similarity = 0.0; for (j = n2 - 1; j >= 0; j--) - if (mapping->index_mapping_reverse[j] < 0) - { - double similarity = - entry_fstrcmp (entry_i, file2->entries[j], best_j_similarity); - if (similarity > best_j_similarity) - { - best_j = j; - best_j_similarity = similarity; - } - } + if (mapping->index_mapping_reverse[j] < 0) + { + double similarity = + entry_fstrcmp (entry_i, file2->entries[j], best_j_similarity); + if (similarity > best_j_similarity) + { + best_j = j; + best_j_similarity = similarity; + } + } if (best_j_similarity >= FSTRCMP_THRESHOLD) - { - /* Found a similar entry in file2. */ - struct entry *entry_j = file2->entries[best_j]; - /* Search whether it approximately occurs in file1 at index i. */ - ssize_t best_i = -1; - double best_i_similarity = 0.0; - ssize_t ii; - for (ii = n1 - 1; ii >= 0; ii--) - if (mapping->index_mapping[ii] < 0) - { - double similarity = - entry_fstrcmp (file1->entries[ii], entry_j, - best_i_similarity); - if (similarity > best_i_similarity) - { - best_i = ii; - best_i_similarity = similarity; - } - } - if (best_i_similarity >= FSTRCMP_THRESHOLD && best_i == i) - { - mapping->index_mapping[i] = best_j; - mapping->index_mapping_reverse[best_j] = i; - } - } + { + /* Found a similar entry in file2. */ + struct entry *entry_j = file2->entries[best_j]; + /* Search whether it approximately occurs in file1 at index i. */ + ssize_t best_i = -1; + double best_i_similarity = 0.0; + ssize_t ii; + for (ii = n1 - 1; ii >= 0; ii--) + if (mapping->index_mapping[ii] < 0) + { + double similarity = + entry_fstrcmp (file1->entries[ii], entry_j, + best_i_similarity); + if (similarity > best_i_similarity) + { + best_i = ii; + best_i_similarity = similarity; + } + } + if (best_i_similarity >= FSTRCMP_THRESHOLD && best_i == i) + { + mapping->index_mapping[i] = best_j; + mapping->index_mapping_reverse[best_j] = i; + } + } if (mapping->index_mapping[i] < -1) - /* It does not approximately occur in FILE2. - Remember it, for next time. */ - mapping->index_mapping[i] = -1; + /* It does not approximately occur in FILE2. + Remember it, for next time. */ + mapping->index_mapping[i] = -1; } return mapping->index_mapping[i]; } @@ -426,46 +426,46 @@ entries_mapping_reverse_get (struct entries_mapping *mapping, ssize_t j) ssize_t best_i = -1; double best_i_similarity = 0.0; for (i = n1 - 1; i >= 0; i--) - if (mapping->index_mapping[i] < 0) - { - double similarity = - entry_fstrcmp (file1->entries[i], entry_j, best_i_similarity); - if (similarity > best_i_similarity) - { - best_i = i; - best_i_similarity = similarity; - } - } + if (mapping->index_mapping[i] < 0) + { + double similarity = + entry_fstrcmp (file1->entries[i], entry_j, best_i_similarity); + if (similarity > best_i_similarity) + { + best_i = i; + best_i_similarity = similarity; + } + } if (best_i_similarity >= FSTRCMP_THRESHOLD) - { - /* Found a similar entry in file1. */ - struct entry *entry_i = file1->entries[best_i]; - /* Search whether it approximately occurs in file2 at index j. */ - ssize_t best_j = -1; - double best_j_similarity = 0.0; - ssize_t jj; - for (jj = n2 - 1; jj >= 0; jj--) - if (mapping->index_mapping_reverse[jj] < 0) - { - double similarity = - entry_fstrcmp (entry_i, file2->entries[jj], - best_j_similarity); - if (similarity > best_j_similarity) - { - best_j = jj; - best_j_similarity = similarity; - } - } - if (best_j_similarity >= FSTRCMP_THRESHOLD && best_j == j) - { - mapping->index_mapping_reverse[j] = best_i; - mapping->index_mapping[best_i] = j; - } - } + { + /* Found a similar entry in file1. */ + struct entry *entry_i = file1->entries[best_i]; + /* Search whether it approximately occurs in file2 at index j. */ + ssize_t best_j = -1; + double best_j_similarity = 0.0; + ssize_t jj; + for (jj = n2 - 1; jj >= 0; jj--) + if (mapping->index_mapping_reverse[jj] < 0) + { + double similarity = + entry_fstrcmp (entry_i, file2->entries[jj], + best_j_similarity); + if (similarity > best_j_similarity) + { + best_j = jj; + best_j_similarity = similarity; + } + } + if (best_j_similarity >= FSTRCMP_THRESHOLD && best_j == j) + { + mapping->index_mapping_reverse[j] = best_i; + mapping->index_mapping[best_i] = j; + } + } if (mapping->index_mapping_reverse[j] < -1) - /* It does not approximately occur in FILE1. - Remember it, for next time. */ - mapping->index_mapping_reverse[j] = -1; + /* It does not approximately occur in FILE1. + Remember it, for next time. */ + mapping->index_mapping_reverse[j] = -1; } return mapping->index_mapping_reverse[j]; } @@ -480,8 +480,8 @@ entries_mapping_reverse_get (struct entries_mapping *mapping, ssize_t j) Return the result in *RESULT. */ static void compute_mapping (struct changelog_file *file1, struct changelog_file *file2, - bool full, - struct entries_mapping *result) + bool full, + struct entries_mapping *result) { /* Mapping from indices in file1 to indices in file2. */ ssize_t *index_mapping; @@ -503,52 +503,52 @@ compute_mapping (struct changelog_file *file1, struct changelog_file *file2, /* Take an entry from file1. */ if (index_mapping[i] < -1) { - struct entry *entry = file1->entries[i]; - /* Search whether it occurs in file2. */ - j = gl_list_indexof (file2->entries_reversed, entry); - if (j >= 0) - { - j = n2 - 1 - j; - /* Found an exact correspondence. */ - /* If index_mapping_reverse[j] >= 0, we have already seen other - copies of this entry, and there were more occurrences of it in - file1 than in file2. In this case, do nothing. */ - if (index_mapping_reverse[j] < 0) - { - index_mapping[i] = j; - index_mapping_reverse[j] = i; - /* Look for more occurrences of the same entry. Match them - as long as they pair up. Unpaired occurrences of the same - entry are left without mapping. */ - { - ssize_t curr_i = i; - ssize_t curr_j = j; - - for (;;) - { - ssize_t next_i; - ssize_t next_j; - - next_i = - gl_list_indexof_from (file1->entries_reversed, - n1 - curr_i, entry); - if (next_i < 0) - break; - next_j = - gl_list_indexof_from (file2->entries_reversed, - n2 - curr_j, entry); - if (next_j < 0) - break; - curr_i = n1 - 1 - next_i; - curr_j = n2 - 1 - next_j; - ASSERT (index_mapping[curr_i] < 0); - ASSERT (index_mapping_reverse[curr_j] < 0); - index_mapping[curr_i] = curr_j; - index_mapping_reverse[curr_j] = curr_i; - } - } - } - } + struct entry *entry = file1->entries[i]; + /* Search whether it occurs in file2. */ + j = gl_list_indexof (file2->entries_reversed, entry); + if (j >= 0) + { + j = n2 - 1 - j; + /* Found an exact correspondence. */ + /* If index_mapping_reverse[j] >= 0, we have already seen other + copies of this entry, and there were more occurrences of it in + file1 than in file2. In this case, do nothing. */ + if (index_mapping_reverse[j] < 0) + { + index_mapping[i] = j; + index_mapping_reverse[j] = i; + /* Look for more occurrences of the same entry. Match them + as long as they pair up. Unpaired occurrences of the same + entry are left without mapping. */ + { + ssize_t curr_i = i; + ssize_t curr_j = j; + + for (;;) + { + ssize_t next_i; + ssize_t next_j; + + next_i = + gl_list_indexof_from (file1->entries_reversed, + n1 - curr_i, entry); + if (next_i < 0) + break; + next_j = + gl_list_indexof_from (file2->entries_reversed, + n2 - curr_j, entry); + if (next_j < 0) + break; + curr_i = n1 - 1 - next_i; + curr_j = n2 - 1 - next_j; + ASSERT (index_mapping[curr_i] < 0); + ASSERT (index_mapping_reverse[curr_j] < 0); + index_mapping[curr_i] = curr_j; + index_mapping_reverse[curr_j] = curr_i; + } + } + } + } } result->file1 = file1; @@ -580,9 +580,9 @@ struct edit { enum edit_type type; /* Range of indices into the entries of FILE1. */ - ssize_t i1, i2; /* first, last index; only used for CHANGE, REMOVAL */ + ssize_t i1, i2; /* first, last index; only used for CHANGE, REMOVAL */ /* Range of indices into the entries of FILE2. */ - ssize_t j1, j2; /* first, last index; only used for ADDITION, CHANGE */ + ssize_t j1, j2; /* first, last index; only used for ADDITION, CHANGE */ }; /* This structure represents the differences from one file, FILE1, to another @@ -617,7 +617,7 @@ struct differences FILE2. */ static void compute_differences (struct changelog_file *file1, struct changelog_file *file2, - struct differences *result) + struct differences *result) { /* Unlike compute_mapping, which mostly ignores the order of the entries and therefore works well when some entries are permuted, here we use the order. @@ -653,12 +653,12 @@ compute_differences (struct changelog_file *file1, struct changelog_file *file2, while (i < n1 || j < n2) { while (i < n1 && ctxt.index_mapping[i] < 0) - i++; + i++; while (j < n2 && ctxt.index_mapping_reverse[j] < 0) - j++; + j++; ASSERT ((i < n1) == (j < n2)); if (i == n1 && j == n2) - break; + break; ctxt.index_mapping[i] = j; ctxt.index_mapping_reverse[j] = i; i++; @@ -672,85 +672,85 @@ compute_differences (struct changelog_file *file1, struct changelog_file *file2, while (i < n1 || j < n2) { if (i == n1) - { - struct edit *e; - ASSERT (j < n2); - e = XMALLOC (struct edit); - e->type = ADDITION; - e->j1 = j; - e->j2 = n2 - 1; - gl_list_add_last (edits, e); - break; - } + { + struct edit *e; + ASSERT (j < n2); + e = XMALLOC (struct edit); + e->type = ADDITION; + e->j1 = j; + e->j2 = n2 - 1; + gl_list_add_last (edits, e); + break; + } if (j == n2) - { - struct edit *e; - ASSERT (i < n1); - e = XMALLOC (struct edit); - e->type = REMOVAL; - e->i1 = i; - e->i2 = n1 - 1; - gl_list_add_last (edits, e); - break; - } + { + struct edit *e; + ASSERT (i < n1); + e = XMALLOC (struct edit); + e->type = REMOVAL; + e->i1 = i; + e->i2 = n1 - 1; + gl_list_add_last (edits, e); + break; + } if (ctxt.index_mapping[i] >= 0) - { - if (ctxt.index_mapping_reverse[j] >= 0) - { - ASSERT (ctxt.index_mapping[i] == j); - ASSERT (ctxt.index_mapping_reverse[j] == i); - i++; - j++; - } - else - { - struct edit *e; - ASSERT (ctxt.index_mapping_reverse[j] < 0); - e = XMALLOC (struct edit); - e->type = ADDITION; - e->j1 = j; - do - j++; - while (j < n2 && ctxt.index_mapping_reverse[j] < 0); - e->j2 = j - 1; - gl_list_add_last (edits, e); - } - } + { + if (ctxt.index_mapping_reverse[j] >= 0) + { + ASSERT (ctxt.index_mapping[i] == j); + ASSERT (ctxt.index_mapping_reverse[j] == i); + i++; + j++; + } + else + { + struct edit *e; + ASSERT (ctxt.index_mapping_reverse[j] < 0); + e = XMALLOC (struct edit); + e->type = ADDITION; + e->j1 = j; + do + j++; + while (j < n2 && ctxt.index_mapping_reverse[j] < 0); + e->j2 = j - 1; + gl_list_add_last (edits, e); + } + } else - { - if (ctxt.index_mapping_reverse[j] >= 0) - { - struct edit *e; - ASSERT (ctxt.index_mapping[i] < 0); - e = XMALLOC (struct edit); - e->type = REMOVAL; - e->i1 = i; - do - i++; - while (i < n1 && ctxt.index_mapping[i] < 0); - e->i2 = i - 1; - gl_list_add_last (edits, e); - } - else - { - struct edit *e; - ASSERT (ctxt.index_mapping[i] < 0); - ASSERT (ctxt.index_mapping_reverse[j] < 0); - e = XMALLOC (struct edit); - e->type = CHANGE; - e->i1 = i; - do - i++; - while (i < n1 && ctxt.index_mapping[i] < 0); - e->i2 = i - 1; - e->j1 = j; - do - j++; - while (j < n2 && ctxt.index_mapping_reverse[j] < 0); - e->j2 = j - 1; - gl_list_add_last (edits, e); - } - } + { + if (ctxt.index_mapping_reverse[j] >= 0) + { + struct edit *e; + ASSERT (ctxt.index_mapping[i] < 0); + e = XMALLOC (struct edit); + e->type = REMOVAL; + e->i1 = i; + do + i++; + while (i < n1 && ctxt.index_mapping[i] < 0); + e->i2 = i - 1; + gl_list_add_last (edits, e); + } + else + { + struct edit *e; + ASSERT (ctxt.index_mapping[i] < 0); + ASSERT (ctxt.index_mapping_reverse[j] < 0); + e = XMALLOC (struct edit); + e->type = CHANGE; + e->i1 = i; + do + i++; + while (i < n1 && ctxt.index_mapping[i] < 0); + e->i2 = i - 1; + e->j1 = j; + do + j++; + while (j < n2 && ctxt.index_mapping_reverse[j] < 0); + e->j2 = j - 1; + gl_list_add_last (edits, e); + } + } } result->index_mapping = ctxt.index_mapping; @@ -787,10 +787,10 @@ find_paragraph_end (const struct entry *entry, size_t offset) { const char *nl = memchr (string + offset, '\n', length - offset); if (nl == NULL) - return length; + return length; offset = (nl - string) + 1; if (offset < length && string[offset] == '\n') - return offset; + return offset; } } @@ -813,8 +813,8 @@ find_paragraph_end (const struct entry *entry, size_t offset) If the entries don't have this form, it returns false. */ static bool try_split_merged_entry (const struct entry *old_entry, - const struct entry *new_entry, - struct entry *new_split[2]) + const struct entry *new_entry, + struct entry *new_split[2]) { size_t old_title_len = find_paragraph_end (old_entry, 0); size_t new_title_len = find_paragraph_end (new_entry, 0); @@ -826,7 +826,7 @@ try_split_merged_entry (const struct entry *old_entry, /* Same title? */ if (!(old_title_len == new_title_len - && memcmp (old_entry->string, new_entry->string, old_title_len) == 0)) + && memcmp (old_entry->string, new_entry->string, old_title_len) == 0)) return false; old_body.string = old_entry->string + old_title_len; @@ -843,20 +843,20 @@ try_split_merged_entry (const struct entry *old_entry, new_body.string = new_entry->string + split_offset; new_body.length = new_entry->length - split_offset; similarity = - entry_fstrcmp (&old_body, &new_body, best_similarity); + entry_fstrcmp (&old_body, &new_body, best_similarity); if (similarity > best_similarity) - { - best_split_offset = split_offset; - best_similarity = similarity; - } + { + best_split_offset = split_offset; + best_similarity = similarity; + } if (best_similarity == 1.0) - /* It cannot get better. */ - break; + /* It cannot get better. */ + break; if (split_offset < new_entry->length) - split_offset = find_paragraph_end (new_entry, split_offset + 1); + split_offset = find_paragraph_end (new_entry, split_offset + 1); else - break; + break; } /* BODY' should not be empty. */ @@ -935,11 +935,11 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, "Try `%s --help' for more information.\n", - program_name); + program_name); else { printf ("Usage: %s [OPTION] O-FILE-NAME A-FILE-NAME B-FILE-NAME\n", - program_name); + program_name); printf ("\n"); printf ("Merges independent modifications of a ChangeLog style file.\n"); printf ("O-FILE-NAME names the original file, the ancestor of the two others.\n"); @@ -960,7 +960,7 @@ usage (int status) printf (" -V, --version output version information and exit\n"); printf ("\n"); fputs ("Report bugs to .\n", - stdout); + stdout); } exit (status); @@ -986,7 +986,7 @@ main (int argc, char *argv[]) while ((optchar = getopt_long (argc, argv, "hV", long_options, NULL)) != EOF) switch (optchar) { - case '\0': /* Long option. */ + case '\0': /* Long option. */ break; case 'h': do_help = true; @@ -994,7 +994,7 @@ main (int argc, char *argv[]) case 'V': do_version = true; break; - case CHAR_MAX + 1: /* --split-merged-entry */ + case CHAR_MAX + 1: /* --split-merged-entry */ split_merged_entry = true; break; default: @@ -1055,11 +1055,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\ looking at the "upstream" repository. They want to be informed about changes and expect them to be shown at the top of the ChangeLog. When a user pulls downstream, on the other hand, he has two options: - a) He gets the change entries from the central repository also at the - top of his ChangeLog, and his own changes come after them. - b) He gets the change entries from the central repository after those - he has collected for his branch. His own change entries stay at - the top of the ChangeLog file. + a) He gets the change entries from the central repository also at the + top of his ChangeLog, and his own changes come after them. + b) He gets the change entries from the central repository after those + he has collected for his branch. His own change entries stay at + the top of the ChangeLog file. In the case a) he has to reorder the ChangeLog before he can commit. No one does that. So most people want b). In other words, the order of entries in a ChangeLog should represent @@ -1072,9 +1072,9 @@ There is NO WARRANTY, to the extent permitted by law.\n\ branches in a repository and pull from one to another, "git" has no way to know which branch is more "upstream" than the other. The git-tag(1) manual page also says: - "One important aspect of git is it is distributed, and being - distributed largely means there is no inherent "upstream" or - "downstream" in the system." + "One important aspect of git is it is distributed, and being + distributed largely means there is no inherent "upstream" or + "downstream" in the system." Therefore anyone who attempts to produce a ChangeLog from the merge history will fail. @@ -1085,42 +1085,42 @@ There is NO WARRANTY, to the extent permitted by law.\n\ "git pull" only to pull downstream. How to distinguish these situation? There are several hints: - - During a "git stash apply", GIT_REFLOG_ACTION is not set. During - a "git pull", it is set to 'pull '. During a "git pull --rebase", - it is set to 'pull --rebase'. During a "git cherry-pick", it is - set to 'cherry-pick'. - - During a "git stash apply", there is an environment variable of - the form GITHEAD_<40_hex_digits>='Stashed changes'. */ + - During a "git stash apply", GIT_REFLOG_ACTION is not set. During + a "git pull", it is set to 'pull '. During a "git pull --rebase", + it is set to 'pull --rebase'. During a "git cherry-pick", it is + set to 'cherry-pick'. + - During a "git stash apply", there is an environment variable of + the form GITHEAD_<40_hex_digits>='Stashed changes'. */ { const char *var; var = getenv ("GIT_DOWNSTREAM"); if (var != NULL && var[0] != '\0') - downstream = true; + downstream = true; else - { - var = getenv ("GIT_UPSTREAM"); - if (var != NULL && var[0] != '\0') - downstream = false; - else - { - var = getenv ("GIT_REFLOG_ACTION"); - #if 0 /* Debugging code */ - printf ("GIT_REFLOG_ACTION=|%s|\n", var); - #endif - if (var != NULL - && ((strncmp (var, "pull", 4) == 0 - && c_strstr (var, " --rebase") == NULL) - || strncmp (var, "merge origin", 12) == 0)) - downstream = true; - else - { - /* "git stash apply", "git rebase", "git cherry-pick" and - similar. */ - downstream = false; - } - } - } + { + var = getenv ("GIT_UPSTREAM"); + if (var != NULL && var[0] != '\0') + downstream = false; + else + { + var = getenv ("GIT_REFLOG_ACTION"); + #if 0 /* Debugging code */ + printf ("GIT_REFLOG_ACTION=|%s|\n", var); + #endif + if (var != NULL + && ((strncmp (var, "pull", 4) == 0 + && c_strstr (var, " --rebase") == NULL) + || strncmp (var, "merge origin", 12) == 0)) + downstream = true; + else + { + /* "git stash apply", "git rebase", "git cherry-pick" and + similar. */ + downstream = false; + } + } + } } #if 0 /* Debugging code */ @@ -1131,21 +1131,21 @@ There is NO WARRANTY, to the extent permitted by law.\n\ printf ("First line of %%B:\n"); sprintf (buf, "head -1 %s", other_file_name); system (buf); printf ("Guessing calling convention: %s\n", - downstream - ? "%A = modified by user, %B = upstream" - : "%A = upstream, %B = modified by user"); + downstream + ? "%A = modified by user, %B = upstream" + : "%A = upstream, %B = modified by user"); } #endif if (downstream) { - mainstream_file_name = other_file_name; - modified_file_name = destination_file_name; + mainstream_file_name = other_file_name; + modified_file_name = destination_file_name; } else { - mainstream_file_name = destination_file_name; - modified_file_name = other_file_name; + mainstream_file_name = destination_file_name; + modified_file_name = other_file_name; } /* Read the three files into memory. */ @@ -1167,478 +1167,478 @@ There is NO WARRANTY, to the extent permitted by law.\n\ XNMALLOC (mainstream_file.num_entries, gl_list_node_t); result_entries = gl_list_create_empty (GL_LINKED_LIST, entry_equals, entry_hashcode, - NULL, true); + NULL, true); { size_t k; for (k = 0; k < mainstream_file.num_entries; k++) - result_entries_pointers[k] = - gl_list_add_last (result_entries, mainstream_file.entries[k]); + result_entries_pointers[k] = + gl_list_add_last (result_entries, mainstream_file.entries[k]); } result_conflicts = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, true); { size_t e; for (e = 0; e < diffs.num_edits; e++) - { - struct edit *edit = diffs.edits[e]; - switch (edit->type) - { - case ADDITION: - if (edit->j1 == 0) - { - /* An addition to the top of modified_file. - Apply it to the top of mainstream_file. */ - ssize_t j; - for (j = edit->j2; j >= edit->j1; j--) - { - struct entry *added_entry = modified_file.entries[j]; - gl_list_add_first (result_entries, added_entry); - } - } - else - { - ssize_t i_before; - ssize_t i_after; - ssize_t k_before; - ssize_t k_after; - i_before = diffs.index_mapping_reverse[edit->j1 - 1]; - ASSERT (i_before >= 0); - i_after = (edit->j2 + 1 == modified_file.num_entries - ? ancestor_file.num_entries - : diffs.index_mapping_reverse[edit->j2 + 1]); - ASSERT (i_after >= 0); - ASSERT (i_after == i_before + 1); - /* An addition between ancestor_file.entries[i_before] and - ancestor_file.entries[i_after]. See whether these two - entries still exist in mainstream_file and are still - consecutive. */ - k_before = entries_mapping_get (&mapping, i_before); - k_after = (i_after == ancestor_file.num_entries - ? mainstream_file.num_entries - : entries_mapping_get (&mapping, i_after)); - if (k_before >= 0 && k_after >= 0 && k_after == k_before + 1) - { - /* Yes, the entry before and after are still neighbours - in mainstream_file. Apply the addition between - them. */ - if (k_after == mainstream_file.num_entries) - { - size_t j; - for (j = edit->j1; j <= edit->j2; j++) - { - struct entry *added_entry = modified_file.entries[j]; - gl_list_add_last (result_entries, added_entry); - } - } - else - { - gl_list_node_t node_k_after = result_entries_pointers[k_after]; - size_t j; - for (j = edit->j1; j <= edit->j2; j++) - { - struct entry *added_entry = modified_file.entries[j]; - gl_list_add_before (result_entries, node_k_after, added_entry); - } - } - } - else - { - /* It's not clear where the additions should be applied. - Let the user decide. */ - struct conflict *c = XMALLOC (struct conflict); - size_t j; - c->num_old_entries = 0; - c->old_entries = NULL; - c->num_modified_entries = edit->j2 - edit->j1 + 1; - c->modified_entries = - XNMALLOC (c->num_modified_entries, struct entry *); - for (j = edit->j1; j <= edit->j2; j++) - c->modified_entries[j - edit->j1] = modified_file.entries[j]; - gl_list_add_last (result_conflicts, c); - } - } - break; - case REMOVAL: - { - /* Apply the removals one by one. */ - size_t i; - for (i = edit->i1; i <= edit->i2; i++) - { - struct entry *removed_entry = ancestor_file.entries[i]; - ssize_t k = entries_mapping_get (&mapping, i); - if (k >= 0 - && entry_equals (removed_entry, - mainstream_file.entries[k])) - { - /* The entry to be removed still exists in - mainstream_file. Remove it. */ - gl_list_node_set_value (result_entries, - result_entries_pointers[k], - &empty_entry); - } - else - { - /* The entry to be removed was already removed or was - modified. This is a conflict. */ - struct conflict *c = XMALLOC (struct conflict); - c->num_old_entries = 1; - c->old_entries = - XNMALLOC (c->num_old_entries, struct entry *); - c->old_entries[0] = removed_entry; - c->num_modified_entries = 0; - c->modified_entries = NULL; - gl_list_add_last (result_conflicts, c); - } - } - } - break; - case CHANGE: - { - bool done = false; - /* When the user usually merges entries from the same day, - and this edit is at the top of the file: */ - if (split_merged_entry && edit->j1 == 0) - { - /* Test whether the change is "simple merged", i.e. whether - it consists of additions, followed by an augmentation of - the first changed entry, followed by small changes of the - remaining entries: - entry_1 - entry_2 - ... - entry_n - are mapped to - added_entry - ... - added_entry - augmented_entry_1 - modified_entry_2 - ... - modified_entry_n. */ - if (edit->i2 - edit->i1 <= edit->j2 - edit->j1) - { - struct entry *split[2]; - bool simple_merged = - try_split_merged_entry (ancestor_file.entries[edit->i1], - modified_file.entries[edit->i1 + edit->j2 - edit->i2], - split); - if (simple_merged) - { - size_t i; - for (i = edit->i1 + 1; i <= edit->i2; i++) - if (entry_fstrcmp (ancestor_file.entries[i], - modified_file.entries[i + edit->j2 - edit->i2], - FSTRCMP_THRESHOLD) - < FSTRCMP_THRESHOLD) - { - simple_merged = false; - break; - } - } - if (simple_merged) - { - /* Apply the additions at the top of modified_file. - Apply each of the single-entry changes - separately. */ - size_t num_changed = edit->i2 - edit->i1 + 1; /* > 0 */ - size_t num_added = (edit->j2 - edit->j1 + 1) - num_changed; - ssize_t j; - /* First part of the split modified_file.entries[edit->j2 - edit->i2 + edit->i1]: */ - gl_list_add_first (result_entries, split[0]); - /* The additions. */ - for (j = edit->j1 + num_added - 1; j >= edit->j1; j--) - { - struct entry *added_entry = modified_file.entries[j]; - gl_list_add_first (result_entries, added_entry); - } - /* Now the single-entry changes. */ - for (j = edit->j1 + num_added; j <= edit->j2; j++) - { - struct entry *changed_entry = - (j == edit->j1 + num_added - ? split[1] - : modified_file.entries[j]); - size_t i = j + edit->i2 - edit->j2; - ssize_t k = entries_mapping_get (&mapping, i); - if (k >= 0 - && entry_equals (ancestor_file.entries[i], - mainstream_file.entries[k])) - { - gl_list_node_set_value (result_entries, - result_entries_pointers[k], - changed_entry); - } - else if (!entry_equals (ancestor_file.entries[i], - changed_entry)) - { - struct conflict *c = XMALLOC (struct conflict); - c->num_old_entries = 1; - c->old_entries = - XNMALLOC (c->num_old_entries, struct entry *); - c->old_entries[0] = ancestor_file.entries[i]; - c->num_modified_entries = 1; - c->modified_entries = - XNMALLOC (c->num_modified_entries, struct entry *); - c->modified_entries[0] = changed_entry; - gl_list_add_last (result_conflicts, c); - } - } - done = true; - } - } - } - if (!done) - { - bool simple; - /* Test whether the change is "simple", i.e. whether it - consists of small changes to the old ChangeLog entries - and additions before them: - entry_1 - ... - entry_n - are mapped to - added_entry - ... - added_entry - modified_entry_1 - ... - modified_entry_n. */ - if (edit->i2 - edit->i1 <= edit->j2 - edit->j1) - { - size_t i; - simple = true; - for (i = edit->i1; i <= edit->i2; i++) - if (entry_fstrcmp (ancestor_file.entries[i], - modified_file.entries[i + edit->j2 - edit->i2], - FSTRCMP_THRESHOLD) - < FSTRCMP_THRESHOLD) - { - simple = false; - break; - } - } - else - simple = false; - if (simple) - { - /* Apply the additions and each of the single-entry - changes separately. */ - size_t num_changed = edit->i2 - edit->i1 + 1; /* > 0 */ - size_t num_added = (edit->j2 - edit->j1 + 1) - num_changed; - if (edit->j1 == 0) - { - /* A simple change at the top of modified_file. - Apply it to the top of mainstream_file. */ - ssize_t j; - for (j = edit->j1 + num_added - 1; j >= edit->j1; j--) - { - struct entry *added_entry = modified_file.entries[j]; - gl_list_add_first (result_entries, added_entry); - } - for (j = edit->j1 + num_added; j <= edit->j2; j++) - { - struct entry *changed_entry = modified_file.entries[j]; - size_t i = j + edit->i2 - edit->j2; - ssize_t k = entries_mapping_get (&mapping, i); - if (k >= 0 - && entry_equals (ancestor_file.entries[i], - mainstream_file.entries[k])) - { - gl_list_node_set_value (result_entries, - result_entries_pointers[k], - changed_entry); - } - else - { - struct conflict *c; - ASSERT (!entry_equals (ancestor_file.entries[i], - changed_entry)); - c = XMALLOC (struct conflict); - c->num_old_entries = 1; - c->old_entries = - XNMALLOC (c->num_old_entries, struct entry *); - c->old_entries[0] = ancestor_file.entries[i]; - c->num_modified_entries = 1; - c->modified_entries = - XNMALLOC (c->num_modified_entries, struct entry *); - c->modified_entries[0] = changed_entry; - gl_list_add_last (result_conflicts, c); - } - } - done = true; - } - else - { - ssize_t i_before; - ssize_t k_before; - bool linear; - i_before = diffs.index_mapping_reverse[edit->j1 - 1]; - ASSERT (i_before >= 0); - /* A simple change after ancestor_file.entries[i_before]. - See whether this entry and the following num_changed - entries still exist in mainstream_file and are still - consecutive. */ - k_before = entries_mapping_get (&mapping, i_before); - linear = (k_before >= 0); - if (linear) - { - size_t i; - for (i = i_before + 1; i <= i_before + num_changed; i++) - if (entries_mapping_get (&mapping, i) != k_before + (i - i_before)) - { - linear = false; - break; - } - } - if (linear) - { - gl_list_node_t node_for_insert = - result_entries_pointers[k_before + 1]; - ssize_t j; - for (j = edit->j1 + num_added - 1; j >= edit->j1; j--) - { - struct entry *added_entry = modified_file.entries[j]; - gl_list_add_before (result_entries, node_for_insert, added_entry); - } - for (j = edit->j1 + num_added; j <= edit->j2; j++) - { - struct entry *changed_entry = modified_file.entries[j]; - size_t i = j + edit->i2 - edit->j2; - ssize_t k = entries_mapping_get (&mapping, i); - ASSERT (k >= 0); - if (entry_equals (ancestor_file.entries[i], - mainstream_file.entries[k])) - { - gl_list_node_set_value (result_entries, - result_entries_pointers[k], - changed_entry); - } - else - { - struct conflict *c; - ASSERT (!entry_equals (ancestor_file.entries[i], - changed_entry)); - c = XMALLOC (struct conflict); - c->num_old_entries = 1; - c->old_entries = - XNMALLOC (c->num_old_entries, struct entry *); - c->old_entries[0] = ancestor_file.entries[i]; - c->num_modified_entries = 1; - c->modified_entries = - XNMALLOC (c->num_modified_entries, struct entry *); - c->modified_entries[0] = changed_entry; - gl_list_add_last (result_conflicts, c); - } - } - done = true; - } - } - } - else - { - /* A big change. - See whether the num_changed entries still exist - unchanged in mainstream_file and are still - consecutive. */ - ssize_t i_first; - ssize_t k_first; - bool linear_unchanged; - i_first = edit->i1; - k_first = entries_mapping_get (&mapping, i_first); - linear_unchanged = - (k_first >= 0 - && entry_equals (ancestor_file.entries[i_first], - mainstream_file.entries[k_first])); - if (linear_unchanged) - { - size_t i; - for (i = i_first + 1; i <= edit->i2; i++) - if (!(entries_mapping_get (&mapping, i) == k_first + (i - i_first) - && entry_equals (ancestor_file.entries[i], - mainstream_file.entries[entries_mapping_get (&mapping, i)]))) - { - linear_unchanged = false; - break; - } - } - if (linear_unchanged) - { - gl_list_node_t node_for_insert = - result_entries_pointers[k_first]; - ssize_t j; - size_t i; - for (j = edit->j2; j >= edit->j1; j--) - { - struct entry *new_entry = modified_file.entries[j]; - gl_list_add_before (result_entries, node_for_insert, new_entry); - } - for (i = edit->i1; i <= edit->i2; i++) - { - ssize_t k = entries_mapping_get (&mapping, i); - ASSERT (k >= 0); - ASSERT (entry_equals (ancestor_file.entries[i], - mainstream_file.entries[k])); - gl_list_node_set_value (result_entries, - result_entries_pointers[k], - &empty_entry); - } - done = true; - } - } - } - if (!done) - { - struct conflict *c = XMALLOC (struct conflict); - size_t i, j; - c->num_old_entries = edit->i2 - edit->i1 + 1; - c->old_entries = - XNMALLOC (c->num_old_entries, struct entry *); - for (i = edit->i1; i <= edit->i2; i++) - c->old_entries[i - edit->i1] = ancestor_file.entries[i]; - c->num_modified_entries = edit->j2 - edit->j1 + 1; - c->modified_entries = - XNMALLOC (c->num_modified_entries, struct entry *); - for (j = edit->j1; j <= edit->j2; j++) - c->modified_entries[j - edit->j1] = modified_file.entries[j]; - gl_list_add_last (result_conflicts, c); - } - } - break; - } - } + { + struct edit *edit = diffs.edits[e]; + switch (edit->type) + { + case ADDITION: + if (edit->j1 == 0) + { + /* An addition to the top of modified_file. + Apply it to the top of mainstream_file. */ + ssize_t j; + for (j = edit->j2; j >= edit->j1; j--) + { + struct entry *added_entry = modified_file.entries[j]; + gl_list_add_first (result_entries, added_entry); + } + } + else + { + ssize_t i_before; + ssize_t i_after; + ssize_t k_before; + ssize_t k_after; + i_before = diffs.index_mapping_reverse[edit->j1 - 1]; + ASSERT (i_before >= 0); + i_after = (edit->j2 + 1 == modified_file.num_entries + ? ancestor_file.num_entries + : diffs.index_mapping_reverse[edit->j2 + 1]); + ASSERT (i_after >= 0); + ASSERT (i_after == i_before + 1); + /* An addition between ancestor_file.entries[i_before] and + ancestor_file.entries[i_after]. See whether these two + entries still exist in mainstream_file and are still + consecutive. */ + k_before = entries_mapping_get (&mapping, i_before); + k_after = (i_after == ancestor_file.num_entries + ? mainstream_file.num_entries + : entries_mapping_get (&mapping, i_after)); + if (k_before >= 0 && k_after >= 0 && k_after == k_before + 1) + { + /* Yes, the entry before and after are still neighbours + in mainstream_file. Apply the addition between + them. */ + if (k_after == mainstream_file.num_entries) + { + size_t j; + for (j = edit->j1; j <= edit->j2; j++) + { + struct entry *added_entry = modified_file.entries[j]; + gl_list_add_last (result_entries, added_entry); + } + } + else + { + gl_list_node_t node_k_after = result_entries_pointers[k_after]; + size_t j; + for (j = edit->j1; j <= edit->j2; j++) + { + struct entry *added_entry = modified_file.entries[j]; + gl_list_add_before (result_entries, node_k_after, added_entry); + } + } + } + else + { + /* It's not clear where the additions should be applied. + Let the user decide. */ + struct conflict *c = XMALLOC (struct conflict); + size_t j; + c->num_old_entries = 0; + c->old_entries = NULL; + c->num_modified_entries = edit->j2 - edit->j1 + 1; + c->modified_entries = + XNMALLOC (c->num_modified_entries, struct entry *); + for (j = edit->j1; j <= edit->j2; j++) + c->modified_entries[j - edit->j1] = modified_file.entries[j]; + gl_list_add_last (result_conflicts, c); + } + } + break; + case REMOVAL: + { + /* Apply the removals one by one. */ + size_t i; + for (i = edit->i1; i <= edit->i2; i++) + { + struct entry *removed_entry = ancestor_file.entries[i]; + ssize_t k = entries_mapping_get (&mapping, i); + if (k >= 0 + && entry_equals (removed_entry, + mainstream_file.entries[k])) + { + /* The entry to be removed still exists in + mainstream_file. Remove it. */ + gl_list_node_set_value (result_entries, + result_entries_pointers[k], + &empty_entry); + } + else + { + /* The entry to be removed was already removed or was + modified. This is a conflict. */ + struct conflict *c = XMALLOC (struct conflict); + c->num_old_entries = 1; + c->old_entries = + XNMALLOC (c->num_old_entries, struct entry *); + c->old_entries[0] = removed_entry; + c->num_modified_entries = 0; + c->modified_entries = NULL; + gl_list_add_last (result_conflicts, c); + } + } + } + break; + case CHANGE: + { + bool done = false; + /* When the user usually merges entries from the same day, + and this edit is at the top of the file: */ + if (split_merged_entry && edit->j1 == 0) + { + /* Test whether the change is "simple merged", i.e. whether + it consists of additions, followed by an augmentation of + the first changed entry, followed by small changes of the + remaining entries: + entry_1 + entry_2 + ... + entry_n + are mapped to + added_entry + ... + added_entry + augmented_entry_1 + modified_entry_2 + ... + modified_entry_n. */ + if (edit->i2 - edit->i1 <= edit->j2 - edit->j1) + { + struct entry *split[2]; + bool simple_merged = + try_split_merged_entry (ancestor_file.entries[edit->i1], + modified_file.entries[edit->i1 + edit->j2 - edit->i2], + split); + if (simple_merged) + { + size_t i; + for (i = edit->i1 + 1; i <= edit->i2; i++) + if (entry_fstrcmp (ancestor_file.entries[i], + modified_file.entries[i + edit->j2 - edit->i2], + FSTRCMP_THRESHOLD) + < FSTRCMP_THRESHOLD) + { + simple_merged = false; + break; + } + } + if (simple_merged) + { + /* Apply the additions at the top of modified_file. + Apply each of the single-entry changes + separately. */ + size_t num_changed = edit->i2 - edit->i1 + 1; /* > 0 */ + size_t num_added = (edit->j2 - edit->j1 + 1) - num_changed; + ssize_t j; + /* First part of the split modified_file.entries[edit->j2 - edit->i2 + edit->i1]: */ + gl_list_add_first (result_entries, split[0]); + /* The additions. */ + for (j = edit->j1 + num_added - 1; j >= edit->j1; j--) + { + struct entry *added_entry = modified_file.entries[j]; + gl_list_add_first (result_entries, added_entry); + } + /* Now the single-entry changes. */ + for (j = edit->j1 + num_added; j <= edit->j2; j++) + { + struct entry *changed_entry = + (j == edit->j1 + num_added + ? split[1] + : modified_file.entries[j]); + size_t i = j + edit->i2 - edit->j2; + ssize_t k = entries_mapping_get (&mapping, i); + if (k >= 0 + && entry_equals (ancestor_file.entries[i], + mainstream_file.entries[k])) + { + gl_list_node_set_value (result_entries, + result_entries_pointers[k], + changed_entry); + } + else if (!entry_equals (ancestor_file.entries[i], + changed_entry)) + { + struct conflict *c = XMALLOC (struct conflict); + c->num_old_entries = 1; + c->old_entries = + XNMALLOC (c->num_old_entries, struct entry *); + c->old_entries[0] = ancestor_file.entries[i]; + c->num_modified_entries = 1; + c->modified_entries = + XNMALLOC (c->num_modified_entries, struct entry *); + c->modified_entries[0] = changed_entry; + gl_list_add_last (result_conflicts, c); + } + } + done = true; + } + } + } + if (!done) + { + bool simple; + /* Test whether the change is "simple", i.e. whether it + consists of small changes to the old ChangeLog entries + and additions before them: + entry_1 + ... + entry_n + are mapped to + added_entry + ... + added_entry + modified_entry_1 + ... + modified_entry_n. */ + if (edit->i2 - edit->i1 <= edit->j2 - edit->j1) + { + size_t i; + simple = true; + for (i = edit->i1; i <= edit->i2; i++) + if (entry_fstrcmp (ancestor_file.entries[i], + modified_file.entries[i + edit->j2 - edit->i2], + FSTRCMP_THRESHOLD) + < FSTRCMP_THRESHOLD) + { + simple = false; + break; + } + } + else + simple = false; + if (simple) + { + /* Apply the additions and each of the single-entry + changes separately. */ + size_t num_changed = edit->i2 - edit->i1 + 1; /* > 0 */ + size_t num_added = (edit->j2 - edit->j1 + 1) - num_changed; + if (edit->j1 == 0) + { + /* A simple change at the top of modified_file. + Apply it to the top of mainstream_file. */ + ssize_t j; + for (j = edit->j1 + num_added - 1; j >= edit->j1; j--) + { + struct entry *added_entry = modified_file.entries[j]; + gl_list_add_first (result_entries, added_entry); + } + for (j = edit->j1 + num_added; j <= edit->j2; j++) + { + struct entry *changed_entry = modified_file.entries[j]; + size_t i = j + edit->i2 - edit->j2; + ssize_t k = entries_mapping_get (&mapping, i); + if (k >= 0 + && entry_equals (ancestor_file.entries[i], + mainstream_file.entries[k])) + { + gl_list_node_set_value (result_entries, + result_entries_pointers[k], + changed_entry); + } + else + { + struct conflict *c; + ASSERT (!entry_equals (ancestor_file.entries[i], + changed_entry)); + c = XMALLOC (struct conflict); + c->num_old_entries = 1; + c->old_entries = + XNMALLOC (c->num_old_entries, struct entry *); + c->old_entries[0] = ancestor_file.entries[i]; + c->num_modified_entries = 1; + c->modified_entries = + XNMALLOC (c->num_modified_entries, struct entry *); + c->modified_entries[0] = changed_entry; + gl_list_add_last (result_conflicts, c); + } + } + done = true; + } + else + { + ssize_t i_before; + ssize_t k_before; + bool linear; + i_before = diffs.index_mapping_reverse[edit->j1 - 1]; + ASSERT (i_before >= 0); + /* A simple change after ancestor_file.entries[i_before]. + See whether this entry and the following num_changed + entries still exist in mainstream_file and are still + consecutive. */ + k_before = entries_mapping_get (&mapping, i_before); + linear = (k_before >= 0); + if (linear) + { + size_t i; + for (i = i_before + 1; i <= i_before + num_changed; i++) + if (entries_mapping_get (&mapping, i) != k_before + (i - i_before)) + { + linear = false; + break; + } + } + if (linear) + { + gl_list_node_t node_for_insert = + result_entries_pointers[k_before + 1]; + ssize_t j; + for (j = edit->j1 + num_added - 1; j >= edit->j1; j--) + { + struct entry *added_entry = modified_file.entries[j]; + gl_list_add_before (result_entries, node_for_insert, added_entry); + } + for (j = edit->j1 + num_added; j <= edit->j2; j++) + { + struct entry *changed_entry = modified_file.entries[j]; + size_t i = j + edit->i2 - edit->j2; + ssize_t k = entries_mapping_get (&mapping, i); + ASSERT (k >= 0); + if (entry_equals (ancestor_file.entries[i], + mainstream_file.entries[k])) + { + gl_list_node_set_value (result_entries, + result_entries_pointers[k], + changed_entry); + } + else + { + struct conflict *c; + ASSERT (!entry_equals (ancestor_file.entries[i], + changed_entry)); + c = XMALLOC (struct conflict); + c->num_old_entries = 1; + c->old_entries = + XNMALLOC (c->num_old_entries, struct entry *); + c->old_entries[0] = ancestor_file.entries[i]; + c->num_modified_entries = 1; + c->modified_entries = + XNMALLOC (c->num_modified_entries, struct entry *); + c->modified_entries[0] = changed_entry; + gl_list_add_last (result_conflicts, c); + } + } + done = true; + } + } + } + else + { + /* A big change. + See whether the num_changed entries still exist + unchanged in mainstream_file and are still + consecutive. */ + ssize_t i_first; + ssize_t k_first; + bool linear_unchanged; + i_first = edit->i1; + k_first = entries_mapping_get (&mapping, i_first); + linear_unchanged = + (k_first >= 0 + && entry_equals (ancestor_file.entries[i_first], + mainstream_file.entries[k_first])); + if (linear_unchanged) + { + size_t i; + for (i = i_first + 1; i <= edit->i2; i++) + if (!(entries_mapping_get (&mapping, i) == k_first + (i - i_first) + && entry_equals (ancestor_file.entries[i], + mainstream_file.entries[entries_mapping_get (&mapping, i)]))) + { + linear_unchanged = false; + break; + } + } + if (linear_unchanged) + { + gl_list_node_t node_for_insert = + result_entries_pointers[k_first]; + ssize_t j; + size_t i; + for (j = edit->j2; j >= edit->j1; j--) + { + struct entry *new_entry = modified_file.entries[j]; + gl_list_add_before (result_entries, node_for_insert, new_entry); + } + for (i = edit->i1; i <= edit->i2; i++) + { + ssize_t k = entries_mapping_get (&mapping, i); + ASSERT (k >= 0); + ASSERT (entry_equals (ancestor_file.entries[i], + mainstream_file.entries[k])); + gl_list_node_set_value (result_entries, + result_entries_pointers[k], + &empty_entry); + } + done = true; + } + } + } + if (!done) + { + struct conflict *c = XMALLOC (struct conflict); + size_t i, j; + c->num_old_entries = edit->i2 - edit->i1 + 1; + c->old_entries = + XNMALLOC (c->num_old_entries, struct entry *); + for (i = edit->i1; i <= edit->i2; i++) + c->old_entries[i - edit->i1] = ancestor_file.entries[i]; + c->num_modified_entries = edit->j2 - edit->j1 + 1; + c->modified_entries = + XNMALLOC (c->num_modified_entries, struct entry *); + for (j = edit->j1; j <= edit->j2; j++) + c->modified_entries[j - edit->j1] = modified_file.entries[j]; + gl_list_add_last (result_conflicts, c); + } + } + break; + } + } } /* Output the result. */ { FILE *fp = fopen (destination_file_name, "w"); if (fp == NULL) - { - fprintf (stderr, "could not write file '%s'\n", destination_file_name); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "could not write file '%s'\n", destination_file_name); + exit (EXIT_FAILURE); + } /* Output the conflicts at the top. */ { - size_t n = gl_list_size (result_conflicts); - size_t i; - for (i = 0; i < n; i++) - conflict_write (fp, (struct conflict *) gl_list_get_at (result_conflicts, i)); + size_t n = gl_list_size (result_conflicts); + size_t i; + for (i = 0; i < n; i++) + conflict_write (fp, (struct conflict *) gl_list_get_at (result_conflicts, i)); } /* Output the modified and unmodified entries, in order. */ { - gl_list_iterator_t iter = gl_list_iterator (result_entries); - const void *elt; - gl_list_node_t node; - while (gl_list_iterator_next (&iter, &elt, &node)) - entry_write (fp, (struct entry *) elt); - gl_list_iterator_free (&iter); + gl_list_iterator_t iter = gl_list_iterator (result_entries); + const void *elt; + gl_list_node_t node; + while (gl_list_iterator_next (&iter, &elt, &node)) + entry_write (fp, (struct entry *) elt); + gl_list_iterator_free (&iter); } if (fwriteerror (fp)) - { - fprintf (stderr, "error writing to file '%s'\n", destination_file_name); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "error writing to file '%s'\n", destination_file_name); + exit (EXIT_FAILURE); + } } exit (gl_list_size (result_conflicts) > 0 ? EXIT_FAILURE : EXIT_SUCCESS); diff --git a/lib/gl_anyavltree_list1.h b/lib/gl_anyavltree_list1.h index 980517d3d..e71fa845c 100644 --- a/lib/gl_anyavltree_list1.h +++ b/lib/gl_anyavltree_list1.h @@ -19,9 +19,9 @@ /* 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)). + 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. + | 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 @@ -44,9 +44,9 @@ struct gl_list_node_impl gl_list_add_before, gl_list_add_after can be implemented. */ struct gl_list_node_impl *parent; int balance; /* heightof(right) - heightof(left), - always = -1 or 0 or 1 */ + always = -1 or 0 or 1 */ size_t branch_size; /* number of nodes in this branch, - = branchsize(left)+branchsize(right)+1 */ + = branchsize(left)+branchsize(right)+1 */ const void *value; }; diff --git a/lib/gl_anyavltree_list2.h b/lib/gl_anyavltree_list2.h index f468688ee..1ae6df84b 100644 --- a/lib/gl_anyavltree_list2.h +++ b/lib/gl_anyavltree_list2.h @@ -60,11 +60,11 @@ create_subtree_with_contents (size_t count, const void **contents) static gl_list_t gl_tree_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_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 = XMALLOC (struct gl_list_impl); @@ -89,7 +89,7 @@ gl_tree_create (gl_list_implementation_t implementation, #if WITH_HASHTABLE /* Now that the tree is built, node_position() works. Now we can - add the nodes to the hash table. */ + add the nodes to the hash table. */ add_nodes_to_buckets (list); #endif } @@ -105,7 +105,7 @@ gl_tree_create (gl_list_implementation_t implementation, Rotation operations are performed starting at PARENT (not NODE itself!). */ static void rebalance (gl_list_t list, - gl_list_node_t node, int height_diff, gl_list_node_t parent) + gl_list_node_t node, int height_diff, gl_list_node_t parent) { for (;;) { @@ -121,250 +121,250 @@ rebalance (gl_list_t list, 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. */ + 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); + 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; + /* 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_list_node_t *nodep; - - if (node->parent == NULL) - /* node == list->root */ - nodep = &list->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_list_node_t nodeleftleft = nodeleft->left; - gl_list_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; - - node->branch_size = - (nodeleftright != NULL ? nodeleftright->branch_size : 0) - + 1 + (noderight != NULL ? noderight->branch_size : 0); - nodeleft->branch_size = - nodeleftleft->branch_size + 1 + node->branch_size; - - *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_list_node_t L = nodeleft->right = nodeleftright->left; - gl_list_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; - - nodeleft->branch_size = - (nodeleft->left != NULL ? nodeleft->left->branch_size : 0) - + 1 + (nodeleft->right != NULL ? nodeleft->right->branch_size : 0); - node->branch_size = - (node->left != NULL ? node->left->branch_size : 0) - + 1 + (node->right != NULL ? node->right->branch_size : 0); - nodeleftright->branch_size = - nodeleft->branch_size + 1 + node->branch_size; - - *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_list_node_t noderightleft = noderight->left; - gl_list_node_t noderightright = noderight->right; - 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; - - node->branch_size = - (nodeleft != NULL ? nodeleft->branch_size : 0) - + 1 + (noderightleft != NULL ? noderightleft->branch_size : 0); - noderight->branch_size = - node->branch_size + 1 + noderightright->branch_size; - - *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_list_node_t L = node->right = noderightleft->left; - gl_list_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; - - node->branch_size = - (node->left != NULL ? node->left->branch_size : 0) - + 1 + (node->right != NULL ? node->right->branch_size : 0); - noderight->branch_size = - (noderight->left != NULL ? noderight->left->branch_size : 0) - + 1 + (noderight->right != NULL ? noderight->right->branch_size : 0); - noderightleft->branch_size = - node->branch_size + 1 + noderight->branch_size; - - *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; - } + { + /* node->balance is outside the range [-1,1]. Must rotate. */ + gl_list_node_t *nodep; + + if (node->parent == NULL) + /* node == list->root */ + nodep = &list->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_list_node_t nodeleftleft = nodeleft->left; + gl_list_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; + + node->branch_size = + (nodeleftright != NULL ? nodeleftright->branch_size : 0) + + 1 + (noderight != NULL ? noderight->branch_size : 0); + nodeleft->branch_size = + nodeleftleft->branch_size + 1 + node->branch_size; + + *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_list_node_t L = nodeleft->right = nodeleftright->left; + gl_list_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; + + nodeleft->branch_size = + (nodeleft->left != NULL ? nodeleft->left->branch_size : 0) + + 1 + (nodeleft->right != NULL ? nodeleft->right->branch_size : 0); + node->branch_size = + (node->left != NULL ? node->left->branch_size : 0) + + 1 + (node->right != NULL ? node->right->branch_size : 0); + nodeleftright->branch_size = + nodeleft->branch_size + 1 + node->branch_size; + + *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_list_node_t noderightleft = noderight->left; + gl_list_node_t noderightright = noderight->right; + 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; + + node->branch_size = + (nodeleft != NULL ? nodeleft->branch_size : 0) + + 1 + (noderightleft != NULL ? noderightleft->branch_size : 0); + noderight->branch_size = + node->branch_size + 1 + noderightright->branch_size; + + *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_list_node_t L = node->right = noderightleft->left; + gl_list_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; + + node->branch_size = + (node->left != NULL ? node->left->branch_size : 0) + + 1 + (node->right != NULL ? node->right->branch_size : 0); + noderight->branch_size = + (noderight->left != NULL ? noderight->left->branch_size : 0) + + 1 + (noderight->right != NULL ? noderight->right->branch_size : 0); + noderightleft->branch_size = + node->branch_size + 1 + noderight->branch_size; + + *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); - } + { + /* 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; + break; parent = node->parent; if (parent == NULL) - break; + break; } } @@ -397,7 +397,7 @@ gl_tree_add_first (gl_list_t list, const void *elt) gl_list_node_t node; for (node = list->root; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; new_node->parent = node; @@ -405,15 +405,15 @@ gl_tree_add_first (gl_list_t list, const void *elt) /* Update branch_size fields of the parent nodes. */ { - gl_list_node_t p; + gl_list_node_t p; - for (p = node; p != NULL; p = p->parent) - p->branch_size++; + for (p = node; p != NULL; p = p->parent) + p->branch_size++; } /* Rebalance. */ if (node->right == NULL && node->parent != NULL) - rebalance (list, node, 1, node->parent); + rebalance (list, node, 1, node->parent); } #if WITH_HASHTABLE @@ -456,7 +456,7 @@ gl_tree_add_last (gl_list_t list, const void *elt) gl_list_node_t node; for (node = list->root; node->right != NULL; ) - node = node->right; + node = node->right; node->right = new_node; new_node->parent = node; @@ -464,15 +464,15 @@ gl_tree_add_last (gl_list_t list, const void *elt) /* Update branch_size fields of the parent nodes. */ { - gl_list_node_t p; + gl_list_node_t p; - for (p = node; p != NULL; p = p->parent) - p->branch_size++; + for (p = node; p != NULL; p = p->parent) + p->branch_size++; } /* Rebalance. */ if (node->left == NULL && node->parent != NULL) - rebalance (list, node, 1, node->parent); + rebalance (list, node, 1, node->parent); } #if WITH_HASHTABLE @@ -515,7 +515,7 @@ gl_tree_add_before (gl_list_t list, gl_list_node_t node, const void *elt) else { for (node = node->left; node->right != NULL; ) - node = node->right; + node = node->right; node->right = new_node; node->balance++; height_inc = (node->left == NULL); @@ -574,7 +574,7 @@ gl_tree_add_after (gl_list_t list, gl_list_node_t node, const void *elt) else { for (node = node->right; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; node->balance--; height_inc = (node->right == NULL); @@ -624,54 +624,54 @@ gl_tree_remove_node (gl_list_t list, gl_list_node_t node) gl_list_node_t child = node->right; if (child != NULL) - child->parent = parent; + child->parent = parent; if (parent == NULL) - list->root = child; + list->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - /* Update branch_size fields of the parent nodes. */ - { - gl_list_node_t p; - - for (p = parent; p != NULL; p = p->parent) - p->branch_size--; - } - - rebalance (list, child, -1, parent); - } + { + if (parent->left == node) + parent->left = child; + else /* parent->right == node */ + parent->right = child; + + /* Update branch_size fields of the parent nodes. */ + { + gl_list_node_t p; + + for (p = parent; p != NULL; p = p->parent) + p->branch_size--; + } + + rebalance (list, 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. */ + general case below is more complicated, hence slower. */ /* Replace node with node->left. */ gl_list_node_t child = node->left; child->parent = parent; if (parent == NULL) - list->root = child; + list->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - /* Update branch_size fields of the parent nodes. */ - { - gl_list_node_t p; - - for (p = parent; p != NULL; p = p->parent) - p->branch_size--; - } - - rebalance (list, child, -1, parent); - } + { + if (parent->left == node) + parent->left = child; + else /* parent->right == node */ + parent->right = child; + + /* Update branch_size fields of the parent nodes. */ + { + gl_list_node_t p; + + for (p = parent; p != NULL; p = p->parent) + p->branch_size--; + } + + rebalance (list, child, -1, parent); + } } else { @@ -681,61 +681,61 @@ gl_tree_remove_node (gl_list_t list, gl_list_node_t node) gl_list_node_t child; for (subst = node->left; subst->right != NULL; ) - subst = subst->right; + 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. */ + 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; - } + { + if (child != NULL) + child->parent = subst_parent; + subst_parent->right = child; + } /* Update branch_size fields of the parent nodes. */ { - gl_list_node_t p; + gl_list_node_t p; - for (p = subst_parent; p != NULL; p = p->parent) - p->branch_size--; + for (p = subst_parent; p != NULL; p = p->parent) + p->branch_size--; } /* Copy subst into node's position. - (This is safer than to copy subst's value into node, keep node in - place, and free subst.) */ + (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->left = node->left; + subst->left->parent = subst; + } subst->right = node->right; subst->right->parent = subst; subst->balance = node->balance; subst->branch_size = node->branch_size; subst->parent = parent; if (parent == NULL) - list->root = subst; + list->root = subst; else if (parent->left == node) - parent->left = subst; + parent->left = subst; else /* parent->right == node */ - parent->right = subst; + 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. */ + except when subst_parent == node. In this case, we need to use + its replacement, subst. */ rebalance (list, child, -1, subst_parent != node ? subst_parent : subst); } diff --git a/lib/gl_anyhash_list2.h b/lib/gl_anyhash_list2.h index 2ac0cdae9..03640f4cb 100644 --- a/lib/gl_anyhash_list2.h +++ b/lib/gl_anyhash_list2.h @@ -104,20 +104,20 @@ hash_resize (gl_list_t list, size_t estimate) /* Iterate through the entries of the old table. */ for (i = list->table_size; i > 0; ) - { - gl_hash_entry_t node = old_table[--i]; + { + 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; + 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; - } - } + node = next; + } + } list->table = new_table; list->table_size = new_size; diff --git a/lib/gl_anylinked_list2.h b/lib/gl_anylinked_list2.h index 9fbe5a879..7c7b7e37c 100644 --- a/lib/gl_anylinked_list2.h +++ b/lib/gl_anylinked_list2.h @@ -38,10 +38,10 @@ static gl_list_t gl_linked_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_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 = XMALLOC (struct gl_list_impl); @@ -63,11 +63,11 @@ gl_linked_create_empty (gl_list_implementation_t implementation, static gl_list_t gl_linked_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_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 = XMALLOC (struct gl_list_impl); gl_list_node_t tail; @@ -95,9 +95,9 @@ gl_linked_create (gl_list_implementation_t implementation, 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); + (list->base.hashcode_fn != NULL + ? list->base.hashcode_fn (node->value) + : (size_t)(uintptr_t) node->value); /* Add node to the hash table. */ add_to_bucket (list, node); @@ -133,19 +133,19 @@ gl_linked_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt) if (elt != node->value) { size_t new_hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + (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; - add_to_bucket (list, node); - } + { + remove_from_bucket (list, node); + node->value = elt; + node->h.hashcode = new_hashcode; + add_to_bucket (list, node); + } else - node->value = elt; + node->value = elt; } #else node->value = elt; @@ -178,14 +178,14 @@ gl_linked_get_at (gl_list_t list, size_t position) { node = list->root.next; for (; position > 0; position--) - node = node->next; + node = node->next; } else { position = count - 1 - position; node = list->root.prev; for (; position > 0; position--) - node = node->prev; + node = node->prev; } return node->value; } @@ -204,32 +204,32 @@ gl_linked_set_at (gl_list_t list, size_t position, const void *elt) { node = list->root.next; for (; position > 0; position--) - node = node->next; + node = node->next; } else { position = count - 1 - position; node = list->root.prev; for (; position > 0; position--) - node = node->prev; + 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); + (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; - add_to_bucket (list, node); - } + { + remove_from_bucket (list, node); + node->value = elt; + node->h.hashcode = new_hashcode; + add_to_bucket (list, node); + } else - node->value = elt; + node->value = elt; } #else node->value = elt; @@ -239,7 +239,7 @@ gl_linked_set_at (gl_list_t list, size_t position, const void *elt) 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) + const void *elt) { size_t count = list->count; @@ -257,113 +257,113 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index, 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; + /* 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; - } + /* 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; @@ -375,15 +375,15 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index, if (equals != NULL) { - for (; end_index > 0; node = node->next, end_index--) - if (equals (elt, node->value)) - return node; + 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; + for (; end_index > 0; node = node->next, end_index--) + if (elt == node->value) + return node; } return NULL; #endif @@ -392,7 +392,7 @@ gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index, static size_t gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { size_t count = list->count; @@ -415,62 +415,62 @@ gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, /* 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; + /* 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; + /* 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. */ @@ -478,15 +478,15 @@ gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, return (size_t)(-1); else { - size_t index = 0; + size_t index = 0; - for (; node->prev != &list->root; node = node->prev) - index++; + for (; node->prev != &list->root; node = node->prev) + index++; - if (index >= start_index && index < end_index) - return index; - else - return (size_t)(-1); + if (index >= start_index && index < end_index) + return index; + else + return (size_t)(-1); } #else gl_listelement_equals_fn equals = list->base.equals_fn; @@ -498,19 +498,19 @@ gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, if (equals != NULL) { - for (; - index < end_index; - node = node->next, index++) - if (equals (elt, node->value)) - return index; + 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; + for (; + index < end_index; + node = node->next, index++) + if (elt == node->value) + return index; } return (size_t)(-1); #endif @@ -666,7 +666,7 @@ gl_linked_add_at (gl_list_t list, size_t position, const void *elt) node = &list->root; for (; position > 0; position--) - node = node->next; + node = node->next; new_node->prev = node; ASYNCSAFE(gl_list_node_t) new_node->next = node->next; new_node->next->prev = new_node; @@ -679,7 +679,7 @@ gl_linked_add_at (gl_list_t list, size_t position, const void *elt) position = count - position; node = &list->root; for (; position > 0; position--) - node = node->prev; + 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; @@ -736,7 +736,7 @@ gl_linked_remove_at (gl_list_t list, size_t position) node = &list->root; for (; position > 0; position--) - node = node->next; + node = node->next; removed_node = node->next; after_removed = node->next->next; ASYNCSAFE(gl_list_node_t) node->next = after_removed; @@ -750,7 +750,7 @@ gl_linked_remove_at (gl_list_t list, size_t position) position = count - 1 - position; node = &list->root; for (; position > 0; position--) - node = node->prev; + node = node->prev; removed_node = node->prev; before_removed = node->prev->prev; node->prev = before_removed; @@ -788,7 +788,7 @@ gl_linked_list_free (gl_list_t list) { gl_list_node_t next = node->next; if (dispose != NULL) - dispose (node->value); + dispose (node->value); free (node); node = next; } @@ -820,7 +820,7 @@ gl_linked_iterator (gl_list_t list) static gl_list_iterator_t gl_linked_iterator_from_to (gl_list_t list, - size_t start_index, size_t end_index) + size_t start_index, size_t end_index) { gl_list_iterator_t result; size_t n1, n2, n3; @@ -843,10 +843,10 @@ gl_linked_iterator_from_to (gl_list_t list, node = &list->root; for (i = n3; i > 0; i--) - node = node->prev; + node = node->prev; result.q = node; for (i = n2; i > 0; i--) - node = node->prev; + node = node->prev; result.p = node; } else if (n2 > n3) @@ -857,12 +857,12 @@ gl_linked_iterator_from_to (gl_list_t list, node = list->root.next; for (i = n1; i > 0; i--) - node = node->next; + node = node->next; result.p = node; node = &list->root; for (i = n3; i > 0; i--) - node = node->prev; + node = node->prev; result.q = node; } else @@ -873,10 +873,10 @@ gl_linked_iterator_from_to (gl_list_t list, node = list->root.next; for (i = n1; i > 0; i--) - node = node->next; + node = node->next; result.p = node; for (i = n2; i > 0; i--) - node = node->next; + node = node->next; result.q = node; } @@ -891,14 +891,14 @@ gl_linked_iterator_from_to (gl_list_t list, static bool gl_linked_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) + 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; + *nodep = node; iterator->p = node->next; return true; } @@ -915,7 +915,7 @@ gl_linked_iterator_free (gl_list_iterator_t *iterator) static gl_list_node_t gl_linked_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node; @@ -924,18 +924,18 @@ gl_linked_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, int cmp = compar (node->value, elt); if (cmp > 0) - break; + break; if (cmp == 0) - return node; + 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) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { size_t count = list->count; @@ -951,29 +951,29 @@ gl_linked_sortedlist_search_from_to (gl_list_t list, gl_list_node_t node; if (position <= ((count - 1) / 2)) - { - node = list->root.next; - for (; position > 0; position--) - node = node->next; - } + { + 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; - } + { + 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; - } + { + int cmp = compar (node->value, elt); + + if (cmp > 0) + break; + if (cmp == 0) + return node; + node = node->next; + } while (--high > 0); } return NULL; @@ -981,7 +981,7 @@ gl_linked_sortedlist_search_from_to (gl_list_t list, static size_t gl_linked_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node; size_t index; @@ -993,18 +993,18 @@ gl_linked_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, int cmp = compar (node->value, elt); if (cmp > 0) - break; + break; if (cmp == 0) - return index; + 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) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { size_t count = list->count; @@ -1021,30 +1021,30 @@ gl_linked_sortedlist_indexof_from_to (gl_list_t list, gl_list_node_t node; if (position <= ((count - 1) / 2)) - { - node = list->root.next; - for (; position > 0; position--) - node = node->next; - } + { + 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; - } + { + 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++; - } + { + 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); @@ -1052,7 +1052,7 @@ gl_linked_sortedlist_indexof_from_to (gl_list_t list, static gl_list_node_t gl_linked_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node; @@ -1064,7 +1064,7 @@ gl_linked_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, static bool gl_linked_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node; @@ -1073,9 +1073,9 @@ gl_linked_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, int cmp = compar (node->value, elt); if (cmp > 0) - break; + break; if (cmp == 0) - return gl_linked_remove_node (list, node); + return gl_linked_remove_node (list, node); } return false; } diff --git a/lib/gl_anyrbtree_list1.h b/lib/gl_anyrbtree_list1.h index fcd1474ea..782227d36 100644 --- a/lib/gl_anyrbtree_list1.h +++ b/lib/gl_anyrbtree_list1.h @@ -51,7 +51,7 @@ struct gl_list_node_impl struct gl_list_node_impl *parent; color_t color; /* node's color */ size_t branch_size; /* number of nodes in this branch, - = branchsize(left)+branchsize(right)+1 */ + = branchsize(left)+branchsize(right)+1 */ const void *value; }; diff --git a/lib/gl_anyrbtree_list2.h b/lib/gl_anyrbtree_list2.h index 09e8421a9..4f6a91219 100644 --- a/lib/gl_anyrbtree_list2.h +++ b/lib/gl_anyrbtree_list2.h @@ -25,7 +25,7 @@ Its height is h where 2^(h-1) <= count <= 2^h - 1. */ static gl_list_node_t create_subtree_with_contents (unsigned int bh, - size_t count, const void **contents) + size_t count, const void **contents) { size_t half1 = (count - 1) / 2; size_t half2 = count / 2; @@ -35,9 +35,9 @@ create_subtree_with_contents (unsigned int bh, if (half1 > 0) { /* half1 > 0 implies count > 1, implies bh >= 1, implies - 2^(bh-1) - 1 <= half1 <= 2^bh - 1. */ + 2^(bh-1) - 1 <= half1 <= 2^bh - 1. */ node->left = - create_subtree_with_contents (bh - 1, half1, contents); + create_subtree_with_contents (bh - 1, half1, contents); node->left->parent = node; } else @@ -48,7 +48,7 @@ create_subtree_with_contents (unsigned int bh, if (half2 > 0) { /* half2 > 0 implies count > 1, implies bh >= 1, implies - 2^(bh-1) - 1 <= half2 <= 2^bh - 1. */ + 2^(bh-1) - 1 <= half2 <= 2^bh - 1. */ node->right = create_subtree_with_contents (bh - 1, half2, contents + half1 + 1); node->right->parent = node; @@ -65,11 +65,11 @@ create_subtree_with_contents (unsigned int bh, static gl_list_t gl_tree_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_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 = XMALLOC (struct gl_list_impl); @@ -90,13 +90,13 @@ gl_tree_create (gl_list_implementation_t implementation, if (count > 0) { /* Assuming 2^bh - 1 <= count <= 2^(bh+1) - 2, we create a tree whose - upper bh levels are black, and only the partially present lowest - level is red. */ + upper bh levels are black, and only the partially present lowest + level is red. */ unsigned int bh; { - size_t n; - for (n = count + 1, bh = 0; n > 1; n = n >> 1) - bh++; + size_t n; + for (n = count + 1, bh = 0; n > 1; n = n >> 1) + bh++; } list->root = create_subtree_with_contents (bh, count, contents); @@ -104,7 +104,7 @@ gl_tree_create (gl_list_implementation_t implementation, #if WITH_HASHTABLE /* Now that the tree is built, node_position() works. Now we can - add the nodes to the hash table. */ + add the nodes to the hash table. */ add_nodes_to_buckets (list); #endif } @@ -116,11 +116,11 @@ gl_tree_create (gl_list_implementation_t implementation, /* Rotate left a subtree. - B D - / \ / \ - A D --> B E - / \ / \ - C E A C + B D + / \ / \ + A D --> B E + / \ / \ + C E A C Change the tree structure, update the branch sizes. The caller must update the colors and register D as child of its parent. */ @@ -150,11 +150,11 @@ rotate_left (gl_list_node_t b_node, gl_list_node_t d_node) /* Rotate right a subtree. - D B - / \ / \ - B E --> A D - / \ / \ - A C C E + D B + / \ / \ + B E --> A D + / \ / \ + A C C E Change the tree structure, update the branch sizes. The caller must update the colors and register B as child of its parent. */ @@ -191,118 +191,118 @@ rebalance_after_add (gl_list_t list, gl_list_node_t node, gl_list_node_t parent) for (;;) { /* At this point, parent = node->parent != NULL. - Think of node->color being RED (although node->color is not yet - assigned.) */ + Think of node->color being RED (although node->color is not yet + assigned.) */ gl_list_node_t grandparent; gl_list_node_t uncle; if (parent->color == BLACK) - { - /* A RED color for node is acceptable. */ - node->color = RED; - return; - } + { + /* A RED color for node is acceptable. */ + node->color = RED; + return; + } grandparent = parent->parent; /* Since parent is RED, we know that - grandparent is != NULL and colored BLACK. */ + grandparent is != NULL and colored BLACK. */ if (grandparent->left == parent) - uncle = grandparent->right; + uncle = grandparent->right; else if (grandparent->right == parent) - uncle = grandparent->left; + uncle = grandparent->left; else - abort (); + abort (); if (uncle != NULL && uncle->color == RED) - { - /* Change grandparent from BLACK to RED, and - change parent and uncle from RED to BLACK. - This makes it acceptable for node to be RED. */ - node->color = RED; - parent->color = uncle->color = BLACK; - node = grandparent; - } + { + /* Change grandparent from BLACK to RED, and + change parent and uncle from RED to BLACK. + This makes it acceptable for node to be RED. */ + node->color = RED; + parent->color = uncle->color = BLACK; + node = grandparent; + } else - { - /* grandparent and uncle are BLACK. parent is RED. node wants - to be RED too. - In this case, recoloring is not sufficient. Need to perform - one or two rotations. */ - gl_list_node_t *grandparentp; - - if (grandparent->parent == NULL) - grandparentp = &list->root; - else if (grandparent->parent->left == grandparent) - grandparentp = &grandparent->parent->left; - else if (grandparent->parent->right == grandparent) - grandparentp = &grandparent->parent->right; - else - abort (); - - if (grandparent->left == parent) - { - if (parent->right == node) - { - /* Rotation between node and parent. */ - grandparent->left = rotate_left (parent, node); - node = parent; - parent = grandparent->left; - } - /* grandparent and uncle are BLACK. parent and node want to be - RED. parent = grandparent->left. node = parent->left. - - grandparent parent - bh+1 bh+1 - / \ / \ - parent uncle --> node grandparent - bh bh bh bh - / \ / \ - node C C uncle - bh bh bh bh - */ - *grandparentp = rotate_right (parent, grandparent); - parent->color = BLACK; - node->color = grandparent->color = RED; - } - else /* grandparent->right == parent */ - { - if (parent->left == node) - { - /* Rotation between node and parent. */ - grandparent->right = rotate_right (node, parent); - node = parent; - parent = grandparent->right; - } - /* grandparent and uncle are BLACK. parent and node want to be - RED. parent = grandparent->right. node = parent->right. - - grandparent parent - bh+1 bh+1 - / \ / \ - uncle parent --> grandparent node - bh bh bh bh - / \ / \ - C node uncle C - bh bh bh bh - */ - *grandparentp = rotate_left (grandparent, parent); - parent->color = BLACK; - node->color = grandparent->color = RED; - } - return; - } + { + /* grandparent and uncle are BLACK. parent is RED. node wants + to be RED too. + In this case, recoloring is not sufficient. Need to perform + one or two rotations. */ + gl_list_node_t *grandparentp; + + if (grandparent->parent == NULL) + grandparentp = &list->root; + else if (grandparent->parent->left == grandparent) + grandparentp = &grandparent->parent->left; + else if (grandparent->parent->right == grandparent) + grandparentp = &grandparent->parent->right; + else + abort (); + + if (grandparent->left == parent) + { + if (parent->right == node) + { + /* Rotation between node and parent. */ + grandparent->left = rotate_left (parent, node); + node = parent; + parent = grandparent->left; + } + /* grandparent and uncle are BLACK. parent and node want to be + RED. parent = grandparent->left. node = parent->left. + + grandparent parent + bh+1 bh+1 + / \ / \ + parent uncle --> node grandparent + bh bh bh bh + / \ / \ + node C C uncle + bh bh bh bh + */ + *grandparentp = rotate_right (parent, grandparent); + parent->color = BLACK; + node->color = grandparent->color = RED; + } + else /* grandparent->right == parent */ + { + if (parent->left == node) + { + /* Rotation between node and parent. */ + grandparent->right = rotate_right (node, parent); + node = parent; + parent = grandparent->right; + } + /* grandparent and uncle are BLACK. parent and node want to be + RED. parent = grandparent->right. node = parent->right. + + grandparent parent + bh+1 bh+1 + / \ / \ + uncle parent --> grandparent node + bh bh bh bh + / \ / \ + C node uncle C + bh bh bh bh + */ + *grandparentp = rotate_left (grandparent, parent); + parent->color = BLACK; + node->color = grandparent->color = RED; + } + return; + } /* Start again with a new (node, parent) pair. */ parent = node->parent; if (parent == NULL) - { - /* Change node's color from RED to BLACK. This increases the - tree's black-height. */ - node->color = BLACK; - return; - } + { + /* Change node's color from RED to BLACK. This increases the + tree's black-height. */ + node->color = BLACK; + return; + } } } @@ -316,280 +316,280 @@ rebalance_after_remove (gl_list_t list, gl_list_node_t child, gl_list_node_t par for (;;) { /* At this point, we reduced the black-height of the CHILD subtree by 1. - To make up, either look for a possibility to turn a RED to a BLACK - node, or try to reduce the black-height tree of CHILD's sibling - subtree as well. */ + To make up, either look for a possibility to turn a RED to a BLACK + node, or try to reduce the black-height tree of CHILD's sibling + subtree as well. */ gl_list_node_t *parentp; if (parent->parent == NULL) - parentp = &list->root; + parentp = &list->root; else if (parent->parent->left == parent) - parentp = &parent->parent->left; + parentp = &parent->parent->left; else if (parent->parent->right == parent) - parentp = &parent->parent->right; + parentp = &parent->parent->right; else - abort (); + abort (); if (parent->left == child) - { - gl_list_node_t sibling = parent->right; - /* sibling's black-height is >= 1. In particular, - sibling != NULL. - - parent - / \ - child sibling - bh bh+1 - */ - - if (sibling->color == RED) - { - /* sibling is RED, hence parent is BLACK and sibling's children - are non-NULL and BLACK. - - parent sibling - bh+2 bh+2 - / \ / \ - child sibling --> parent SR - bh bh+1 bh+1 bh+1 - / \ / \ - SL SR child SL - bh+1 bh+1 bh bh+1 - */ - *parentp = rotate_left (parent, sibling); - parent->color = RED; - sibling->color = BLACK; - - /* Concentrate on the subtree of parent. The new sibling is - one of the old sibling's children, and known to be BLACK. */ - parentp = &sibling->left; - sibling = parent->right; - } - /* Now we know that sibling is BLACK. - - parent - / \ - child sibling - bh bh+1 - */ - if (sibling->right != NULL && sibling->right->color == RED) - { - /* - parent sibling - bh+1|bh+2 bh+1|bh+2 - / \ / \ - child sibling --> parent SR - bh bh+1 bh+1 bh+1 - / \ / \ - SL SR child SL - bh bh bh bh - */ - *parentp = rotate_left (parent, sibling); - sibling->color = parent->color; - parent->color = BLACK; - sibling->right->color = BLACK; - return; - } - else if (sibling->left != NULL && sibling->left->color == RED) - { - /* - parent parent - bh+1|bh+2 bh+1|bh+2 - / \ / \ - child sibling --> child SL - bh bh+1 bh bh+1 - / \ / \ - SL SR SLL sibling - bh bh bh bh - / \ / \ - SLL SLR SLR SR - bh bh bh bh - - where SLL, SLR, SR are all black. - */ - parent->right = rotate_right (sibling->left, sibling); - /* Change sibling from BLACK to RED and SL from RED to BLACK. */ - sibling->color = RED; - sibling = parent->right; - sibling->color = BLACK; - - /* Now do as in the previous case. */ - *parentp = rotate_left (parent, sibling); - sibling->color = parent->color; - parent->color = BLACK; - sibling->right->color = BLACK; - return; - } - else - { - if (parent->color == BLACK) - { - /* Change sibling from BLACK to RED. Then the entire - subtree at parent has decreased its black-height. - parent parent - bh+2 bh+1 - / \ / \ - child sibling --> child sibling - bh bh+1 bh bh - */ - sibling->color = RED; - - child = parent; - } - else - { - /* Change parent from RED to BLACK, but compensate by - changing sibling from BLACK to RED. - parent parent - bh+1 bh+1 - / \ / \ - child sibling --> child sibling - bh bh+1 bh bh - */ - parent->color = BLACK; - sibling->color = RED; - return; - } - } - } + { + gl_list_node_t sibling = parent->right; + /* sibling's black-height is >= 1. In particular, + sibling != NULL. + + parent + / \ + child sibling + bh bh+1 + */ + + if (sibling->color == RED) + { + /* sibling is RED, hence parent is BLACK and sibling's children + are non-NULL and BLACK. + + parent sibling + bh+2 bh+2 + / \ / \ + child sibling --> parent SR + bh bh+1 bh+1 bh+1 + / \ / \ + SL SR child SL + bh+1 bh+1 bh bh+1 + */ + *parentp = rotate_left (parent, sibling); + parent->color = RED; + sibling->color = BLACK; + + /* Concentrate on the subtree of parent. The new sibling is + one of the old sibling's children, and known to be BLACK. */ + parentp = &sibling->left; + sibling = parent->right; + } + /* Now we know that sibling is BLACK. + + parent + / \ + child sibling + bh bh+1 + */ + if (sibling->right != NULL && sibling->right->color == RED) + { + /* + parent sibling + bh+1|bh+2 bh+1|bh+2 + / \ / \ + child sibling --> parent SR + bh bh+1 bh+1 bh+1 + / \ / \ + SL SR child SL + bh bh bh bh + */ + *parentp = rotate_left (parent, sibling); + sibling->color = parent->color; + parent->color = BLACK; + sibling->right->color = BLACK; + return; + } + else if (sibling->left != NULL && sibling->left->color == RED) + { + /* + parent parent + bh+1|bh+2 bh+1|bh+2 + / \ / \ + child sibling --> child SL + bh bh+1 bh bh+1 + / \ / \ + SL SR SLL sibling + bh bh bh bh + / \ / \ + SLL SLR SLR SR + bh bh bh bh + + where SLL, SLR, SR are all black. + */ + parent->right = rotate_right (sibling->left, sibling); + /* Change sibling from BLACK to RED and SL from RED to BLACK. */ + sibling->color = RED; + sibling = parent->right; + sibling->color = BLACK; + + /* Now do as in the previous case. */ + *parentp = rotate_left (parent, sibling); + sibling->color = parent->color; + parent->color = BLACK; + sibling->right->color = BLACK; + return; + } + else + { + if (parent->color == BLACK) + { + /* Change sibling from BLACK to RED. Then the entire + subtree at parent has decreased its black-height. + parent parent + bh+2 bh+1 + / \ / \ + child sibling --> child sibling + bh bh+1 bh bh + */ + sibling->color = RED; + + child = parent; + } + else + { + /* Change parent from RED to BLACK, but compensate by + changing sibling from BLACK to RED. + parent parent + bh+1 bh+1 + / \ / \ + child sibling --> child sibling + bh bh+1 bh bh + */ + parent->color = BLACK; + sibling->color = RED; + return; + } + } + } else if (parent->right == child) - { - gl_list_node_t sibling = parent->left; - /* sibling's black-height is >= 1. In particular, - sibling != NULL. - - parent - / \ - sibling child - bh+1 bh - */ - - if (sibling->color == RED) - { - /* sibling is RED, hence parent is BLACK and sibling's children - are non-NULL and BLACK. - - parent sibling - bh+2 bh+2 - / \ / \ - sibling child --> SR parent - bh+1 ch bh+1 bh+1 - / \ / \ - SL SR SL child - bh+1 bh+1 bh+1 bh - */ - *parentp = rotate_right (sibling, parent); - parent->color = RED; - sibling->color = BLACK; - - /* Concentrate on the subtree of parent. The new sibling is - one of the old sibling's children, and known to be BLACK. */ - parentp = &sibling->right; - sibling = parent->left; - } - /* Now we know that sibling is BLACK. - - parent - / \ - sibling child - bh+1 bh - */ - if (sibling->left != NULL && sibling->left->color == RED) - { - /* - parent sibling - bh+1|bh+2 bh+1|bh+2 - / \ / \ - sibling child --> SL parent - bh+1 bh bh+1 bh+1 - / \ / \ - SL SR SR child - bh bh bh bh - */ - *parentp = rotate_right (sibling, parent); - sibling->color = parent->color; - parent->color = BLACK; - sibling->left->color = BLACK; - return; - } - else if (sibling->right != NULL && sibling->right->color == RED) - { - /* - parent parent - bh+1|bh+2 bh+1|bh+2 - / \ / \ - sibling child --> SR child - bh+1 bh bh+1 bh - / \ / \ - SL SR sibling SRR - bh bh bh bh - / \ / \ - SRL SRR SL SRL - bh bh bh bh - - where SL, SRL, SRR are all black. - */ - parent->left = rotate_left (sibling, sibling->right); - /* Change sibling from BLACK to RED and SL from RED to BLACK. */ - sibling->color = RED; - sibling = parent->left; - sibling->color = BLACK; - - /* Now do as in the previous case. */ - *parentp = rotate_right (sibling, parent); - sibling->color = parent->color; - parent->color = BLACK; - sibling->left->color = BLACK; - return; - } - else - { - if (parent->color == BLACK) - { - /* Change sibling from BLACK to RED. Then the entire - subtree at parent has decreased its black-height. - parent parent - bh+2 bh+1 - / \ / \ - sibling child --> sibling child - bh+1 bh bh bh - */ - sibling->color = RED; - - child = parent; - } - else - { - /* Change parent from RED to BLACK, but compensate by - changing sibling from BLACK to RED. - parent parent - bh+1 bh+1 - / \ / \ - sibling child --> sibling child - bh+1 bh bh bh - */ - parent->color = BLACK; - sibling->color = RED; - return; - } - } - } + { + gl_list_node_t sibling = parent->left; + /* sibling's black-height is >= 1. In particular, + sibling != NULL. + + parent + / \ + sibling child + bh+1 bh + */ + + if (sibling->color == RED) + { + /* sibling is RED, hence parent is BLACK and sibling's children + are non-NULL and BLACK. + + parent sibling + bh+2 bh+2 + / \ / \ + sibling child --> SR parent + bh+1 ch bh+1 bh+1 + / \ / \ + SL SR SL child + bh+1 bh+1 bh+1 bh + */ + *parentp = rotate_right (sibling, parent); + parent->color = RED; + sibling->color = BLACK; + + /* Concentrate on the subtree of parent. The new sibling is + one of the old sibling's children, and known to be BLACK. */ + parentp = &sibling->right; + sibling = parent->left; + } + /* Now we know that sibling is BLACK. + + parent + / \ + sibling child + bh+1 bh + */ + if (sibling->left != NULL && sibling->left->color == RED) + { + /* + parent sibling + bh+1|bh+2 bh+1|bh+2 + / \ / \ + sibling child --> SL parent + bh+1 bh bh+1 bh+1 + / \ / \ + SL SR SR child + bh bh bh bh + */ + *parentp = rotate_right (sibling, parent); + sibling->color = parent->color; + parent->color = BLACK; + sibling->left->color = BLACK; + return; + } + else if (sibling->right != NULL && sibling->right->color == RED) + { + /* + parent parent + bh+1|bh+2 bh+1|bh+2 + / \ / \ + sibling child --> SR child + bh+1 bh bh+1 bh + / \ / \ + SL SR sibling SRR + bh bh bh bh + / \ / \ + SRL SRR SL SRL + bh bh bh bh + + where SL, SRL, SRR are all black. + */ + parent->left = rotate_left (sibling, sibling->right); + /* Change sibling from BLACK to RED and SL from RED to BLACK. */ + sibling->color = RED; + sibling = parent->left; + sibling->color = BLACK; + + /* Now do as in the previous case. */ + *parentp = rotate_right (sibling, parent); + sibling->color = parent->color; + parent->color = BLACK; + sibling->left->color = BLACK; + return; + } + else + { + if (parent->color == BLACK) + { + /* Change sibling from BLACK to RED. Then the entire + subtree at parent has decreased its black-height. + parent parent + bh+2 bh+1 + / \ / \ + sibling child --> sibling child + bh+1 bh bh bh + */ + sibling->color = RED; + + child = parent; + } + else + { + /* Change parent from RED to BLACK, but compensate by + changing sibling from BLACK to RED. + parent parent + bh+1 bh+1 + / \ / \ + sibling child --> sibling child + bh+1 bh bh bh + */ + parent->color = BLACK; + sibling->color = RED; + return; + } + } + } else - abort (); + abort (); /* Start again with a new (child, parent) pair. */ parent = child->parent; #if 0 /* Already handled. */ if (child != NULL && child->color == RED) - { - child->color = BLACK; - return; - } + { + child->color = BLACK; + return; + } #endif if (parent == NULL) - return; + return; } } @@ -622,17 +622,17 @@ gl_tree_add_first (gl_list_t list, const void *elt) gl_list_node_t node; for (node = list->root; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; new_node->parent = node; /* Update branch_size fields of the parent nodes. */ { - gl_list_node_t p; + gl_list_node_t p; - for (p = node; p != NULL; p = p->parent) - p->branch_size++; + for (p = node; p != NULL; p = p->parent) + p->branch_size++; } /* Color and rebalance. */ @@ -679,17 +679,17 @@ gl_tree_add_last (gl_list_t list, const void *elt) gl_list_node_t node; for (node = list->root; node->right != NULL; ) - node = node->right; + node = node->right; node->right = new_node; new_node->parent = node; /* Update branch_size fields of the parent nodes. */ { - gl_list_node_t p; + gl_list_node_t p; - for (p = node; p != NULL; p = p->parent) - p->branch_size++; + for (p = node; p != NULL; p = p->parent) + p->branch_size++; } /* Color and rebalance. */ @@ -730,7 +730,7 @@ gl_tree_add_before (gl_list_t list, gl_list_node_t node, const void *elt) else { for (node = node->left; node->right != NULL; ) - node = node->right; + node = node->right; node->right = new_node; } new_node->parent = node; @@ -780,7 +780,7 @@ gl_tree_add_after (gl_list_t list, gl_list_node_t node, const void *elt) else { for (node = node->right; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; } new_node->parent = node; @@ -827,61 +827,61 @@ gl_tree_remove_node (gl_list_t list, gl_list_node_t node) gl_list_node_t child = node->right; if (child != NULL) - { - child->parent = parent; - /* Since node->left == NULL, child must be RED and of height 1, - hence node must have been BLACK. Recolor the child. */ - child->color = BLACK; - } + { + child->parent = parent; + /* Since node->left == NULL, child must be RED and of height 1, + hence node must have been BLACK. Recolor the child. */ + child->color = BLACK; + } if (parent == NULL) - list->root = child; + list->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - /* Update branch_size fields of the parent nodes. */ - { - gl_list_node_t p; - - for (p = parent; p != NULL; p = p->parent) - p->branch_size--; - } - - if (child == NULL && node->color == BLACK) - rebalance_after_remove (list, child, parent); - } + { + if (parent->left == node) + parent->left = child; + else /* parent->right == node */ + parent->right = child; + + /* Update branch_size fields of the parent nodes. */ + { + gl_list_node_t p; + + for (p = parent; p != NULL; p = p->parent) + p->branch_size--; + } + + if (child == NULL && node->color == BLACK) + rebalance_after_remove (list, child, 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. */ + general case below is more complicated, hence slower. */ /* Replace node with node->left. */ gl_list_node_t child = node->left; child->parent = parent; /* Since node->right == NULL, child must be RED and of height 1, - hence node must have been BLACK. Recolor the child. */ + hence node must have been BLACK. Recolor the child. */ child->color = BLACK; if (parent == NULL) - list->root = child; + list->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - /* Update branch_size fields of the parent nodes. */ - { - gl_list_node_t p; - - for (p = parent; p != NULL; p = p->parent) - p->branch_size--; - } - } + { + if (parent->left == node) + parent->left = child; + else /* parent->right == node */ + parent->right = child; + + /* Update branch_size fields of the parent nodes. */ + { + gl_list_node_t p; + + for (p = parent; p != NULL; p = p->parent) + p->branch_size--; + } + } } else { @@ -892,7 +892,7 @@ gl_tree_remove_node (gl_list_t list, gl_list_node_t node) color_t removed_color; for (subst = node->left; subst->right != NULL; ) - subst = subst->right; + subst = subst->right; subst_parent = subst->parent; @@ -901,63 +901,63 @@ gl_tree_remove_node (gl_list_t list, gl_list_node_t node) removed_color = subst->color; /* 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. */ + 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; - } + { + if (child != NULL) + child->parent = subst_parent; + subst_parent->right = child; + } /* Update branch_size fields of the parent nodes. */ { - gl_list_node_t p; + gl_list_node_t p; - for (p = subst_parent; p != NULL; p = p->parent) - p->branch_size--; + for (p = subst_parent; p != NULL; p = p->parent) + p->branch_size--; } /* Copy subst into node's position. - (This is safer than to copy subst's value into node, keep node in - place, and free subst.) */ + (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->left = node->left; + subst->left->parent = subst; + } subst->right = node->right; subst->right->parent = subst; subst->color = node->color; subst->branch_size = node->branch_size; subst->parent = parent; if (parent == NULL) - list->root = subst; + list->root = subst; else if (parent->left == node) - parent->left = subst; + parent->left = subst; else /* parent->right == node */ - parent->right = subst; + parent->right = subst; if (removed_color == BLACK) - { - if (child != NULL && child->color == RED) - /* Recolor the child. */ - child->color = BLACK; - else - /* 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_after_remove (list, child, - subst_parent != node ? subst_parent : subst); - } + { + if (child != NULL && child->color == RED) + /* Recolor the child. */ + child->color = BLACK; + else + /* 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_after_remove (list, child, + subst_parent != node ? subst_parent : subst); + } } if (list->base.dispose_fn != NULL) diff --git a/lib/gl_anytree_list2.h b/lib/gl_anytree_list2.h index 143348eda..c2cc82084 100644 --- a/lib/gl_anytree_list2.h +++ b/lib/gl_anytree_list2.h @@ -20,10 +20,10 @@ static gl_list_t gl_tree_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_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 = XMALLOC (struct gl_list_impl); @@ -60,19 +60,19 @@ gl_tree_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt) if (elt != node->value) { size_t new_hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + (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; - add_to_bucket (list, node); - } + { + remove_from_bucket (list, node); + node->value = elt; + node->h.hashcode = new_hashcode; + add_to_bucket (list, node); + } else - node->value = elt; + node->value = elt; } #else node->value = elt; @@ -86,12 +86,12 @@ gl_tree_next_node (gl_list_t list, gl_list_node_t node) { node = node->right; while (node->left != NULL) - node = node->left; + node = node->left; } else { while (node->parent != NULL && node->parent->right == node) - node = node->parent; + node = node->parent; node = node->parent; } return node; @@ -104,12 +104,12 @@ gl_tree_previous_node (gl_list_t list, gl_list_node_t node) { node = node->left; while (node->right != NULL) - node = node->right; + node = node->right; } else { while (node->parent != NULL && node->parent->left == node) - node = node->parent; + node = node->parent; node = node->parent; } return node; @@ -125,16 +125,16 @@ node_at (gl_list_node_t root, size_t position) for (;;) { if (node->left != NULL) - { - if (position < node->left->branch_size) - { - node = node->left; - continue; - } - position -= node->left->branch_size; - } + { + if (position < node->left->branch_size) + { + node = node->left; + continue; + } + position -= node->left->branch_size; + } if (position == 0) - break; + break; position--; node = node->right; } @@ -166,19 +166,19 @@ gl_tree_set_at (gl_list_t list, size_t position, const void *elt) if (elt != node->value) { size_t new_hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (elt) - : (size_t)(uintptr_t) elt); + (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; - add_to_bucket (list, node); - } + { + remove_from_bucket (list, node); + node->value = elt; + node->h.hashcode = new_hashcode; + add_to_bucket (list, node); + } else - node->value = elt; + node->value = elt; } #else node->value = elt; @@ -190,10 +190,10 @@ gl_tree_set_at (gl_list_t list, size_t position, const void *elt) static gl_list_node_t gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { if (!(start_index <= end_index - && end_index <= (list->root != NULL ? list->root->branch_size : 0))) + && end_index <= (list->root != NULL ? list->root->branch_size : 0))) /* Invalid arguments. */ abort (); { @@ -206,105 +206,105 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index, if (start_index == 0) { - /* Consider all elements. */ - for (;;) - { - /* Descend on left branch. */ - for (;;) - { - if (node == NULL) - break; - stack_ptr->node = node; - stack_ptr->rightp = 0; - node = node->left; - stack_ptr++; - } - /* Climb up again. */ - for (;;) - { - if (stack_ptr == &stack[0]) - return NULL; - stack_ptr--; - if (!stack_ptr->rightp) - break; - } - node = stack_ptr->node; - /* Test against current element. */ - if (equals != NULL ? equals (elt, node->value) : elt == node->value) - return node; - index++; - if (index >= end_index) - return NULL; - /* Descend on right branch. */ - stack_ptr->rightp = 1; - node = node->right; - stack_ptr++; - } + /* Consider all elements. */ + for (;;) + { + /* Descend on left branch. */ + for (;;) + { + if (node == NULL) + break; + stack_ptr->node = node; + stack_ptr->rightp = 0; + node = node->left; + stack_ptr++; + } + /* Climb up again. */ + for (;;) + { + if (stack_ptr == &stack[0]) + return NULL; + stack_ptr--; + if (!stack_ptr->rightp) + break; + } + node = stack_ptr->node; + /* Test against current element. */ + if (equals != NULL ? equals (elt, node->value) : elt == node->value) + return node; + index++; + if (index >= end_index) + return NULL; + /* Descend on right branch. */ + stack_ptr->rightp = 1; + node = node->right; + stack_ptr++; + } } else { - /* Consider only elements at indices >= start_index. - In this case, rightp contains the difference between the start_index - for the parent node and the one for the child node (0 when the child - node is the parent's left child, > 0 when the child is the parent's - right child). */ - for (;;) - { - /* Descend on left branch. */ - for (;;) - { - if (node == NULL) - break; - if (node->branch_size <= start_index) - break; - stack_ptr->node = node; - stack_ptr->rightp = 0; - node = node->left; - stack_ptr++; - } - /* Climb up again. */ - for (;;) - { - if (stack_ptr == &stack[0]) - return NULL; - stack_ptr--; - if (!stack_ptr->rightp) - break; - start_index += stack_ptr->rightp; - } - node = stack_ptr->node; - { - size_t left_branch_size1 = - (node->left != NULL ? node->left->branch_size : 0) + 1; - if (start_index < left_branch_size1) - { - /* Test against current element. */ - if (equals != NULL ? equals (elt, node->value) : elt == node->value) - return node; - /* Now that we have considered all indices < left_branch_size1, - we can increment start_index. */ - start_index = left_branch_size1; - } - index++; - if (index >= end_index) - return NULL; - /* Descend on right branch. */ - start_index -= left_branch_size1; - stack_ptr->rightp = left_branch_size1; - } - node = node->right; - stack_ptr++; - } + /* Consider only elements at indices >= start_index. + In this case, rightp contains the difference between the start_index + for the parent node and the one for the child node (0 when the child + node is the parent's left child, > 0 when the child is the parent's + right child). */ + for (;;) + { + /* Descend on left branch. */ + for (;;) + { + if (node == NULL) + break; + if (node->branch_size <= start_index) + break; + stack_ptr->node = node; + stack_ptr->rightp = 0; + node = node->left; + stack_ptr++; + } + /* Climb up again. */ + for (;;) + { + if (stack_ptr == &stack[0]) + return NULL; + stack_ptr--; + if (!stack_ptr->rightp) + break; + start_index += stack_ptr->rightp; + } + node = stack_ptr->node; + { + size_t left_branch_size1 = + (node->left != NULL ? node->left->branch_size : 0) + 1; + if (start_index < left_branch_size1) + { + /* Test against current element. */ + if (equals != NULL ? equals (elt, node->value) : elt == node->value) + return node; + /* Now that we have considered all indices < left_branch_size1, + we can increment start_index. */ + start_index = left_branch_size1; + } + index++; + if (index >= end_index) + return NULL; + /* Descend on right branch. */ + start_index -= left_branch_size1; + stack_ptr->rightp = left_branch_size1; + } + node = node->right; + stack_ptr++; + } } } } static size_t gl_tree_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { if (!(start_index <= end_index - && end_index <= (list->root != NULL ? list->root->branch_size : 0))) + && end_index <= (list->root != NULL ? list->root->branch_size : 0))) /* Invalid arguments. */ abort (); { @@ -317,95 +317,95 @@ gl_tree_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, if (start_index == 0) { - /* Consider all elements. */ - for (;;) - { - /* Descend on left branch. */ - for (;;) - { - if (node == NULL) - break; - stack_ptr->node = node; - stack_ptr->rightp = 0; - node = node->left; - stack_ptr++; - } - /* Climb up again. */ - for (;;) - { - if (stack_ptr == &stack[0]) - return (size_t)(-1); - stack_ptr--; - if (!stack_ptr->rightp) - break; - } - node = stack_ptr->node; - /* Test against current element. */ - if (equals != NULL ? equals (elt, node->value) : elt == node->value) - return index; - index++; - if (index >= end_index) - return (size_t)(-1); - /* Descend on right branch. */ - stack_ptr->rightp = 1; - node = node->right; - stack_ptr++; - } + /* Consider all elements. */ + for (;;) + { + /* Descend on left branch. */ + for (;;) + { + if (node == NULL) + break; + stack_ptr->node = node; + stack_ptr->rightp = 0; + node = node->left; + stack_ptr++; + } + /* Climb up again. */ + for (;;) + { + if (stack_ptr == &stack[0]) + return (size_t)(-1); + stack_ptr--; + if (!stack_ptr->rightp) + break; + } + node = stack_ptr->node; + /* Test against current element. */ + if (equals != NULL ? equals (elt, node->value) : elt == node->value) + return index; + index++; + if (index >= end_index) + return (size_t)(-1); + /* Descend on right branch. */ + stack_ptr->rightp = 1; + node = node->right; + stack_ptr++; + } } else { - /* Consider only elements at indices >= start_index. - In this case, rightp contains the difference between the start_index - for the parent node and the one for the child node (0 when the child - node is the parent's left child, > 0 when the child is the parent's - right child). */ - for (;;) - { - /* Descend on left branch. */ - for (;;) - { - if (node == NULL) - break; - if (node->branch_size <= start_index) - break; - stack_ptr->node = node; - stack_ptr->rightp = 0; - node = node->left; - stack_ptr++; - } - /* Climb up again. */ - for (;;) - { - if (stack_ptr == &stack[0]) - return (size_t)(-1); - stack_ptr--; - if (!stack_ptr->rightp) - break; - start_index += stack_ptr->rightp; - } - node = stack_ptr->node; - { - size_t left_branch_size1 = - (node->left != NULL ? node->left->branch_size : 0) + 1; - if (start_index < left_branch_size1) - { - /* Test against current element. */ - if (equals != NULL ? equals (elt, node->value) : elt == node->value) - return index; - /* Now that we have considered all indices < left_branch_size1, - we can increment start_index. */ - start_index = left_branch_size1; - } - index++; - if (index >= end_index) - return (size_t)(-1); - /* Descend on right branch. */ - start_index -= left_branch_size1; - stack_ptr->rightp = left_branch_size1; - } - node = node->right; - stack_ptr++; - } + /* Consider only elements at indices >= start_index. + In this case, rightp contains the difference between the start_index + for the parent node and the one for the child node (0 when the child + node is the parent's left child, > 0 when the child is the parent's + right child). */ + for (;;) + { + /* Descend on left branch. */ + for (;;) + { + if (node == NULL) + break; + if (node->branch_size <= start_index) + break; + stack_ptr->node = node; + stack_ptr->rightp = 0; + node = node->left; + stack_ptr++; + } + /* Climb up again. */ + for (;;) + { + if (stack_ptr == &stack[0]) + return (size_t)(-1); + stack_ptr--; + if (!stack_ptr->rightp) + break; + start_index += stack_ptr->rightp; + } + node = stack_ptr->node; + { + size_t left_branch_size1 = + (node->left != NULL ? node->left->branch_size : 0) + 1; + if (start_index < left_branch_size1) + { + /* Test against current element. */ + if (equals != NULL ? equals (elt, node->value) : elt == node->value) + return index; + /* Now that we have considered all indices < left_branch_size1, + we can increment start_index. */ + start_index = left_branch_size1; + } + index++; + if (index >= end_index) + return (size_t)(-1); + /* Descend on right branch. */ + start_index -= left_branch_size1; + stack_ptr->rightp = left_branch_size1; + } + node = node->right; + stack_ptr++; + } } } } @@ -444,10 +444,10 @@ gl_tree_remove (gl_list_t list, const void *elt) if (list->root != NULL) { gl_list_node_t node = - gl_tree_search_from_to (list, 0, list->root->branch_size, elt); + gl_tree_search_from_to (list, 0, list->root->branch_size, elt); if (node != NULL) - return gl_tree_remove_node (list, node); + return gl_tree_remove_node (list, node); } return false; } @@ -466,28 +466,28 @@ gl_tree_list_free (gl_list_t list) { /* Descend on left branch. */ for (;;) - { - if (node == NULL) - break; - stack_ptr->node = node; - stack_ptr->rightp = false; - node = node->left; - stack_ptr++; - } + { + 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 (list->base.dispose_fn != NULL) - list->base.dispose_fn (node->value); - free (node); - } + { + if (stack_ptr == &stack[0]) + goto done_iterate; + stack_ptr--; + node = stack_ptr->node; + if (!stack_ptr->rightp) + break; + /* Free the current node. */ + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (node->value); + free (node); + } /* Descend on right branch. */ stack_ptr->rightp = true; node = node->right; @@ -552,27 +552,27 @@ gl_tree_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index) static bool gl_tree_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) + 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; + *nodep = node; /* Advance to the next node. */ if (node->right != NULL) - { - node = node->right; - while (node->left != NULL) - node = node->left; - } + { + 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; - } + { + while (node->parent != NULL && node->parent->right == node) + node = node->parent; + node = node->parent; + } iterator->p = node; return true; } @@ -589,7 +589,7 @@ gl_tree_iterator_free (gl_list_iterator_t *iterator) static gl_list_node_t gl_tree_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node; @@ -598,121 +598,121 @@ gl_tree_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, int cmp = compar (node->value, elt); if (cmp < 0) - node = node->right; + node = node->right; else if (cmp > 0) - node = node->left; + node = node->left; else /* cmp == 0 */ - { - /* We have an element equal to ELT. But we need the leftmost such - element. */ - gl_list_node_t found = node; - node = node->left; - for (; node != NULL; ) - { - int cmp2 = compar (node->value, elt); - - if (cmp2 < 0) - node = node->right; - else if (cmp2 > 0) - /* The list was not sorted. */ - abort (); - else /* cmp2 == 0 */ - { - found = node; - node = node->left; - } - } - return found; - } + { + /* We have an element equal to ELT. But we need the leftmost such + element. */ + gl_list_node_t found = node; + node = node->left; + for (; node != NULL; ) + { + int cmp2 = compar (node->value, elt); + + if (cmp2 < 0) + node = node->right; + else if (cmp2 > 0) + /* The list was not sorted. */ + abort (); + else /* cmp2 == 0 */ + { + found = node; + node = node->left; + } + } + return found; + } } return NULL; } static gl_list_node_t gl_tree_sortedlist_search_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { gl_list_node_t node; if (!(low <= high - && high <= (list->root != NULL ? list->root->branch_size : 0))) + && high <= (list->root != NULL ? list->root->branch_size : 0))) /* Invalid arguments. */ abort (); for (node = list->root; node != NULL; ) { size_t left_branch_size = - (node->left != NULL ? node->left->branch_size : 0); + (node->left != NULL ? node->left->branch_size : 0); if (low > left_branch_size) - { - low -= left_branch_size + 1; - high -= left_branch_size + 1; - node = node->right; - } + { + low -= left_branch_size + 1; + high -= left_branch_size + 1; + node = node->right; + } else if (high <= left_branch_size) - node = node->left; + node = node->left; else - { - /* Here low <= left_branch_size < high. */ - int cmp = compar (node->value, elt); - - if (cmp < 0) - { - low = 0; - high -= left_branch_size + 1; - node = node->right; - } - else if (cmp > 0) - node = node->left; - else /* cmp == 0 */ - { - /* We have an element equal to ELT. But we need the leftmost - such element. */ - gl_list_node_t found = node; - node = node->left; - for (; node != NULL; ) - { - size_t left_branch_size2 = - (node->left != NULL ? node->left->branch_size : 0); - - if (low > left_branch_size2) - { - low -= left_branch_size2 + 1; - node = node->right; - } - else - { - /* Here low <= left_branch_size2. */ - int cmp2 = compar (node->value, elt); - - if (cmp2 < 0) - { - low = 0; - node = node->right; - } - else if (cmp2 > 0) - /* The list was not sorted. */ - abort (); - else /* cmp2 == 0 */ - { - found = node; - node = node->left; - } - } - } - return found; - } - } + { + /* Here low <= left_branch_size < high. */ + int cmp = compar (node->value, elt); + + if (cmp < 0) + { + low = 0; + high -= left_branch_size + 1; + node = node->right; + } + else if (cmp > 0) + node = node->left; + else /* cmp == 0 */ + { + /* We have an element equal to ELT. But we need the leftmost + such element. */ + gl_list_node_t found = node; + node = node->left; + for (; node != NULL; ) + { + size_t left_branch_size2 = + (node->left != NULL ? node->left->branch_size : 0); + + if (low > left_branch_size2) + { + low -= left_branch_size2 + 1; + node = node->right; + } + else + { + /* Here low <= left_branch_size2. */ + int cmp2 = compar (node->value, elt); + + if (cmp2 < 0) + { + low = 0; + node = node->right; + } + else if (cmp2 > 0) + /* The list was not sorted. */ + abort (); + else /* cmp2 == 0 */ + { + found = node; + node = node->left; + } + } + } + return found; + } + } } return NULL; } static size_t gl_tree_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node; size_t position; @@ -722,138 +722,138 @@ gl_tree_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, int cmp = compar (node->value, elt); if (cmp < 0) - { - if (node->left != NULL) - position += node->left->branch_size; - position++; - node = node->right; - } + { + if (node->left != NULL) + position += node->left->branch_size; + position++; + node = node->right; + } else if (cmp > 0) - node = node->left; + node = node->left; else /* cmp == 0 */ - { - /* We have an element equal to ELT. But we need the leftmost such - element. */ - size_t found_position = - position + (node->left != NULL ? node->left->branch_size : 0); - node = node->left; - for (; node != NULL; ) - { - int cmp2 = compar (node->value, elt); - - if (cmp2 < 0) - { - if (node->left != NULL) - position += node->left->branch_size; - position++; - node = node->right; - } - else if (cmp2 > 0) - /* The list was not sorted. */ - abort (); - else /* cmp2 == 0 */ - { - found_position = - position - + (node->left != NULL ? node->left->branch_size : 0); - node = node->left; - } - } - return found_position; - } + { + /* We have an element equal to ELT. But we need the leftmost such + element. */ + size_t found_position = + position + (node->left != NULL ? node->left->branch_size : 0); + node = node->left; + for (; node != NULL; ) + { + int cmp2 = compar (node->value, elt); + + if (cmp2 < 0) + { + if (node->left != NULL) + position += node->left->branch_size; + position++; + node = node->right; + } + else if (cmp2 > 0) + /* The list was not sorted. */ + abort (); + else /* cmp2 == 0 */ + { + found_position = + position + + (node->left != NULL ? node->left->branch_size : 0); + node = node->left; + } + } + return found_position; + } } return (size_t)(-1); } static size_t gl_tree_sortedlist_indexof_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { gl_list_node_t node; size_t position; if (!(low <= high - && high <= (list->root != NULL ? list->root->branch_size : 0))) + && high <= (list->root != NULL ? list->root->branch_size : 0))) /* Invalid arguments. */ abort (); for (node = list->root, position = 0; node != NULL; ) { size_t left_branch_size = - (node->left != NULL ? node->left->branch_size : 0); + (node->left != NULL ? node->left->branch_size : 0); if (low > left_branch_size) - { - low -= left_branch_size + 1; - high -= left_branch_size + 1; - position += left_branch_size + 1; - node = node->right; - } + { + low -= left_branch_size + 1; + high -= left_branch_size + 1; + position += left_branch_size + 1; + node = node->right; + } else if (high <= left_branch_size) - node = node->left; + node = node->left; else - { - /* Here low <= left_branch_size < high. */ - int cmp = compar (node->value, elt); - - if (cmp < 0) - { - low = 0; - high -= left_branch_size + 1; - position += left_branch_size + 1; - node = node->right; - } - else if (cmp > 0) - node = node->left; - else /* cmp == 0 */ - { - /* We have an element equal to ELT. But we need the leftmost - such element. */ - size_t found_position = - position + (node->left != NULL ? node->left->branch_size : 0); - node = node->left; - for (; node != NULL; ) - { - size_t left_branch_size2 = - (node->left != NULL ? node->left->branch_size : 0); - - if (low > left_branch_size2) - { - low -= left_branch_size2 + 1; - node = node->right; - } - else - { - /* Here low <= left_branch_size2. */ - int cmp2 = compar (node->value, elt); - - if (cmp2 < 0) - { - position += left_branch_size2 + 1; - node = node->right; - } - else if (cmp2 > 0) - /* The list was not sorted. */ - abort (); - else /* cmp2 == 0 */ - { - found_position = position + left_branch_size2; - node = node->left; - } - } - } - return found_position; - } - } + { + /* Here low <= left_branch_size < high. */ + int cmp = compar (node->value, elt); + + if (cmp < 0) + { + low = 0; + high -= left_branch_size + 1; + position += left_branch_size + 1; + node = node->right; + } + else if (cmp > 0) + node = node->left; + else /* cmp == 0 */ + { + /* We have an element equal to ELT. But we need the leftmost + such element. */ + size_t found_position = + position + (node->left != NULL ? node->left->branch_size : 0); + node = node->left; + for (; node != NULL; ) + { + size_t left_branch_size2 = + (node->left != NULL ? node->left->branch_size : 0); + + if (low > left_branch_size2) + { + low -= left_branch_size2 + 1; + node = node->right; + } + else + { + /* Here low <= left_branch_size2. */ + int cmp2 = compar (node->value, elt); + + if (cmp2 < 0) + { + position += left_branch_size2 + 1; + node = node->right; + } + else if (cmp2 > 0) + /* The list was not sorted. */ + abort (); + else /* cmp2 == 0 */ + { + found_position = position + left_branch_size2; + node = node->left; + } + } + } + return found_position; + } + } } return (size_t)(-1); } static gl_list_node_t gl_tree_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node = list->root; @@ -865,25 +865,25 @@ gl_tree_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, int cmp = compar (node->value, elt); if (cmp < 0) - { - if (node->right == NULL) - return gl_tree_add_after (list, node, elt); - node = node->right; - } + { + if (node->right == NULL) + return gl_tree_add_after (list, node, elt); + node = node->right; + } else if (cmp > 0) - { - if (node->left == NULL) - return gl_tree_add_before (list, node, elt); - node = node->left; - } + { + if (node->left == NULL) + return gl_tree_add_before (list, node, elt); + node = node->left; + } else /* cmp == 0 */ - return gl_tree_add_before (list, node, elt); + return gl_tree_add_before (list, node, elt); } } static bool gl_tree_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { gl_list_node_t node = gl_tree_sortedlist_search (list, compar, elt); if (node != NULL) diff --git a/lib/gl_anytree_oset.h b/lib/gl_anytree_oset.h index 95f212406..bbcd7a40e 100644 --- a/lib/gl_anytree_oset.h +++ b/lib/gl_anytree_oset.h @@ -29,8 +29,8 @@ typedef iterstack_item_t iterstack_t[MAXHEIGHT]; static gl_oset_t gl_tree_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn) + gl_setelement_compar_fn compar_fn, + gl_setelement_dispose_fn dispose_fn) { struct gl_oset_impl *set = XMALLOC (struct gl_oset_impl); @@ -58,52 +58,52 @@ gl_tree_search (gl_oset_t set, const void *elt) for (node = set->root; node != NULL; ) { int cmp = (compar != NULL - ? compar (node->value, elt) - : (node->value > elt ? 1 : - node->value < elt ? -1 : 0)); + ? compar (node->value, elt) + : (node->value > elt ? 1 : + node->value < elt ? -1 : 0)); if (cmp < 0) - node = node->right; + node = node->right; else if (cmp > 0) - node = node->left; + node = node->left; else /* cmp == 0 */ - /* We have an element equal to ELT. */ - return true; + /* 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_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; + 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; - } + { + /* 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; } @@ -117,17 +117,17 @@ gl_tree_search_node (gl_oset_t set, const void *elt) for (node = set->root; node != NULL; ) { int cmp = (compar != NULL - ? compar (node->value, elt) - : (node->value > elt ? 1 : - node->value < elt ? -1 : 0)); + ? compar (node->value, elt) + : (node->value > elt ? 1 : + node->value < elt ? -1 : 0)); if (cmp < 0) - node = node->right; + node = node->right; else if (cmp > 0) - node = node->left; + node = node->left; else /* cmp == 0 */ - /* We have an element equal to ELT. */ - return node; + /* We have an element equal to ELT. */ + return node; } return NULL; } @@ -149,30 +149,30 @@ gl_tree_add (gl_oset_t set, const void *elt) for (;;) { int cmp = (compar != NULL - ? compar (node->value, elt) - : (node->value > elt ? 1 : - node->value < elt ? -1 : 0)); + ? compar (node->value, elt) + : (node->value > elt ? 1 : + node->value < elt ? -1 : 0)); if (cmp < 0) - { - if (node->right == NULL) - { - gl_tree_add_after (set, node, elt); - return true; - } - node = node->right; - } + { + if (node->right == NULL) + { + gl_tree_add_after (set, node, elt); + return true; + } + node = node->right; + } else if (cmp > 0) - { - if (node->left == NULL) - { - gl_tree_add_before (set, node, elt); - return true; - } - node = node->left; - } + { + if (node->left == NULL) + { + gl_tree_add_before (set, node, elt); + return true; + } + node = node->left; + } else /* cmp == 0 */ - return false; + return false; } } @@ -199,28 +199,28 @@ gl_tree_oset_free (gl_oset_t set) { /* Descend on left branch. */ for (;;) - { - if (node == NULL) - break; - stack_ptr->node = node; - stack_ptr->rightp = false; - node = node->left; - stack_ptr++; - } + { + 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); - } + { + 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; @@ -266,17 +266,17 @@ gl_tree_iterator_next (gl_oset_iterator_t *iterator, const void **eltp) *eltp = node->value; /* Advance to the next node. */ if (node->right != NULL) - { - node = node->right; - while (node->left != NULL) - node = node->left; - } + { + 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; - } + { + while (node->parent != NULL && node->parent->right == node) + node = node->parent; + node = node->parent; + } iterator->p = node; return true; } diff --git a/lib/gl_anytreehash_list1.h b/lib/gl_anytreehash_list1.h index 95dade95c..45418cfb2 100644 --- a/lib/gl_anytreehash_list1.h +++ b/lib/gl_anytreehash_list1.h @@ -51,14 +51,14 @@ node_position (gl_list_node_t node) gl_list_node_t parent = node->parent; if (parent == NULL) - return position; + return position; /* position is now relative to the subtree of node. */ if (parent->right == node) - { - position += 1; - if (parent->left != NULL) - position += parent->left->branch_size; - } + { + position += 1; + if (parent->left != NULL) + position += parent->left->branch_size; + } /* position is now relative to the subtree of parent. */ node = parent; } @@ -74,7 +74,7 @@ compare_by_position (const void *x1, const void *x2) size_t position2 = node_position (node2); return (position1 > position2 ? 1 : - position1 < position2 ? -1 : 0); + position1 < position2 ? -1 : 0); } /* Compares a node's position in the tree with a given threshold. */ @@ -119,54 +119,54 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node) gl_hash_entry_t *entryp; for (entryp = &list->table[bucket]; *entryp != NULL; entryp = &(*entryp)->hash_next) - { - gl_hash_entry_t entry = *entryp; + { + gl_hash_entry_t entry = *entryp; - if (entry->hashcode == hashcode) - { - if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC) - { - /* An entry representing multiple nodes. */ - gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; - /* Only the first node is interesting. */ - gl_list_node_t node = gl_oset_first (nodes); - if (equals != NULL ? equals (value, node->value) : value == node->value) - { - /* Found already multiple nodes with the same value. - Add the new_node to it. */ - gl_oset_add (nodes, new_node); - return; - } - } - else - { - /* An entry representing a single node. */ - gl_list_node_t node = (struct gl_list_node_impl *) entry; - if (equals != NULL ? equals (value, node->value) : value == node->value) - { - /* Found already a node with the same value. Turn it - into an ordered set, and add new_node to it. */ - gl_oset_t nodes; - struct gl_multiple_nodes *multi_entry; + if (entry->hashcode == hashcode) + { + if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC) + { + /* An entry representing multiple nodes. */ + gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; + /* Only the first node is interesting. */ + gl_list_node_t node = gl_oset_first (nodes); + if (equals != NULL ? equals (value, node->value) : value == node->value) + { + /* Found already multiple nodes with the same value. + Add the new_node to it. */ + gl_oset_add (nodes, new_node); + return; + } + } + else + { + /* An entry representing a single node. */ + gl_list_node_t node = (struct gl_list_node_impl *) entry; + if (equals != NULL ? equals (value, node->value) : value == node->value) + { + /* Found already a node with the same value. Turn it + into an ordered set, and add new_node to it. */ + gl_oset_t nodes; + struct gl_multiple_nodes *multi_entry; - nodes = - gl_oset_create_empty (OSET_TREE_FLAVOR, - compare_by_position, NULL); + nodes = + gl_oset_create_empty (OSET_TREE_FLAVOR, + compare_by_position, NULL); - gl_oset_add (nodes, node); - gl_oset_add (nodes, new_node); + gl_oset_add (nodes, node); + gl_oset_add (nodes, new_node); - multi_entry = XMALLOC (struct gl_multiple_nodes); - multi_entry->h.hash_next = entry->hash_next; - multi_entry->h.hashcode = entry->hashcode; - multi_entry->magic = MULTIPLE_NODES_MAGIC; - multi_entry->nodes = nodes; - *entryp = &multi_entry->h; - return; - } - } - } - } + multi_entry = XMALLOC (struct gl_multiple_nodes); + multi_entry->h.hash_next = entry->hash_next; + multi_entry->h.hashcode = entry->hashcode; + multi_entry->magic = MULTIPLE_NODES_MAGIC; + multi_entry->nodes = nodes; + *entryp = &multi_entry->h; + return; + } + } + } + } } /* If no duplicates are allowed, multiple nodes are not needed. */ new_node->h.hash_next = list->table[bucket]; @@ -192,45 +192,45 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node) gl_hash_entry_t *entryp; for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next) - { - gl_hash_entry_t entry = *entryp; + { + gl_hash_entry_t entry = *entryp; - if (entry == &old_node->h) - { - /* Found old_node as a single node in the bucket. Remove it. */ - *entryp = old_node->h.hash_next; - break; - } - if (entry == NULL) - /* node is not in the right bucket. Did the hash codes - change inadvertently? */ - abort (); - if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC - && entry->hashcode == hashcode) - { - /* An entry representing multiple nodes. */ - gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; - /* Only the first node is interesting. */ - gl_list_node_t node = gl_oset_first (nodes); - if (equals != NULL ? equals (value, node->value) : value == node->value) - { - /* Found multiple nodes with the same value. - old_node must be one of them. Remove it. */ - if (!gl_oset_remove (nodes, old_node)) - abort (); - if (gl_oset_size (nodes) == 1) - { - /* Replace a one-element set with a single node. */ - node = gl_oset_first (nodes); - node->h.hash_next = entry->hash_next; - *entryp = &node->h; - gl_oset_free (nodes); - free (entry); - } - break; - } - } - } + if (entry == &old_node->h) + { + /* Found old_node as a single node in the bucket. Remove it. */ + *entryp = old_node->h.hash_next; + break; + } + if (entry == NULL) + /* node is not in the right bucket. Did the hash codes + change inadvertently? */ + abort (); + if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC + && entry->hashcode == hashcode) + { + /* An entry representing multiple nodes. */ + gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; + /* Only the first node is interesting. */ + gl_list_node_t node = gl_oset_first (nodes); + if (equals != NULL ? equals (value, node->value) : value == node->value) + { + /* Found multiple nodes with the same value. + old_node must be one of them. Remove it. */ + if (!gl_oset_remove (nodes, old_node)) + abort (); + if (gl_oset_size (nodes) == 1) + { + /* Replace a one-element set with a single node. */ + node = gl_oset_first (nodes); + node->h.hash_next = entry->hash_next; + *entryp = &node->h; + gl_oset_free (nodes); + free (entry); + } + break; + } + } + } } else { @@ -238,17 +238,17 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node) gl_hash_entry_t *entryp; for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next) - { - if (*entryp == &old_node->h) - { - *entryp = old_node->h.hash_next; - break; - } - if (*entryp == NULL) - /* node is not in the right bucket. Did the hash codes - change inadvertently? */ - abort (); - } + { + if (*entryp == &old_node->h) + { + *entryp = old_node->h.hash_next; + break; + } + if (*entryp == NULL) + /* node is not in the right bucket. Did the hash codes + change inadvertently? */ + abort (); + } } } @@ -266,29 +266,29 @@ add_nodes_to_buckets (gl_list_t list) { /* Descend on left branch. */ for (;;) - { - if (node == NULL) - break; - stack_ptr->node = node; - stack_ptr->rightp = false; - node = node->left; - stack_ptr++; - } + { + 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]) - return; - stack_ptr--; - if (!stack_ptr->rightp) - break; - } + { + if (stack_ptr == &stack[0]) + return; + stack_ptr--; + if (!stack_ptr->rightp) + break; + } node = stack_ptr->node; /* Add the current node to the hash table. */ node->h.hashcode = - (list->base.hashcode_fn != NULL - ? list->base.hashcode_fn (node->value) - : (size_t)(uintptr_t) node->value); + (list->base.hashcode_fn != NULL + ? list->base.hashcode_fn (node->value) + : (size_t)(uintptr_t) node->value); add_to_bucket (list, node); /* Descend on right branch. */ stack_ptr->rightp = true; diff --git a/lib/gl_anytreehash_list2.h b/lib/gl_anytreehash_list2.h index 4e22bb7c0..b433ecdd7 100644 --- a/lib/gl_anytreehash_list2.h +++ b/lib/gl_anytreehash_list2.h @@ -19,10 +19,10 @@ static gl_list_node_t gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { if (!(start_index <= end_index - && end_index <= (list->root != NULL ? list->root->branch_size : 0))) + && end_index <= (list->root != NULL ? list->root->branch_size : 0))) /* Invalid arguments. */ abort (); { @@ -36,91 +36,91 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index, if (list->base.allow_duplicates) { - for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next) - if (entry->hashcode == hashcode) - { - if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC) - { - /* An entry representing multiple nodes. */ - gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; - /* The first node is interesting. */ - gl_list_node_t node = gl_oset_first (nodes); - if (equals != NULL ? equals (elt, node->value) : elt == node->value) - { - /* All nodes in the entry are equal to the given ELT. */ - if (start_index == 0) - { - /* We have to return only the one at the minimal - position, and this is the first one in the ordered - set. */ - if (end_index == list->root->branch_size - || node_position (node) < end_index) - return node; - } - else - { - /* We have to return only the one at the minimal - position >= start_index. */ - const void *elt; - if (gl_oset_search_atleast (nodes, - compare_position_threshold, - (void *)(uintptr_t)start_index, - &elt)) - { - node = (gl_list_node_t) elt; - if (end_index == list->root->branch_size - || node_position (node) < end_index) - return node; - } - } - break; - } - } - else - { - /* An entry representing a single node. */ - gl_list_node_t node = (struct gl_list_node_impl *) entry; - if (equals != NULL ? equals (elt, node->value) : elt == node->value) - { - bool position_in_bounds; - if (start_index == 0 && end_index == list->root->branch_size) - position_in_bounds = true; - else - { - size_t position = node_position (node); - position_in_bounds = - (position >= start_index && position < end_index); - } - if (position_in_bounds) - return node; - break; - } - } - } + for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next) + if (entry->hashcode == hashcode) + { + if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC) + { + /* An entry representing multiple nodes. */ + gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; + /* The first node is interesting. */ + gl_list_node_t node = gl_oset_first (nodes); + if (equals != NULL ? equals (elt, node->value) : elt == node->value) + { + /* All nodes in the entry are equal to the given ELT. */ + if (start_index == 0) + { + /* We have to return only the one at the minimal + position, and this is the first one in the ordered + set. */ + if (end_index == list->root->branch_size + || node_position (node) < end_index) + return node; + } + else + { + /* We have to return only the one at the minimal + position >= start_index. */ + const void *elt; + if (gl_oset_search_atleast (nodes, + compare_position_threshold, + (void *)(uintptr_t)start_index, + &elt)) + { + node = (gl_list_node_t) elt; + if (end_index == list->root->branch_size + || node_position (node) < end_index) + return node; + } + } + break; + } + } + else + { + /* An entry representing a single node. */ + gl_list_node_t node = (struct gl_list_node_impl *) entry; + if (equals != NULL ? equals (elt, node->value) : elt == node->value) + { + bool position_in_bounds; + if (start_index == 0 && end_index == list->root->branch_size) + position_in_bounds = true; + else + { + size_t position = node_position (node); + position_in_bounds = + (position >= start_index && position < end_index); + } + if (position_in_bounds) + return node; + break; + } + } + } } else { - /* If no duplicates are allowed, multiple nodes are not needed. */ - for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next) - if (entry->hashcode == hashcode) - { - gl_list_node_t node = (struct gl_list_node_impl *) entry; - if (equals != NULL ? equals (elt, node->value) : elt == node->value) - { - bool position_in_bounds; - if (start_index == 0 && end_index == list->root->branch_size) - position_in_bounds = true; - else - { - size_t position = node_position (node); - position_in_bounds = - (position >= start_index && position < end_index); - } - if (position_in_bounds) - return node; - break; - } - } + /* If no duplicates are allowed, multiple nodes are not needed. */ + for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next) + if (entry->hashcode == hashcode) + { + gl_list_node_t node = (struct gl_list_node_impl *) entry; + if (equals != NULL ? equals (elt, node->value) : elt == node->value) + { + bool position_in_bounds; + if (start_index == 0 && end_index == list->root->branch_size) + position_in_bounds = true; + else + { + size_t position = node_position (node); + position_in_bounds = + (position >= start_index && position < end_index); + } + if (position_in_bounds) + return node; + break; + } + } } return NULL; @@ -129,7 +129,7 @@ gl_tree_search_from_to (gl_list_t list, size_t start_index, size_t end_index, static size_t gl_tree_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { gl_list_node_t node = gl_tree_search_from_to (list, start_index, end_index, elt); @@ -149,24 +149,24 @@ gl_tree_list_free (gl_list_t list) size_t i; for (i = list->table_size; i > 0; ) - { - gl_hash_entry_t entry = list->table[--i]; + { + gl_hash_entry_t entry = list->table[--i]; - while (entry != NULL) - { - gl_hash_entry_t next = entry->hash_next; + while (entry != NULL) + { + gl_hash_entry_t next = entry->hash_next; - if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC) - { - gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; + if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC) + { + gl_oset_t nodes = ((struct gl_multiple_nodes *) entry)->nodes; - gl_oset_free (nodes); - free (entry); - } + gl_oset_free (nodes); + free (entry); + } - entry = next; - } - } + entry = next; + } + } } /* Iterate across all elements in post-order. */ @@ -177,34 +177,34 @@ gl_tree_list_free (gl_list_t list) 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 (list->base.dispose_fn != NULL) - list->base.dispose_fn (node->value); - free (node); - } - /* Descend on right branch. */ - stack_ptr->rightp = true; - node = node->right; - stack_ptr++; + /* 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 (list->base.dispose_fn != NULL) + list->base.dispose_fn (node->value); + free (node); + } + /* Descend on right branch. */ + stack_ptr->rightp = true; + node = node->right; + stack_ptr++; } } done_iterate: diff --git a/lib/gl_array_list.c b/lib/gl_array_list.c index f82d01b0b..d75bf0a74 100644 --- a/lib/gl_array_list.c +++ b/lib/gl_array_list.c @@ -53,10 +53,10 @@ struct gl_list_impl static gl_list_t gl_array_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_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 = XMALLOC (struct gl_list_impl); @@ -74,11 +74,11 @@ gl_array_create_empty (gl_list_implementation_t implementation, static gl_list_t gl_array_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_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 = XMALLOC (struct gl_list_impl); @@ -178,7 +178,7 @@ gl_array_set_at (gl_list_t list, size_t position, const void *elt) static size_t gl_array_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { size_t count = list->count; @@ -190,38 +190,38 @@ gl_array_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, { gl_listelement_equals_fn equals = list->base.equals_fn; if (equals != NULL) - { - size_t i; - - for (i = start_index;;) - { - if (equals (elt, list->elements[i])) - return i; - i++; - if (i == end_index) - break; - } - } + { + size_t i; + + for (i = start_index;;) + { + if (equals (elt, list->elements[i])) + return i; + i++; + if (i == end_index) + break; + } + } else - { - size_t i; - - for (i = start_index;;) - { - if (elt == list->elements[i]) - return i; - i++; - if (i == end_index) - break; - } - } + { + size_t i; + + for (i = start_index;;) + { + if (elt == list->elements[i]) + return i; + i++; + if (i == end_index) + break; + } + } } return (size_t)(-1); } static gl_list_node_t gl_array_search_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { size_t index = gl_array_indexof_from_to (list, start_index, end_index, elt); return INDEX_TO_NODE (index); @@ -401,19 +401,19 @@ gl_array_list_free (gl_list_t list) if (list->elements != NULL) { if (list->base.dispose_fn != NULL) - { - size_t count = list->count; - - if (count > 0) - { - gl_listelement_dispose_fn dispose = list->base.dispose_fn; - const void **elements = list->elements; - - do - dispose (*elements++); - while (--count > 0); - } - } + { + size_t count = list->count; + + if (count > 0) + { + gl_listelement_dispose_fn dispose = list->base.dispose_fn; + const void **elements = list->elements; + + do + dispose (*elements++); + while (--count > 0); + } + } free (list->elements); } free (list); @@ -462,14 +462,14 @@ gl_array_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index) static bool gl_array_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) + const void **eltp, gl_list_node_t *nodep) { gl_list_t list = iterator->list; if (iterator->count != list->count) { if (iterator->count != list->count + 1) - /* Concurrent modifications were done on the list. */ - abort (); + /* Concurrent modifications were done on the list. */ + abort (); /* The last returned element was removed. */ iterator->count--; iterator->p = (const void **) iterator->p - 1; @@ -480,7 +480,7 @@ gl_array_iterator_next (gl_list_iterator_t *iterator, const void **p = (const void **) iterator->p; *eltp = *p; if (nodep != NULL) - *nodep = INDEX_TO_NODE (p - list->elements); + *nodep = INDEX_TO_NODE (p - list->elements); iterator->p = p + 1; return true; } @@ -497,9 +497,9 @@ gl_array_iterator_free (gl_list_iterator_t *iterator) static size_t gl_array_sortedlist_indexof_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { if (!(low <= high && high <= list->count)) /* Invalid arguments. */ @@ -507,47 +507,47 @@ gl_array_sortedlist_indexof_from_to (gl_list_t list, if (low < high) { /* At each loop iteration, low < high; for indices < low the values - are smaller than ELT; for indices >= high the values are greater - than ELT. So, if the element occurs in the list, it is at - low <= position < high. */ + are smaller than ELT; for indices >= high the values are greater + than ELT. So, if the element occurs in the list, it is at + low <= position < high. */ do - { - size_t mid = low + (high - low) / 2; /* low <= mid < high */ - int cmp = compar (list->elements[mid], elt); - - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid; - else /* cmp == 0 */ - { - /* We have an element equal to ELT at index MID. But we need - the minimal such index. */ - high = mid; - /* At each loop iteration, low <= high and - compar (list->elements[high], elt) == 0, - and we know that the first occurrence of the element is at - low <= position <= high. */ - while (low < high) - { - size_t mid2 = low + (high - low) / 2; /* low <= mid2 < high */ - int cmp2 = compar (list->elements[mid2], elt); - - if (cmp2 < 0) - low = mid2 + 1; - else if (cmp2 > 0) - /* The list was not sorted. */ - abort (); - else /* cmp2 == 0 */ - { - if (mid2 == low) - break; - high = mid2 - 1; - } - } - return low; - } - } + { + size_t mid = low + (high - low) / 2; /* low <= mid < high */ + int cmp = compar (list->elements[mid], elt); + + if (cmp < 0) + low = mid + 1; + else if (cmp > 0) + high = mid; + else /* cmp == 0 */ + { + /* We have an element equal to ELT at index MID. But we need + the minimal such index. */ + high = mid; + /* At each loop iteration, low <= high and + compar (list->elements[high], elt) == 0, + and we know that the first occurrence of the element is at + low <= position <= high. */ + while (low < high) + { + size_t mid2 = low + (high - low) / 2; /* low <= mid2 < high */ + int cmp2 = compar (list->elements[mid2], elt); + + if (cmp2 < 0) + low = mid2 + 1; + else if (cmp2 > 0) + /* The list was not sorted. */ + abort (); + else /* cmp2 == 0 */ + { + if (mid2 == low) + break; + high = mid2 - 1; + } + } + return low; + } + } while (low < high); /* Here low == high. */ } @@ -556,17 +556,17 @@ gl_array_sortedlist_indexof_from_to (gl_list_t list, static size_t gl_array_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { return gl_array_sortedlist_indexof_from_to (list, compar, 0, list->count, - elt); + elt); } static gl_list_node_t gl_array_sortedlist_search_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { size_t index = gl_array_sortedlist_indexof_from_to (list, compar, low, high, elt); @@ -575,7 +575,7 @@ gl_array_sortedlist_search_from_to (gl_list_t list, static gl_list_node_t gl_array_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { size_t index = gl_array_sortedlist_indexof_from_to (list, compar, 0, list->count, elt); @@ -584,7 +584,7 @@ gl_array_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, static gl_list_node_t gl_array_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { size_t count = list->count; size_t low = 0; @@ -598,21 +598,21 @@ gl_array_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, int cmp = compar (list->elements[mid], elt); if (cmp < 0) - low = mid + 1; + low = mid + 1; else if (cmp > 0) - high = mid; + high = mid; else /* cmp == 0 */ - { - low = mid; - break; - } + { + low = mid; + break; + } } return gl_array_add_at (list, low, elt); } static bool gl_array_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { size_t index = gl_array_sortedlist_indexof (list, compar, elt); if (index == (size_t)(-1)) diff --git a/lib/gl_array_oset.c b/lib/gl_array_oset.c index 83c563b74..959de3f22 100644 --- a/lib/gl_array_oset.c +++ b/lib/gl_array_oset.c @@ -42,8 +42,8 @@ struct gl_oset_impl static gl_oset_t gl_array_create_empty (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn) + gl_setelement_compar_fn compar_fn, + gl_setelement_dispose_fn dispose_fn) { struct gl_oset_impl *set = XMALLOC (struct gl_oset_impl); @@ -75,25 +75,25 @@ gl_array_indexof (gl_oset_t set, const void *elt) size_t high = count; /* At each loop iteration, low < high; for indices < low the values - are smaller than ELT; for indices >= high the values are greater - than ELT. So, if the element occurs in the list, it is at - low <= position < high. */ + are smaller than ELT; for indices >= high the values are greater + than ELT. So, if the element occurs in the list, it is at + low <= position < high. */ do - { - size_t mid = low + (high - low) / 2; /* low <= mid < high */ - int cmp = (compar != NULL - ? compar (set->elements[mid], elt) - : (set->elements[mid] > elt ? 1 : - set->elements[mid] < elt ? -1 : 0)); - - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid; - else /* cmp == 0 */ - /* We have an element equal to ELT at index MID. */ - return mid; - } + { + size_t mid = low + (high - low) / 2; /* low <= mid < high */ + int cmp = (compar != NULL + ? compar (set->elements[mid], elt) + : (set->elements[mid] > elt ? 1 : + set->elements[mid] < elt ? -1 : 0)); + + if (cmp < 0) + low = mid + 1; + else if (cmp > 0) + high = mid; + else /* cmp == 0 */ + /* We have an element equal to ELT at index MID. */ + return mid; + } while (low < high); } return (size_t)(-1); @@ -107,9 +107,9 @@ gl_array_search (gl_oset_t set, const void *elt) static bool gl_array_search_atleast (gl_oset_t set, - gl_setelement_threshold_fn threshold_fn, - const void *threshold, - const void **eltp) + gl_setelement_threshold_fn threshold_fn, + const void *threshold, + const void **eltp) { size_t count = set->count; @@ -119,37 +119,37 @@ gl_array_search_atleast (gl_oset_t set, size_t high = count; /* At each loop iteration, low < high; for indices < low the values are - smaller than THRESHOLD; for indices >= high the values are nonexistent. - So, if an element >= THRESHOLD occurs in the list, it is at - low <= position < high. */ + smaller than THRESHOLD; for indices >= high the values are nonexistent. + So, if an element >= THRESHOLD occurs in the list, it is at + low <= position < high. */ do - { - size_t mid = low + (high - low) / 2; /* low <= mid < high */ - - if (! threshold_fn (set->elements[mid], threshold)) - low = mid + 1; - else - { - /* We have an element >= THRESHOLD at index MID. But we need the - minimal such index. */ - high = mid; - /* At each loop iteration, low <= high and - compar (list->elements[high], value) >= 0, - and we know that the first occurrence of the element is at - low <= position <= high. */ - while (low < high) - { - size_t mid2 = low + (high - low) / 2; /* low <= mid2 < high */ - - if (! threshold_fn (set->elements[mid2], threshold)) - low = mid2 + 1; - else - high = mid2; - } - *eltp = set->elements[low]; - return true; - } - } + { + size_t mid = low + (high - low) / 2; /* low <= mid < high */ + + if (! threshold_fn (set->elements[mid], threshold)) + low = mid + 1; + else + { + /* We have an element >= THRESHOLD at index MID. But we need the + minimal such index. */ + high = mid; + /* At each loop iteration, low <= high and + compar (list->elements[high], value) >= 0, + and we know that the first occurrence of the element is at + low <= position <= high. */ + while (low < high) + { + size_t mid2 = low + (high - low) / 2; /* low <= mid2 < high */ + + if (! threshold_fn (set->elements[mid2], threshold)) + low = mid2 + 1; + else + high = mid2; + } + *eltp = set->elements[low]; + return true; + } + } while (low < high); } return false; @@ -224,24 +224,24 @@ gl_array_add (gl_oset_t set, const void *elt) size_t high = count; /* At each loop iteration, low < high; for indices < low the values - are smaller than ELT; for indices >= high the values are greater - than ELT. So, if the element occurs in the list, it is at - low <= position < high. */ + are smaller than ELT; for indices >= high the values are greater + than ELT. So, if the element occurs in the list, it is at + low <= position < high. */ do - { - size_t mid = low + (high - low) / 2; /* low <= mid < high */ - int cmp = (compar != NULL - ? compar (set->elements[mid], elt) - : (set->elements[mid] > elt ? 1 : - set->elements[mid] < elt ? -1 : 0)); - - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid; - else /* cmp == 0 */ - return false; - } + { + size_t mid = low + (high - low) / 2; /* low <= mid < high */ + int cmp = (compar != NULL + ? compar (set->elements[mid], elt) + : (set->elements[mid] > elt ? 1 : + set->elements[mid] < elt ? -1 : 0)); + + if (cmp < 0) + low = mid + 1; + else if (cmp > 0) + high = mid; + else /* cmp == 0 */ + return false; + } while (low < high); } gl_array_add_at (set, low, elt); @@ -267,19 +267,19 @@ gl_array_free (gl_oset_t set) if (set->elements != NULL) { if (set->base.dispose_fn != NULL) - { - size_t count = set->count; - - if (count > 0) - { - gl_setelement_dispose_fn dispose = set->base.dispose_fn; - const void **elements = set->elements; - - do - dispose (*elements++); - while (--count > 0); - } - } + { + size_t count = set->count; + + if (count > 0) + { + gl_setelement_dispose_fn dispose = set->base.dispose_fn; + const void **elements = set->elements; + + do + dispose (*elements++); + while (--count > 0); + } + } free (set->elements); } free (set); @@ -312,8 +312,8 @@ gl_array_iterator_next (gl_oset_iterator_t *iterator, const void **eltp) if (iterator->count != set->count) { if (iterator->count != set->count + 1) - /* Concurrent modifications were done on the set. */ - abort (); + /* Concurrent modifications were done on the set. */ + abort (); /* The last returned element was removed. */ iterator->count--; iterator->p = (const void **) iterator->p - 1; diff --git a/lib/gl_avltree_list.c b/lib/gl_avltree_list.c index f50b6f3dc..1f6c470ff 100644 --- a/lib/gl_avltree_list.c +++ b/lib/gl_avltree_list.c @@ -47,8 +47,8 @@ check_invariants (gl_list_node_t node, gl_list_node_t parent) if (!(node->parent == parent)) abort (); if (!(node->branch_size - == (node->left != NULL ? node->left->branch_size : 0) - + 1 + (node->right != NULL ? node->right->branch_size : 0))) + == (node->left != NULL ? node->left->branch_size : 0) + + 1 + (node->right != NULL ? node->right->branch_size : 0))) abort (); if (!(balance >= -1 && balance <= 1)) abort (); diff --git a/lib/gl_avltree_oset.c b/lib/gl_avltree_oset.c index 6ac058d8a..36e2d5811 100644 --- a/lib/gl_avltree_oset.c +++ b/lib/gl_avltree_oset.c @@ -26,9 +26,9 @@ /* 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)). + 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. + | 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 @@ -48,7 +48,7 @@ struct gl_oset_node_impl 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 */ + always = -1 or 0 or 1 */ const void *value; }; typedef struct gl_oset_node_impl * gl_oset_node_t; @@ -74,7 +74,7 @@ struct gl_oset_impl 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) + gl_oset_node_t node, int height_diff, gl_oset_node_t parent) { for (;;) { @@ -90,218 +90,218 @@ rebalance (gl_oset_t set, 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. */ + 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); + 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; + /* 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; - } + { + /* 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); - } + { + /* 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; + break; parent = node->parent; if (parent == NULL) - break; + break; } } @@ -327,7 +327,7 @@ gl_tree_add_first (gl_oset_t set, const void *elt) gl_oset_node_t node; for (node = set->root; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; new_node->parent = node; @@ -335,7 +335,7 @@ gl_tree_add_first (gl_oset_t set, const void *elt) /* Rebalance. */ if (node->right == NULL && node->parent != NULL) - rebalance (set, node, 1, node->parent); + rebalance (set, node, 1, node->parent); } set->count++; @@ -364,7 +364,7 @@ gl_tree_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt) else { for (node = node->left; node->right != NULL; ) - node = node->right; + node = node->right; node->right = new_node; node->balance++; height_inc = (node->left == NULL); @@ -401,7 +401,7 @@ gl_tree_add_after (gl_oset_t set, gl_oset_node_t node, const void *elt) else { for (node = node->right; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; node->balance--; height_inc = (node->right == NULL); @@ -427,38 +427,38 @@ gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node) gl_oset_node_t child = node->right; if (child != NULL) - child->parent = parent; + child->parent = parent; if (parent == NULL) - set->root = child; + set->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - rebalance (set, child, -1, parent); - } + { + 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. */ + 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; + set->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - rebalance (set, child, -1, parent); - } + { + if (parent->left == node) + parent->left = child; + else /* parent->right == node */ + parent->right = child; + + rebalance (set, child, -1, parent); + } } else { @@ -468,52 +468,52 @@ gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node) gl_oset_node_t child; for (subst = node->left; subst->right != NULL; ) - subst = subst->right; + 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. */ + 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; - } + { + 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.) */ + (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->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; + set->root = subst; else if (parent->left == node) - parent->left = subst; + parent->left = subst; else /* parent->right == node */ - parent->right = subst; + 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. */ + 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); } diff --git a/lib/gl_avltreehash_list.c b/lib/gl_avltreehash_list.c index ef739fca2..33f56fe74 100644 --- a/lib/gl_avltreehash_list.c +++ b/lib/gl_avltreehash_list.c @@ -75,8 +75,8 @@ check_invariants (gl_list_node_t node, gl_list_node_t parent) if (!(node->parent == parent)) abort (); if (!(node->branch_size - == (node->left != NULL ? node->left->branch_size : 0) - + 1 + (node->right != NULL ? node->right->branch_size : 0))) + == (node->left != NULL ? node->left->branch_size : 0) + + 1 + (node->right != NULL ? node->right->branch_size : 0))) abort (); if (!(balance >= -1 && balance <= 1)) abort (); diff --git a/lib/gl_carray_list.c b/lib/gl_carray_list.c index 8b43901e2..719b914d0 100644 --- a/lib/gl_carray_list.c +++ b/lib/gl_carray_list.c @@ -56,10 +56,10 @@ struct gl_list_impl static gl_list_t gl_carray_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_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 = XMALLOC (struct gl_list_impl); @@ -78,11 +78,11 @@ gl_carray_create_empty (gl_list_implementation_t implementation, static gl_list_t gl_carray_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_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 = XMALLOC (struct gl_list_impl); @@ -201,7 +201,7 @@ gl_carray_set_at (gl_list_t list, size_t position, const void *elt) static size_t gl_carray_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { size_t count = list->count; @@ -217,53 +217,53 @@ gl_carray_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, i_end = list->offset + end_index; if (i_end >= allocated) - i_end -= allocated; + i_end -= allocated; if (equals != NULL) - { - size_t i; - - i = list->offset + start_index; - if (i >= allocated) /* can only happen if start_index > 0 */ - i -= allocated; - - for (;;) - { - if (equals (elt, list->elements[i])) - return (i >= list->offset ? i : i + allocated) - list->offset; - i++; - if (i == allocated) - i = 0; - if (i == i_end) - break; - } - } + { + size_t i; + + i = list->offset + start_index; + if (i >= allocated) /* can only happen if start_index > 0 */ + i -= allocated; + + for (;;) + { + if (equals (elt, list->elements[i])) + return (i >= list->offset ? i : i + allocated) - list->offset; + i++; + if (i == allocated) + i = 0; + if (i == i_end) + break; + } + } else - { - size_t i; - - i = list->offset + start_index; - if (i >= allocated) /* can only happen if start_index > 0 */ - i -= allocated; - - for (;;) - { - if (elt == list->elements[i]) - return (i >= list->offset ? i : i + allocated) - list->offset; - i++; - if (i == allocated) - i = 0; - if (i == i_end) - break; - } - } + { + size_t i; + + i = list->offset + start_index; + if (i >= allocated) /* can only happen if start_index > 0 */ + i -= allocated; + + for (;;) + { + if (elt == list->elements[i]) + return (i >= list->offset ? i : i + allocated) - list->offset; + i++; + if (i == allocated) + i = 0; + if (i == i_end) + break; + } + } } return (size_t)(-1); } static gl_list_node_t gl_carray_search_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { size_t index = gl_carray_indexof_from_to (list, start_index, end_index, elt); return INDEX_TO_NODE (index); @@ -287,29 +287,29 @@ grow (gl_list_t list) { memory = (const void **) xmalloc (memory_size); if (memory == NULL) - /* Out of memory. */ - xalloc_die (); + /* Out of memory. */ + xalloc_die (); if (list->offset + list->count > list->allocated) - { - memcpy (memory, &list->elements[list->offset], - (list->allocated - list->offset) * sizeof (const void *)); - memcpy (memory + (list->allocated - list->offset), list->elements, - (list->offset + list->count - list->allocated) - * sizeof (const void *)); - - } + { + memcpy (memory, &list->elements[list->offset], + (list->allocated - list->offset) * sizeof (const void *)); + memcpy (memory + (list->allocated - list->offset), list->elements, + (list->offset + list->count - list->allocated) + * sizeof (const void *)); + + } else - memcpy (memory, &list->elements[list->offset], - list->count * sizeof (const void *)); + memcpy (memory, &list->elements[list->offset], + list->count * sizeof (const void *)); if (list->elements != NULL) - free (list->elements); + free (list->elements); } else { memory = (const void **) xrealloc (list->elements, memory_size); if (memory == NULL) - /* Out of memory. */ - xalloc_die (); + /* Out of memory. */ + xalloc_die (); } list->elements = memory; list->offset = 0; @@ -366,21 +366,21 @@ gl_carray_add_at (gl_list_t list, size_t position, const void *elt) i2 = list->offset + position; if (i2 >= list->allocated) - { - /* Here we must have list->offset > 0, hence list->allocated > 0. */ - size_t i1 = list->allocated - 1; - i2 -= list->allocated; - for (i = list->offset; i < i1; i++) - elements[i] = elements[i + 1]; - elements[i1] = elements[0]; - for (i = 0; i < i2; i++) - elements[i] = elements[i + 1]; - } + { + /* Here we must have list->offset > 0, hence list->allocated > 0. */ + size_t i1 = list->allocated - 1; + i2 -= list->allocated; + for (i = list->offset; i < i1; i++) + elements[i] = elements[i + 1]; + elements[i1] = elements[0]; + for (i = 0; i < i2; i++) + elements[i] = elements[i + 1]; + } else - { - for (i = list->offset; i < i2; i++) - elements[i] = elements[i + 1]; - } + { + for (i = list->offset; i < i2; i++) + elements[i] = elements[i + 1]; + } elements[i2] = elt; } else @@ -391,28 +391,28 @@ gl_carray_add_at (gl_list_t list, size_t position, const void *elt) i1 = list->offset + position; i3 = list->offset + count; if (i1 >= list->allocated) - { - i1 -= list->allocated; - i3 -= list->allocated; - for (i = i3; i > i1; i--) - elements[i] = elements[i - 1]; - } + { + i1 -= list->allocated; + i3 -= list->allocated; + for (i = i3; i > i1; i--) + elements[i] = elements[i - 1]; + } else if (i3 >= list->allocated) - { - /* Here we must have list->offset > 0, hence list->allocated > 0. */ - size_t i2 = list->allocated - 1; - i3 -= list->allocated; - for (i = i3; i > 0; i--) - elements[i] = elements[i - 1]; - elements[0] = elements[i2]; - for (i = i2; i > i1; i--) - elements[i] = elements[i - 1]; - } + { + /* Here we must have list->offset > 0, hence list->allocated > 0. */ + size_t i2 = list->allocated - 1; + i3 -= list->allocated; + for (i = i3; i > 0; i--) + elements[i] = elements[i - 1]; + elements[0] = elements[i2]; + for (i = i2; i > i1; i--) + elements[i] = elements[i - 1]; + } else - { - for (i = i3; i > i1; i--) - elements[i] = elements[i - 1]; - } + { + for (i = i3; i > i1; i--) + elements[i] = elements[i - 1]; + } elements[i1] = elt; } list->count = count + 1; @@ -462,25 +462,25 @@ gl_carray_remove_at (gl_list_t list, size_t position) i0 = list->offset; i2 = list->offset + position; if (i2 >= list->allocated) - { - /* Here we must have list->offset > 0, hence list->allocated > 0. */ - size_t i1 = list->allocated - 1; - i2 -= list->allocated; - if (list->base.dispose_fn != NULL) - list->base.dispose_fn (elements[i2]); - for (i = i2; i > 0; i--) - elements[i] = elements[i - 1]; - elements[0] = elements[i1]; - for (i = i1; i > i0; i--) - elements[i] = elements[i - 1]; - } + { + /* Here we must have list->offset > 0, hence list->allocated > 0. */ + size_t i1 = list->allocated - 1; + i2 -= list->allocated; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i2]); + for (i = i2; i > 0; i--) + elements[i] = elements[i - 1]; + elements[0] = elements[i1]; + for (i = i1; i > i0; i--) + elements[i] = elements[i - 1]; + } else - { - if (list->base.dispose_fn != NULL) - list->base.dispose_fn (elements[i2]); - for (i = i2; i > i0; i--) - elements[i] = elements[i - 1]; - } + { + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i2]); + for (i = i2; i > i0; i--) + elements[i] = elements[i - 1]; + } i0++; list->offset = (i0 == list->allocated ? 0 : i0); @@ -493,34 +493,34 @@ gl_carray_remove_at (gl_list_t list, size_t position) i1 = list->offset + position; i3 = list->offset + count - 1; if (i1 >= list->allocated) - { - i1 -= list->allocated; - i3 -= list->allocated; - if (list->base.dispose_fn != NULL) - list->base.dispose_fn (elements[i1]); - for (i = i1; i < i3; i++) - elements[i] = elements[i + 1]; - } + { + i1 -= list->allocated; + i3 -= list->allocated; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i1]); + for (i = i1; i < i3; i++) + elements[i] = elements[i + 1]; + } else if (i3 >= list->allocated) - { - /* Here we must have list->offset > 0, hence list->allocated > 0. */ - size_t i2 = list->allocated - 1; - i3 -= list->allocated; - if (list->base.dispose_fn != NULL) - list->base.dispose_fn (elements[i1]); - for (i = i1; i < i2; i++) - elements[i] = elements[i + 1]; - elements[i2] = elements[0]; - for (i = 0; i < i3; i++) - elements[i] = elements[i + 1]; - } + { + /* Here we must have list->offset > 0, hence list->allocated > 0. */ + size_t i2 = list->allocated - 1; + i3 -= list->allocated; + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i1]); + for (i = i1; i < i2; i++) + elements[i] = elements[i + 1]; + elements[i2] = elements[0]; + for (i = 0; i < i3; i++) + elements[i] = elements[i + 1]; + } else - { - if (list->base.dispose_fn != NULL) - list->base.dispose_fn (elements[i1]); - for (i = i1; i < i3; i++) - elements[i] = elements[i + 1]; - } + { + if (list->base.dispose_fn != NULL) + list->base.dispose_fn (elements[i1]); + for (i = i1; i < i3; i++) + elements[i] = elements[i + 1]; + } } list->count = count - 1; return true; @@ -554,38 +554,38 @@ gl_carray_list_free (gl_list_t list) if (list->elements != NULL) { if (list->base.dispose_fn != NULL) - { - size_t count = list->count; - - if (count > 0) - { - gl_listelement_dispose_fn dispose = list->base.dispose_fn; - const void **elements = list->elements; - size_t i1 = list->offset; - size_t i3 = list->offset + count - 1; - - if (i3 >= list->allocated) - { - /* Here we must have list->offset > 0, hence - list->allocated > 0. */ - size_t i2 = list->allocated - 1; - size_t i; - - i3 -= list->allocated; - for (i = i1; i <= i2; i++) - dispose (elements[i]); - for (i = 0; i <= i3; i++) - dispose (elements[i]); - } - else - { - size_t i; - - for (i = i1; i <= i3; i++) - dispose (elements[i]); - } - } - } + { + size_t count = list->count; + + if (count > 0) + { + gl_listelement_dispose_fn dispose = list->base.dispose_fn; + const void **elements = list->elements; + size_t i1 = list->offset; + size_t i3 = list->offset + count - 1; + + if (i3 >= list->allocated) + { + /* Here we must have list->offset > 0, hence + list->allocated > 0. */ + size_t i2 = list->allocated - 1; + size_t i; + + i3 -= list->allocated; + for (i = i1; i <= i2; i++) + dispose (elements[i]); + for (i = 0; i <= i3; i++) + dispose (elements[i]); + } + else + { + size_t i; + + for (i = i1; i <= i3; i++) + dispose (elements[i]); + } + } + } free (list->elements); } free (list); @@ -634,14 +634,14 @@ gl_carray_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index static bool gl_carray_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) + const void **eltp, gl_list_node_t *nodep) { gl_list_t list = iterator->list; if (iterator->count != list->count) { if (iterator->count != list->count + 1) - /* Concurrent modifications were done on the list. */ - abort (); + /* Concurrent modifications were done on the list. */ + abort (); /* The last returned element was removed. */ iterator->count--; iterator->i--; @@ -651,10 +651,10 @@ gl_carray_iterator_next (gl_list_iterator_t *iterator, { size_t i = list->offset + iterator->i; if (i >= list->allocated) - i -= list->allocated; + i -= list->allocated; *eltp = list->elements[i]; if (nodep != NULL) - *nodep = INDEX_TO_NODE (iterator->i); + *nodep = INDEX_TO_NODE (iterator->i); iterator->i++; return true; } @@ -671,9 +671,9 @@ gl_carray_iterator_free (gl_list_iterator_t *iterator) static size_t gl_carray_sortedlist_indexof_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { if (!(low <= high && high <= list->count)) /* Invalid arguments. */ @@ -681,61 +681,61 @@ gl_carray_sortedlist_indexof_from_to (gl_list_t list, if (low < high) { /* At each loop iteration, low < high; for indices < low the values - are smaller than ELT; for indices >= high the values are greater - than ELT. So, if the element occurs in the list, it is at - low <= position < high. */ + are smaller than ELT; for indices >= high the values are greater + than ELT. So, if the element occurs in the list, it is at + low <= position < high. */ do - { - size_t mid = low + (high - low) / 2; /* low <= mid < high */ - size_t i_mid; - int cmp; - - i_mid = list->offset + mid; - if (i_mid >= list->allocated) - i_mid -= list->allocated; - - cmp = compar (list->elements[i_mid], elt); - - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid; - else /* cmp == 0 */ - { - /* We have an element equal to ELT at index MID. But we need - the minimal such index. */ - high = mid; - /* At each loop iteration, low <= high and - compar (list->elements[i_high], elt) == 0, - and we know that the first occurrence of the element is at - low <= position <= high. */ - while (low < high) - { - size_t mid2 = low + (high - low) / 2; /* low <= mid2 < high */ - size_t i_mid2; - int cmp2; - - i_mid2 = list->offset + mid2; - if (i_mid2 >= list->allocated) - i_mid2 -= list->allocated; - - cmp2 = compar (list->elements[i_mid2], elt); - - if (cmp2 < 0) - low = mid2 + 1; - else if (cmp2 > 0) - /* The list was not sorted. */ - abort (); - else /* cmp2 == 0 */ - { - if (mid2 == low) - break; - high = mid2 - 1; - } - } - return low; - } - } + { + size_t mid = low + (high - low) / 2; /* low <= mid < high */ + size_t i_mid; + int cmp; + + i_mid = list->offset + mid; + if (i_mid >= list->allocated) + i_mid -= list->allocated; + + cmp = compar (list->elements[i_mid], elt); + + if (cmp < 0) + low = mid + 1; + else if (cmp > 0) + high = mid; + else /* cmp == 0 */ + { + /* We have an element equal to ELT at index MID. But we need + the minimal such index. */ + high = mid; + /* At each loop iteration, low <= high and + compar (list->elements[i_high], elt) == 0, + and we know that the first occurrence of the element is at + low <= position <= high. */ + while (low < high) + { + size_t mid2 = low + (high - low) / 2; /* low <= mid2 < high */ + size_t i_mid2; + int cmp2; + + i_mid2 = list->offset + mid2; + if (i_mid2 >= list->allocated) + i_mid2 -= list->allocated; + + cmp2 = compar (list->elements[i_mid2], elt); + + if (cmp2 < 0) + low = mid2 + 1; + else if (cmp2 > 0) + /* The list was not sorted. */ + abort (); + else /* cmp2 == 0 */ + { + if (mid2 == low) + break; + high = mid2 - 1; + } + } + return low; + } + } while (low < high); /* Here low == high. */ } @@ -744,17 +744,17 @@ gl_carray_sortedlist_indexof_from_to (gl_list_t list, static size_t gl_carray_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { return gl_carray_sortedlist_indexof_from_to (list, compar, 0, list->count, - elt); + elt); } static gl_list_node_t gl_carray_sortedlist_search_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { size_t index = gl_carray_sortedlist_indexof_from_to (list, compar, low, high, elt); @@ -763,7 +763,7 @@ gl_carray_sortedlist_search_from_to (gl_list_t list, static gl_list_node_t gl_carray_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { size_t index = gl_carray_sortedlist_indexof_from_to (list, compar, 0, list->count, elt); @@ -772,7 +772,7 @@ gl_carray_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, static gl_list_node_t gl_carray_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { size_t count = list->count; size_t low = 0; @@ -788,26 +788,26 @@ gl_carray_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, i_mid = list->offset + mid; if (i_mid >= list->allocated) - i_mid -= list->allocated; + i_mid -= list->allocated; cmp = compar (list->elements[i_mid], elt); if (cmp < 0) - low = mid + 1; + low = mid + 1; else if (cmp > 0) - high = mid; + high = mid; else /* cmp == 0 */ - { - low = mid; - break; - } + { + low = mid; + break; + } } return gl_carray_add_at (list, low, elt); } static bool gl_carray_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, - const void *elt) + const void *elt) { size_t index = gl_carray_sortedlist_indexof (list, compar, elt); if (index == (size_t)(-1)) diff --git a/lib/gl_linkedhash_list.c b/lib/gl_linkedhash_list.c index 7afecb59a..c83c056cf 100644 --- a/lib/gl_linkedhash_list.c +++ b/lib/gl_linkedhash_list.c @@ -73,14 +73,14 @@ remove_from_bucket (gl_list_t list, gl_list_node_t node) for (p = &list->table[bucket]; ; p = &(*p)->hash_next) { if (*p == &node->h) - { - *p = node->h.hash_next; - break; - } + { + *p = node->h.hash_next; + break; + } if (*p == NULL) - /* node is not in the right bucket. Did the hash codes - change inadvertently? */ - abort (); + /* node is not in the right bucket. Did the hash codes + change inadvertently? */ + abort (); } } diff --git a/lib/gl_list.c b/lib/gl_list.c index d99ed4e26..369615e0b 100644 --- a/lib/gl_list.c +++ b/lib/gl_list.c @@ -28,39 +28,39 @@ 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_listelement_equals_fn equals_fn, + gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, + bool allow_duplicates) { return implementation->create_empty (implementation, equals_fn, hashcode_fn, - dispose_fn, allow_duplicates); + dispose_fn, allow_duplicates); } 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_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->create (implementation, equals_fn, hashcode_fn, - dispose_fn, allow_duplicates, count, contents); + dispose_fn, allow_duplicates, count, contents); } size_t gl_list_size (gl_list_t list) { return ((const struct gl_list_impl_base *) list)->vtable - ->size (list); + ->size (list); } 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); + ->node_value (list, node); } void @@ -74,28 +74,28 @@ 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); + ->next_node (list, node); } 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); + ->previous_node (list, node); } 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); + ->get_at (list, position); } gl_list_node_t gl_list_set_at (gl_list_t list, size_t position, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->set_at (list, position, elt); + ->set_at (list, position, elt); } gl_list_node_t @@ -103,7 +103,7 @@ 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); + ->search_from_to (list, 0, size, elt); } gl_list_node_t @@ -111,14 +111,14 @@ 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); + ->search_from_to (list, start_index, size, elt); } 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); + ->search_from_to (list, start_index, end_index, elt); } size_t @@ -126,7 +126,7 @@ 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); + ->indexof_from_to (list, 0, size, elt); } size_t @@ -134,70 +134,70 @@ 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); + ->indexof_from_to (list, start_index, size, elt); } 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); + ->indexof_from_to (list, start_index, end_index, elt); } gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_first (list, elt); + ->add_first (list, elt); } gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_last (list, elt); + ->add_last (list, elt); } gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_before (list, node, elt); + ->add_before (list, node, elt); } gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_after (list, node, elt); + ->add_after (list, node, elt); } gl_list_node_t gl_list_add_at (gl_list_t list, size_t position, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_at (list, position, elt); + ->add_at (list, position, elt); } 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); + ->remove_node (list, node); } 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); + ->remove_at (list, position); } bool gl_list_remove (gl_list_t list, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->remove_elt (list, elt); + ->remove_elt (list, elt); } void @@ -210,19 +210,19 @@ gl_list_iterator_t gl_list_iterator (gl_list_t list) { return ((const struct gl_list_impl_base *) list)->vtable - ->iterator (list); + ->iterator (list); } 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); + ->iterator_from_to (list, start_index, end_index); } bool gl_list_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) + const void **eltp, gl_list_node_t *nodep) { return iterator->vtable->iterator_next (iterator, eltp, nodep); } @@ -237,44 +237,44 @@ 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); + ->sortedlist_search (list, compar, elt); } 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); + ->sortedlist_search_from_to (list, compar, start_index, end_index, + elt); } 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); + ->sortedlist_indexof (list, compar, elt); } 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); + ->sortedlist_indexof_from_to (list, compar, start_index, end_index, + elt); } gl_list_node_t gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_add (list, compar, elt); + ->sortedlist_add (list, compar, elt); } 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); + ->sortedlist_remove (list, compar, elt); } #endif diff --git a/lib/gl_list.h b/lib/gl_list.h index 41fdfc864..53cfc5398 100644 --- a/lib/gl_list.h +++ b/lib/gl_list.h @@ -57,8 +57,8 @@ extern "C" { n elements: Operation ARRAY LINKED TREE LINKEDHASH TREEHASH - CARRAY with|without with|without - duplicates duplicates + 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) @@ -130,10 +130,10 @@ typedef const struct gl_list_implementation * gl_list_implementation_t; ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in the list. The implementation may verify this at runtime. */ 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); + 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, @@ -147,11 +147,11 @@ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation, COUNT is the number of initial elements. CONTENTS[0..COUNT-1] is the initial contents. */ 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); + 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); @@ -161,7 +161,7 @@ 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. */ extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node, - const void *elt); + const void *elt); /* 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. */ @@ -179,7 +179,7 @@ extern const void * gl_list_get_at (gl_list_t list, size_t position); POSITION must be >= 0 and < gl_list_size (list). Return its node. */ extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position, - const void *elt); + const void *elt); /* Search whether an element is already in the list. Return its node if found, or NULL if not present in the list. */ @@ -189,15 +189,15 @@ extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt); 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); + 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); + 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. */ @@ -207,14 +207,14 @@ extern size_t gl_list_indexof (gl_list_t list, const void *elt); 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); + 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); + size_t start_index, size_t end_index, + const void *elt); /* Add an element as the first element of the list. Return its node. */ @@ -227,17 +227,17 @@ extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt); /* Add an element before a given element node of the list. Return its node. */ extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node, - const void *elt); + const void *elt); /* Add an element after a given element node of the list. Return its node. */ extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node, - const void *elt); + const void *elt); /* Add an element add a given position in the list. POSITION must be >= 0 and <= gl_list_size (list). */ extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position, - const void *elt); + const void *elt); /* Remove an element from the list. Return true. */ @@ -285,14 +285,14 @@ extern gl_list_iterator_t gl_list_iterator (gl_list_t 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); + 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); + const void **eltp, gl_list_node_t *nodep); /* Free an iterator. */ extern void gl_list_iterator_free (gl_list_iterator_t *iterator); @@ -312,8 +312,8 @@ typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2); 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); + 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. @@ -324,10 +324,10 @@ extern gl_list_node_t gl_sortedlist_search (gl_list_t 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); + 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. @@ -335,8 +335,8 @@ extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t 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); + 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. @@ -347,17 +347,17 @@ extern size_t gl_sortedlist_indexof (gl_list_t 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); + 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. */ extern gl_list_node_t gl_sortedlist_add (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); + gl_listelement_compar_fn compar, + const void *elt); /* Search and remove an element from the list. The list is assumed to be sorted with COMPAR. @@ -365,8 +365,8 @@ extern gl_list_node_t gl_sortedlist_add (gl_list_t list, 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); + gl_listelement_compar_fn compar, + const void *elt); /* ------------------------ Implementation Details ------------------------ */ @@ -374,16 +374,16 @@ struct gl_list_implementation { /* gl_list_t functions. */ gl_list_t (*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_listelement_equals_fn equals_fn, + gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, + bool allow_duplicates); gl_list_t (*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_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); void (*node_set_value) (gl_list_t list, gl_list_node_t node, const void *elt); @@ -392,17 +392,17 @@ struct gl_list_implementation const void * (*get_at) (gl_list_t list, size_t position); gl_list_node_t (*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 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); + size_t end_index, const void *elt); gl_list_node_t (*add_first) (gl_list_t list, const void *elt); gl_list_node_t (*add_last) (gl_list_t list, const void *elt); gl_list_node_t (*add_before) (gl_list_t list, gl_list_node_t node, - const void *elt); + const void *elt); gl_list_node_t (*add_after) (gl_list_t list, gl_list_node_t node, - const void *elt); + const void *elt); gl_list_node_t (*add_at) (gl_list_t list, size_t position, - const void *elt); + 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); @@ -410,33 +410,33 @@ struct gl_list_implementation /* 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); + size_t start_index, + size_t end_index); bool (*iterator_next) (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep); + 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_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); + 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); + 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_listelement_compar_fn compar, + size_t start_index, size_t end_index, + const void *elt); gl_list_node_t (*sortedlist_add) (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); + gl_listelement_compar_fn compar, + const void *elt); bool (*sortedlist_remove) (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt); + gl_listelement_compar_fn compar, + const void *elt); }; struct gl_list_impl_base @@ -457,26 +457,26 @@ struct gl_list_impl_base # define gl_list_create_empty gl_list_create_empty_inline static 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_listelement_equals_fn equals_fn, + gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, + bool allow_duplicates) { return implementation->create_empty (implementation, equals_fn, hashcode_fn, - dispose_fn, allow_duplicates); + dispose_fn, allow_duplicates); } # define gl_list_create gl_list_create_inline static 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_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->create (implementation, equals_fn, hashcode_fn, - dispose_fn, allow_duplicates, count, contents); + dispose_fn, allow_duplicates, count, contents); } # define gl_list_size gl_list_size_inline @@ -484,7 +484,7 @@ static inline size_t gl_list_size (gl_list_t list) { return ((const struct gl_list_impl_base *) list)->vtable - ->size (list); + ->size (list); } # define gl_list_node_value gl_list_node_value_inline @@ -492,7 +492,7 @@ static 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); + ->node_value (list, node); } # define gl_list_node_set_value gl_list_node_set_value_inline @@ -508,7 +508,7 @@ static 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); + ->next_node (list, node); } # define gl_list_previous_node gl_list_previous_node_inline @@ -516,7 +516,7 @@ static 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); + ->previous_node (list, node); } # define gl_list_get_at gl_list_get_at_inline @@ -524,7 +524,7 @@ static 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); + ->get_at (list, position); } # define gl_list_set_at gl_list_set_at_inline @@ -532,7 +532,7 @@ static inline gl_list_node_t gl_list_set_at (gl_list_t list, size_t position, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->set_at (list, position, elt); + ->set_at (list, position, elt); } # define gl_list_search gl_list_search_inline @@ -541,7 +541,7 @@ 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); + ->search_from_to (list, 0, size, elt); } # define gl_list_search_from gl_list_search_from_inline @@ -550,16 +550,16 @@ 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); + ->search_from_to (list, start_index, size, elt); } # define gl_list_search_from_to gl_list_search_from_to_inline static 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) + const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->search_from_to (list, start_index, end_index, elt); + ->search_from_to (list, start_index, end_index, elt); } # define gl_list_indexof gl_list_indexof_inline @@ -568,7 +568,7 @@ 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); + ->indexof_from_to (list, 0, size, elt); } # define gl_list_indexof_from gl_list_indexof_from_inline @@ -577,16 +577,16 @@ 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); + ->indexof_from_to (list, start_index, size, elt); } # define gl_list_indexof_from_to gl_list_indexof_from_to_inline static inline size_t gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->indexof_from_to (list, start_index, end_index, elt); + ->indexof_from_to (list, start_index, end_index, elt); } # define gl_list_add_first gl_list_add_first_inline @@ -594,7 +594,7 @@ static inline gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_first (list, elt); + ->add_first (list, elt); } # define gl_list_add_last gl_list_add_last_inline @@ -602,7 +602,7 @@ static inline gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_last (list, elt); + ->add_last (list, elt); } # define gl_list_add_before gl_list_add_before_inline @@ -610,7 +610,7 @@ static inline gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_before (list, node, elt); + ->add_before (list, node, elt); } # define gl_list_add_after gl_list_add_after_inline @@ -618,7 +618,7 @@ static inline gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_after (list, node, elt); + ->add_after (list, node, elt); } # define gl_list_add_at gl_list_add_at_inline @@ -626,7 +626,7 @@ static inline gl_list_node_t gl_list_add_at (gl_list_t list, size_t position, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->add_at (list, position, elt); + ->add_at (list, position, elt); } # define gl_list_remove_node gl_list_remove_node_inline @@ -634,7 +634,7 @@ static 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); + ->remove_node (list, node); } # define gl_list_remove_at gl_list_remove_at_inline @@ -642,7 +642,7 @@ static 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); + ->remove_at (list, position); } # define gl_list_remove gl_list_remove_inline @@ -650,7 +650,7 @@ static 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); + ->remove_elt (list, elt); } # define gl_list_free gl_list_free_inline @@ -665,7 +665,7 @@ static inline gl_list_iterator_t gl_list_iterator (gl_list_t list) { return ((const struct gl_list_impl_base *) list)->vtable - ->iterator (list); + ->iterator (list); } # define gl_list_iterator_from_to gl_list_iterator_from_to_inline @@ -673,13 +673,13 @@ static 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); + ->iterator_from_to (list, start_index, end_index); } # define gl_list_iterator_next gl_list_iterator_next_inline static inline bool gl_list_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) + const void **eltp, gl_list_node_t *nodep) { return iterator->vtable->iterator_next (iterator, eltp, nodep); } @@ -696,7 +696,7 @@ static 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); + ->sortedlist_search (list, compar, elt); } # define gl_sortedlist_search_from_to gl_sortedlist_search_from_to_inline @@ -704,8 +704,8 @@ static 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); + ->sortedlist_search_from_to (list, compar, start_index, end_index, + elt); } # define gl_sortedlist_indexof gl_sortedlist_indexof_inline @@ -713,7 +713,7 @@ static 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); + ->sortedlist_indexof (list, compar, elt); } # define gl_sortedlist_indexof_from_to gl_sortedlist_indexof_from_to_inline @@ -721,8 +721,8 @@ static 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); + ->sortedlist_indexof_from_to (list, compar, start_index, end_index, + elt); } # define gl_sortedlist_add gl_sortedlist_add_inline @@ -730,7 +730,7 @@ static inline gl_list_node_t gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) { return ((const struct gl_list_impl_base *) list)->vtable - ->sortedlist_add (list, compar, elt); + ->sortedlist_add (list, compar, elt); } # define gl_sortedlist_remove gl_sortedlist_remove_inline @@ -738,7 +738,7 @@ static 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); + ->sortedlist_remove (list, compar, elt); } #endif diff --git a/lib/gl_oset.c b/lib/gl_oset.c index 6ec8fb07a..7182f282a 100644 --- a/lib/gl_oset.c +++ b/lib/gl_oset.c @@ -28,8 +28,8 @@ 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_setelement_compar_fn compar_fn, + gl_setelement_dispose_fn dispose_fn) { return implementation->create_empty (implementation, compar_fn, dispose_fn); } @@ -48,11 +48,11 @@ gl_oset_search (gl_oset_t set, const void *elt) bool gl_oset_search_atleast (gl_oset_t set, - gl_setelement_threshold_fn threshold_fn, - const void *threshold, const void **eltp) + 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); + ->search_atleast (set, threshold_fn, threshold, eltp); } bool @@ -65,7 +65,7 @@ bool gl_oset_remove (gl_oset_t set, const void *elt) { return ((const struct gl_oset_impl_base *) set)->vtable - ->remove_elt (set, elt); + ->remove_elt (set, elt); } void diff --git a/lib/gl_oset.h b/lib/gl_oset.h index a609a134c..42f46ecbc 100644 --- a/lib/gl_oset.h +++ b/lib/gl_oset.h @@ -90,8 +90,8 @@ typedef const struct gl_oset_implementation * gl_oset_implementation_t; COMPAR_FN is an element comparison function or NULL. DISPOSE_FN is an element disposal function or NULL. */ 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); + 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); @@ -106,9 +106,9 @@ extern bool gl_oset_search (gl_oset_t set, const void *elt); 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); + 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. */ @@ -149,7 +149,7 @@ 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); + const void **eltp); /* Free an iterator. */ extern void gl_oset_iterator_free (gl_oset_iterator_t *iterator); @@ -160,13 +160,13 @@ struct gl_oset_implementation { /* gl_oset_t functions. */ gl_oset_t (*create_empty) (gl_oset_implementation_t implementation, - gl_setelement_compar_fn compar_fn, - gl_setelement_dispose_fn dispose_fn); + 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); + gl_setelement_threshold_fn threshold_fn, + const void *threshold, const void **eltp); bool (*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); @@ -192,8 +192,8 @@ struct gl_oset_impl_base # define gl_oset_create_empty gl_oset_create_empty_inline static 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_setelement_compar_fn compar_fn, + gl_setelement_dispose_fn dispose_fn) { return implementation->create_empty (implementation, compar_fn, dispose_fn); } @@ -215,11 +215,11 @@ gl_oset_search (gl_oset_t set, const void *elt) # define gl_oset_search_atleast gl_oset_search_atleast_inline static inline bool gl_oset_search_atleast (gl_oset_t set, - gl_setelement_threshold_fn threshold_fn, - const void *threshold, const void **eltp) + 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); + ->search_atleast (set, threshold_fn, threshold, eltp); } # define gl_oset_add gl_oset_add_inline @@ -234,7 +234,7 @@ static 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); + ->remove_elt (set, elt); } # define gl_oset_free gl_oset_free_inline diff --git a/lib/gl_rbtree_list.c b/lib/gl_rbtree_list.c index b4f37e661..e584702c5 100644 --- a/lib/gl_rbtree_list.c +++ b/lib/gl_rbtree_list.c @@ -46,8 +46,8 @@ check_invariants (gl_list_node_t node, gl_list_node_t parent) if (!(node->parent == parent)) abort (); if (!(node->branch_size - == (node->left != NULL ? node->left->branch_size : 0) - + 1 + (node->right != NULL ? node->right->branch_size : 0))) + == (node->left != NULL ? node->left->branch_size : 0) + + 1 + (node->right != NULL ? node->right->branch_size : 0))) abort (); if (!(node->color == BLACK || node->color == RED)) abort (); diff --git a/lib/gl_rbtree_oset.c b/lib/gl_rbtree_oset.c index f019891e2..6247972a3 100644 --- a/lib/gl_rbtree_oset.c +++ b/lib/gl_rbtree_oset.c @@ -76,11 +76,11 @@ struct gl_oset_impl /* Rotate left a subtree. - B D - / \ / \ - A D --> B E - / \ / \ - C E A C + B D + / \ / \ + A D --> B E + / \ / \ + C E A C Change the tree structure, update the branch sizes. The caller must update the colors and register D as child of its parent. */ @@ -102,11 +102,11 @@ rotate_left (gl_oset_node_t b_node, gl_oset_node_t d_node) /* Rotate right a subtree. - D B - / \ / \ - B E --> A D - / \ / \ - A C C E + D B + / \ / \ + B E --> A D + / \ / \ + A C C E Change the tree structure, update the branch sizes. The caller must update the colors and register B as child of its parent. */ @@ -135,118 +135,118 @@ rebalance_after_add (gl_oset_t set, gl_oset_node_t node, gl_oset_node_t parent) for (;;) { /* At this point, parent = node->parent != NULL. - Think of node->color being RED (although node->color is not yet - assigned.) */ + Think of node->color being RED (although node->color is not yet + assigned.) */ gl_oset_node_t grandparent; gl_oset_node_t uncle; if (parent->color == BLACK) - { - /* A RED color for node is acceptable. */ - node->color = RED; - return; - } + { + /* A RED color for node is acceptable. */ + node->color = RED; + return; + } grandparent = parent->parent; /* Since parent is RED, we know that - grandparent is != NULL and colored BLACK. */ + grandparent is != NULL and colored BLACK. */ if (grandparent->left == parent) - uncle = grandparent->right; + uncle = grandparent->right; else if (grandparent->right == parent) - uncle = grandparent->left; + uncle = grandparent->left; else - abort (); + abort (); if (uncle != NULL && uncle->color == RED) - { - /* Change grandparent from BLACK to RED, and - change parent and uncle from RED to BLACK. - This makes it acceptable for node to be RED. */ - node->color = RED; - parent->color = uncle->color = BLACK; - node = grandparent; - } + { + /* Change grandparent from BLACK to RED, and + change parent and uncle from RED to BLACK. + This makes it acceptable for node to be RED. */ + node->color = RED; + parent->color = uncle->color = BLACK; + node = grandparent; + } else - { - /* grandparent and uncle are BLACK. parent is RED. node wants - to be RED too. - In this case, recoloring is not sufficient. Need to perform - one or two rotations. */ - gl_oset_node_t *grandparentp; - - if (grandparent->parent == NULL) - grandparentp = &set->root; - else if (grandparent->parent->left == grandparent) - grandparentp = &grandparent->parent->left; - else if (grandparent->parent->right == grandparent) - grandparentp = &grandparent->parent->right; - else - abort (); - - if (grandparent->left == parent) - { - if (parent->right == node) - { - /* Rotation between node and parent. */ - grandparent->left = rotate_left (parent, node); - node = parent; - parent = grandparent->left; - } - /* grandparent and uncle are BLACK. parent and node want to be - RED. parent = grandparent->left. node = parent->left. - - grandparent parent - bh+1 bh+1 - / \ / \ - parent uncle --> node grandparent - bh bh bh bh - / \ / \ - node C C uncle - bh bh bh bh - */ - *grandparentp = rotate_right (parent, grandparent); - parent->color = BLACK; - node->color = grandparent->color = RED; - } - else /* grandparent->right == parent */ - { - if (parent->left == node) - { - /* Rotation between node and parent. */ - grandparent->right = rotate_right (node, parent); - node = parent; - parent = grandparent->right; - } - /* grandparent and uncle are BLACK. parent and node want to be - RED. parent = grandparent->right. node = parent->right. - - grandparent parent - bh+1 bh+1 - / \ / \ - uncle parent --> grandparent node - bh bh bh bh - / \ / \ - C node uncle C - bh bh bh bh - */ - *grandparentp = rotate_left (grandparent, parent); - parent->color = BLACK; - node->color = grandparent->color = RED; - } - return; - } + { + /* grandparent and uncle are BLACK. parent is RED. node wants + to be RED too. + In this case, recoloring is not sufficient. Need to perform + one or two rotations. */ + gl_oset_node_t *grandparentp; + + if (grandparent->parent == NULL) + grandparentp = &set->root; + else if (grandparent->parent->left == grandparent) + grandparentp = &grandparent->parent->left; + else if (grandparent->parent->right == grandparent) + grandparentp = &grandparent->parent->right; + else + abort (); + + if (grandparent->left == parent) + { + if (parent->right == node) + { + /* Rotation between node and parent. */ + grandparent->left = rotate_left (parent, node); + node = parent; + parent = grandparent->left; + } + /* grandparent and uncle are BLACK. parent and node want to be + RED. parent = grandparent->left. node = parent->left. + + grandparent parent + bh+1 bh+1 + / \ / \ + parent uncle --> node grandparent + bh bh bh bh + / \ / \ + node C C uncle + bh bh bh bh + */ + *grandparentp = rotate_right (parent, grandparent); + parent->color = BLACK; + node->color = grandparent->color = RED; + } + else /* grandparent->right == parent */ + { + if (parent->left == node) + { + /* Rotation between node and parent. */ + grandparent->right = rotate_right (node, parent); + node = parent; + parent = grandparent->right; + } + /* grandparent and uncle are BLACK. parent and node want to be + RED. parent = grandparent->right. node = parent->right. + + grandparent parent + bh+1 bh+1 + / \ / \ + uncle parent --> grandparent node + bh bh bh bh + / \ / \ + C node uncle C + bh bh bh bh + */ + *grandparentp = rotate_left (grandparent, parent); + parent->color = BLACK; + node->color = grandparent->color = RED; + } + return; + } /* Start again with a new (node, parent) pair. */ parent = node->parent; if (parent == NULL) - { - /* Change node's color from RED to BLACK. This increases the - tree's black-height. */ - node->color = BLACK; - return; - } + { + /* Change node's color from RED to BLACK. This increases the + tree's black-height. */ + node->color = BLACK; + return; + } } } @@ -260,280 +260,280 @@ rebalance_after_remove (gl_oset_t set, gl_oset_node_t child, gl_oset_node_t pare for (;;) { /* At this point, we reduced the black-height of the CHILD subtree by 1. - To make up, either look for a possibility to turn a RED to a BLACK - node, or try to reduce the black-height tree of CHILD's sibling - subtree as well. */ + To make up, either look for a possibility to turn a RED to a BLACK + node, or try to reduce the black-height tree of CHILD's sibling + subtree as well. */ gl_oset_node_t *parentp; if (parent->parent == NULL) - parentp = &set->root; + parentp = &set->root; else if (parent->parent->left == parent) - parentp = &parent->parent->left; + parentp = &parent->parent->left; else if (parent->parent->right == parent) - parentp = &parent->parent->right; + parentp = &parent->parent->right; else - abort (); + abort (); if (parent->left == child) - { - gl_oset_node_t sibling = parent->right; - /* sibling's black-height is >= 1. In particular, - sibling != NULL. - - parent - / \ - child sibling - bh bh+1 - */ - - if (sibling->color == RED) - { - /* sibling is RED, hence parent is BLACK and sibling's children - are non-NULL and BLACK. - - parent sibling - bh+2 bh+2 - / \ / \ - child sibling --> parent SR - bh bh+1 bh+1 bh+1 - / \ / \ - SL SR child SL - bh+1 bh+1 bh bh+1 - */ - *parentp = rotate_left (parent, sibling); - parent->color = RED; - sibling->color = BLACK; - - /* Concentrate on the subtree of parent. The new sibling is - one of the old sibling's children, and known to be BLACK. */ - parentp = &sibling->left; - sibling = parent->right; - } - /* Now we know that sibling is BLACK. - - parent - / \ - child sibling - bh bh+1 - */ - if (sibling->right != NULL && sibling->right->color == RED) - { - /* - parent sibling - bh+1|bh+2 bh+1|bh+2 - / \ / \ - child sibling --> parent SR - bh bh+1 bh+1 bh+1 - / \ / \ - SL SR child SL - bh bh bh bh - */ - *parentp = rotate_left (parent, sibling); - sibling->color = parent->color; - parent->color = BLACK; - sibling->right->color = BLACK; - return; - } - else if (sibling->left != NULL && sibling->left->color == RED) - { - /* - parent parent - bh+1|bh+2 bh+1|bh+2 - / \ / \ - child sibling --> child SL - bh bh+1 bh bh+1 - / \ / \ - SL SR SLL sibling - bh bh bh bh - / \ / \ - SLL SLR SLR SR - bh bh bh bh - - where SLL, SLR, SR are all black. - */ - parent->right = rotate_right (sibling->left, sibling); - /* Change sibling from BLACK to RED and SL from RED to BLACK. */ - sibling->color = RED; - sibling = parent->right; - sibling->color = BLACK; - - /* Now do as in the previous case. */ - *parentp = rotate_left (parent, sibling); - sibling->color = parent->color; - parent->color = BLACK; - sibling->right->color = BLACK; - return; - } - else - { - if (parent->color == BLACK) - { - /* Change sibling from BLACK to RED. Then the entire - subtree at parent has decreased its black-height. - parent parent - bh+2 bh+1 - / \ / \ - child sibling --> child sibling - bh bh+1 bh bh - */ - sibling->color = RED; - - child = parent; - } - else - { - /* Change parent from RED to BLACK, but compensate by - changing sibling from BLACK to RED. - parent parent - bh+1 bh+1 - / \ / \ - child sibling --> child sibling - bh bh+1 bh bh - */ - parent->color = BLACK; - sibling->color = RED; - return; - } - } - } + { + gl_oset_node_t sibling = parent->right; + /* sibling's black-height is >= 1. In particular, + sibling != NULL. + + parent + / \ + child sibling + bh bh+1 + */ + + if (sibling->color == RED) + { + /* sibling is RED, hence parent is BLACK and sibling's children + are non-NULL and BLACK. + + parent sibling + bh+2 bh+2 + / \ / \ + child sibling --> parent SR + bh bh+1 bh+1 bh+1 + / \ / \ + SL SR child SL + bh+1 bh+1 bh bh+1 + */ + *parentp = rotate_left (parent, sibling); + parent->color = RED; + sibling->color = BLACK; + + /* Concentrate on the subtree of parent. The new sibling is + one of the old sibling's children, and known to be BLACK. */ + parentp = &sibling->left; + sibling = parent->right; + } + /* Now we know that sibling is BLACK. + + parent + / \ + child sibling + bh bh+1 + */ + if (sibling->right != NULL && sibling->right->color == RED) + { + /* + parent sibling + bh+1|bh+2 bh+1|bh+2 + / \ / \ + child sibling --> parent SR + bh bh+1 bh+1 bh+1 + / \ / \ + SL SR child SL + bh bh bh bh + */ + *parentp = rotate_left (parent, sibling); + sibling->color = parent->color; + parent->color = BLACK; + sibling->right->color = BLACK; + return; + } + else if (sibling->left != NULL && sibling->left->color == RED) + { + /* + parent parent + bh+1|bh+2 bh+1|bh+2 + / \ / \ + child sibling --> child SL + bh bh+1 bh bh+1 + / \ / \ + SL SR SLL sibling + bh bh bh bh + / \ / \ + SLL SLR SLR SR + bh bh bh bh + + where SLL, SLR, SR are all black. + */ + parent->right = rotate_right (sibling->left, sibling); + /* Change sibling from BLACK to RED and SL from RED to BLACK. */ + sibling->color = RED; + sibling = parent->right; + sibling->color = BLACK; + + /* Now do as in the previous case. */ + *parentp = rotate_left (parent, sibling); + sibling->color = parent->color; + parent->color = BLACK; + sibling->right->color = BLACK; + return; + } + else + { + if (parent->color == BLACK) + { + /* Change sibling from BLACK to RED. Then the entire + subtree at parent has decreased its black-height. + parent parent + bh+2 bh+1 + / \ / \ + child sibling --> child sibling + bh bh+1 bh bh + */ + sibling->color = RED; + + child = parent; + } + else + { + /* Change parent from RED to BLACK, but compensate by + changing sibling from BLACK to RED. + parent parent + bh+1 bh+1 + / \ / \ + child sibling --> child sibling + bh bh+1 bh bh + */ + parent->color = BLACK; + sibling->color = RED; + return; + } + } + } else if (parent->right == child) - { - gl_oset_node_t sibling = parent->left; - /* sibling's black-height is >= 1. In particular, - sibling != NULL. - - parent - / \ - sibling child - bh+1 bh - */ - - if (sibling->color == RED) - { - /* sibling is RED, hence parent is BLACK and sibling's children - are non-NULL and BLACK. - - parent sibling - bh+2 bh+2 - / \ / \ - sibling child --> SR parent - bh+1 ch bh+1 bh+1 - / \ / \ - SL SR SL child - bh+1 bh+1 bh+1 bh - */ - *parentp = rotate_right (sibling, parent); - parent->color = RED; - sibling->color = BLACK; - - /* Concentrate on the subtree of parent. The new sibling is - one of the old sibling's children, and known to be BLACK. */ - parentp = &sibling->right; - sibling = parent->left; - } - /* Now we know that sibling is BLACK. - - parent - / \ - sibling child - bh+1 bh - */ - if (sibling->left != NULL && sibling->left->color == RED) - { - /* - parent sibling - bh+1|bh+2 bh+1|bh+2 - / \ / \ - sibling child --> SL parent - bh+1 bh bh+1 bh+1 - / \ / \ - SL SR SR child - bh bh bh bh - */ - *parentp = rotate_right (sibling, parent); - sibling->color = parent->color; - parent->color = BLACK; - sibling->left->color = BLACK; - return; - } - else if (sibling->right != NULL && sibling->right->color == RED) - { - /* - parent parent - bh+1|bh+2 bh+1|bh+2 - / \ / \ - sibling child --> SR child - bh+1 bh bh+1 bh - / \ / \ - SL SR sibling SRR - bh bh bh bh - / \ / \ - SRL SRR SL SRL - bh bh bh bh - - where SL, SRL, SRR are all black. - */ - parent->left = rotate_left (sibling, sibling->right); - /* Change sibling from BLACK to RED and SL from RED to BLACK. */ - sibling->color = RED; - sibling = parent->left; - sibling->color = BLACK; - - /* Now do as in the previous case. */ - *parentp = rotate_right (sibling, parent); - sibling->color = parent->color; - parent->color = BLACK; - sibling->left->color = BLACK; - return; - } - else - { - if (parent->color == BLACK) - { - /* Change sibling from BLACK to RED. Then the entire - subtree at parent has decreased its black-height. - parent parent - bh+2 bh+1 - / \ / \ - sibling child --> sibling child - bh+1 bh bh bh - */ - sibling->color = RED; - - child = parent; - } - else - { - /* Change parent from RED to BLACK, but compensate by - changing sibling from BLACK to RED. - parent parent - bh+1 bh+1 - / \ / \ - sibling child --> sibling child - bh+1 bh bh bh - */ - parent->color = BLACK; - sibling->color = RED; - return; - } - } - } + { + gl_oset_node_t sibling = parent->left; + /* sibling's black-height is >= 1. In particular, + sibling != NULL. + + parent + / \ + sibling child + bh+1 bh + */ + + if (sibling->color == RED) + { + /* sibling is RED, hence parent is BLACK and sibling's children + are non-NULL and BLACK. + + parent sibling + bh+2 bh+2 + / \ / \ + sibling child --> SR parent + bh+1 ch bh+1 bh+1 + / \ / \ + SL SR SL child + bh+1 bh+1 bh+1 bh + */ + *parentp = rotate_right (sibling, parent); + parent->color = RED; + sibling->color = BLACK; + + /* Concentrate on the subtree of parent. The new sibling is + one of the old sibling's children, and known to be BLACK. */ + parentp = &sibling->right; + sibling = parent->left; + } + /* Now we know that sibling is BLACK. + + parent + / \ + sibling child + bh+1 bh + */ + if (sibling->left != NULL && sibling->left->color == RED) + { + /* + parent sibling + bh+1|bh+2 bh+1|bh+2 + / \ / \ + sibling child --> SL parent + bh+1 bh bh+1 bh+1 + / \ / \ + SL SR SR child + bh bh bh bh + */ + *parentp = rotate_right (sibling, parent); + sibling->color = parent->color; + parent->color = BLACK; + sibling->left->color = BLACK; + return; + } + else if (sibling->right != NULL && sibling->right->color == RED) + { + /* + parent parent + bh+1|bh+2 bh+1|bh+2 + / \ / \ + sibling child --> SR child + bh+1 bh bh+1 bh + / \ / \ + SL SR sibling SRR + bh bh bh bh + / \ / \ + SRL SRR SL SRL + bh bh bh bh + + where SL, SRL, SRR are all black. + */ + parent->left = rotate_left (sibling, sibling->right); + /* Change sibling from BLACK to RED and SL from RED to BLACK. */ + sibling->color = RED; + sibling = parent->left; + sibling->color = BLACK; + + /* Now do as in the previous case. */ + *parentp = rotate_right (sibling, parent); + sibling->color = parent->color; + parent->color = BLACK; + sibling->left->color = BLACK; + return; + } + else + { + if (parent->color == BLACK) + { + /* Change sibling from BLACK to RED. Then the entire + subtree at parent has decreased its black-height. + parent parent + bh+2 bh+1 + / \ / \ + sibling child --> sibling child + bh+1 bh bh bh + */ + sibling->color = RED; + + child = parent; + } + else + { + /* Change parent from RED to BLACK, but compensate by + changing sibling from BLACK to RED. + parent parent + bh+1 bh+1 + / \ / \ + sibling child --> sibling child + bh+1 bh bh bh + */ + parent->color = BLACK; + sibling->color = RED; + return; + } + } + } else - abort (); + abort (); /* Start again with a new (child, parent) pair. */ parent = child->parent; #if 0 /* Already handled. */ if (child != NULL && child->color == RED) - { - child->color = BLACK; - return; - } + { + child->color = BLACK; + return; + } #endif if (parent == NULL) - return; + return; } } @@ -559,7 +559,7 @@ gl_tree_add_first (gl_oset_t set, const void *elt) gl_oset_node_t node; for (node = set->root; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; new_node->parent = node; @@ -588,7 +588,7 @@ gl_tree_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt) else { for (node = node->left; node->right != NULL; ) - node = node->right; + node = node->right; node->right = new_node; } new_node->parent = node; @@ -616,7 +616,7 @@ gl_tree_add_after (gl_oset_t set, gl_oset_node_t node, const void *elt) else { for (node = node->right; node->left != NULL; ) - node = node->left; + node = node->left; node->left = new_node; } new_node->parent = node; @@ -639,45 +639,45 @@ gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node) gl_oset_node_t child = node->right; if (child != NULL) - { - child->parent = parent; - /* Since node->left == NULL, child must be RED and of height 1, - hence node must have been BLACK. Recolor the child. */ - child->color = BLACK; - } + { + child->parent = parent; + /* Since node->left == NULL, child must be RED and of height 1, + hence node must have been BLACK. Recolor the child. */ + child->color = BLACK; + } if (parent == NULL) - set->root = child; + set->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - - if (child == NULL && node->color == BLACK) - rebalance_after_remove (set, child, parent); - } + { + if (parent->left == node) + parent->left = child; + else /* parent->right == node */ + parent->right = child; + + if (child == NULL && node->color == BLACK) + rebalance_after_remove (set, child, 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. */ + general case below is more complicated, hence slower. */ /* Replace node with node->left. */ gl_oset_node_t child = node->left; child->parent = parent; /* Since node->right == NULL, child must be RED and of height 1, - hence node must have been BLACK. Recolor the child. */ + hence node must have been BLACK. Recolor the child. */ child->color = BLACK; if (parent == NULL) - set->root = child; + set->root = child; else - { - if (parent->left == node) - parent->left = child; - else /* parent->right == node */ - parent->right = child; - } + { + if (parent->left == node) + parent->left = child; + else /* parent->right == node */ + parent->right = child; + } } else { @@ -688,7 +688,7 @@ gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node) color_t removed_color; for (subst = node->left; subst->right != NULL; ) - subst = subst->right; + subst = subst->right; subst_parent = subst->parent; @@ -697,54 +697,54 @@ gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node) removed_color = subst->color; /* 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. */ + 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; - } + { + 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.) */ + (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->left = node->left; + subst->left->parent = subst; + } subst->right = node->right; subst->right->parent = subst; subst->color = node->color; subst->parent = parent; if (parent == NULL) - set->root = subst; + set->root = subst; else if (parent->left == node) - parent->left = subst; + parent->left = subst; else /* parent->right == node */ - parent->right = subst; + parent->right = subst; if (removed_color == BLACK) - { - if (child != NULL && child->color == RED) - /* Recolor the child. */ - child->color = BLACK; - else - /* 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_after_remove (set, child, - subst_parent != node ? subst_parent : subst); - } + { + if (child != NULL && child->color == RED) + /* Recolor the child. */ + child->color = BLACK; + else + /* 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_after_remove (set, child, + subst_parent != node ? subst_parent : subst); + } } set->count--; diff --git a/lib/gl_rbtreehash_list.c b/lib/gl_rbtreehash_list.c index 73ba2f653..2b21dfa75 100644 --- a/lib/gl_rbtreehash_list.c +++ b/lib/gl_rbtreehash_list.c @@ -74,8 +74,8 @@ check_invariants (gl_list_node_t node, gl_list_node_t parent) if (!(node->parent == parent)) abort (); if (!(node->branch_size - == (node->left != NULL ? node->left->branch_size : 0) - + 1 + (node->right != NULL ? node->right->branch_size : 0))) + == (node->left != NULL ? node->left->branch_size : 0) + + 1 + (node->right != NULL ? node->right->branch_size : 0))) abort (); if (!(node->color == BLACK || node->color == RED)) abort (); diff --git a/lib/gl_sublist.c b/lib/gl_sublist.c index 19158d02d..7970ee772 100644 --- a/lib/gl_sublist.c +++ b/lib/gl_sublist.c @@ -50,10 +50,10 @@ struct gl_list_impl static gl_list_t gl_sublist_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_listelement_equals_fn equals_fn, + gl_listelement_hashcode_fn hashcode_fn, + gl_listelement_dispose_fn dispose_fn, + bool allow_duplicates) { /* Shouldn't be called. */ abort (); @@ -61,11 +61,11 @@ gl_sublist_create_empty (gl_list_implementation_t implementation, static gl_list_t gl_sublist_create_fill (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_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) { /* Shouldn't be called. */ abort (); @@ -146,7 +146,7 @@ gl_sublist_set_at (gl_list_t list, size_t position, const void *elt) static gl_list_node_t gl_sublist_search_from_to (gl_list_t list, size_t start_index, size_t end_index, - const void *elt) + const void *elt) { if (!(start_index <= end_index && end_index <= list->end - list->start)) /* Invalid arguments. */ @@ -154,9 +154,9 @@ gl_sublist_search_from_to (gl_list_t list, size_t start_index, size_t end_index, { size_t index = gl_list_indexof_from_to (list->whole, - list->start + start_index, - list->start + end_index, - elt); + list->start + start_index, + list->start + end_index, + elt); if (index != (size_t)(-1)) return INDEX_TO_NODE (index - list->start); else @@ -166,8 +166,8 @@ gl_sublist_search_from_to (gl_list_t list, size_t start_index, size_t end_index, static size_t gl_sublist_indexof_from_to (gl_list_t list, - size_t start_index, size_t end_index, - const void *elt) + size_t start_index, size_t end_index, + const void *elt) { if (!(start_index <= end_index && end_index <= list->end - list->start)) /* Invalid arguments. */ @@ -175,9 +175,9 @@ gl_sublist_indexof_from_to (gl_list_t list, { size_t index = gl_list_indexof_from_to (list->whole, - list->start + start_index, - list->start + end_index, - elt); + list->start + start_index, + list->start + end_index, + elt); if (index != (size_t)(-1)) index -= list->start; return index; @@ -282,19 +282,19 @@ gl_sublist_iterator (gl_list_t list) static gl_list_iterator_t gl_sublist_iterator_from_to (gl_list_t list, - size_t start_index, size_t end_index) + size_t start_index, size_t end_index) { if (!(start_index <= end_index && end_index <= list->end - list->start)) /* Invalid arguments. */ abort (); return gl_list_iterator_from_to (list->whole, - list->start + start_index, - list->start + end_index); + list->start + start_index, + list->start + end_index); } static bool gl_sublist_iterator_next (gl_list_iterator_t *iterator, - const void **eltp, gl_list_node_t *nodep) + const void **eltp, gl_list_node_t *nodep) { /* Shouldn't be called. */ abort (); @@ -311,12 +311,12 @@ gl_sublist_iterator_free (gl_list_iterator_t *iterator) static gl_list_node_t gl_sublist_sortedlist_search (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt) + gl_listelement_compar_fn compar, + const void *elt) { size_t index = gl_sortedlist_indexof_from_to (list->whole, compar, - list->start, list->end, elt); + list->start, list->end, elt); if (index != (size_t)(-1)) return INDEX_TO_NODE (index - list->start); else @@ -325,9 +325,9 @@ gl_sublist_sortedlist_search (gl_list_t list, static gl_list_node_t gl_sublist_sortedlist_search_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { size_t index; @@ -337,7 +337,7 @@ gl_sublist_sortedlist_search_from_to (gl_list_t list, index = gl_sortedlist_indexof_from_to (list->whole, compar, - list->start + low, list->start + high, elt); + list->start + low, list->start + high, elt); if (index != (size_t)(-1)) return INDEX_TO_NODE (index - list->start); else @@ -346,12 +346,12 @@ gl_sublist_sortedlist_search_from_to (gl_list_t list, static size_t gl_sublist_sortedlist_indexof (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt) + gl_listelement_compar_fn compar, + const void *elt) { size_t index = gl_sortedlist_indexof_from_to (list->whole, compar, list->start, list->end, - elt); + elt); if (index != (size_t)(-1)) index -= list->start; return index; @@ -359,9 +359,9 @@ gl_sublist_sortedlist_indexof (gl_list_t list, static size_t gl_sublist_sortedlist_indexof_from_to (gl_list_t list, - gl_listelement_compar_fn compar, - size_t low, size_t high, - const void *elt) + gl_listelement_compar_fn compar, + size_t low, size_t high, + const void *elt) { size_t index; @@ -370,8 +370,8 @@ gl_sublist_sortedlist_indexof_from_to (gl_list_t list, abort (); index = gl_sortedlist_indexof_from_to (list->whole, compar, - list->start + low, list->start + high, - elt); + list->start + low, list->start + high, + elt); if (index != (size_t)(-1)) index -= list->start; return index; @@ -379,8 +379,8 @@ gl_sublist_sortedlist_indexof_from_to (gl_list_t list, static gl_list_node_t gl_sublist_sortedlist_add (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt) + gl_listelement_compar_fn compar, + const void *elt) { /* It's impossible to implement this method without risking to put the whole list into unsorted order (namely, when the given ELT is smaller @@ -390,8 +390,8 @@ gl_sublist_sortedlist_add (gl_list_t list, static bool gl_sublist_sortedlist_remove (gl_list_t list, - gl_listelement_compar_fn compar, - const void *elt) + gl_listelement_compar_fn compar, + const void *elt) { size_t index = gl_sublist_sortedlist_indexof (list, compar, elt); if (index == (size_t)(-1)) @@ -451,17 +451,17 @@ gl_sublist_create (gl_list_t whole_list, size_t start_index, size_t end_index) list->base.allow_duplicates = whole_list->base.allow_duplicates; /* unused */ if (whole_list->base.vtable == &gl_sublist_list_implementation) { - /* Optimization of a sublist of a sublist: Collapse the two - indirections into a single indirection. */ - list->whole = whole_list->whole; - list->start = whole_list->start + start_index; - list->end = whole_list->start + end_index; + /* Optimization of a sublist of a sublist: Collapse the two + indirections into a single indirection. */ + list->whole = whole_list->whole; + list->start = whole_list->start + start_index; + list->end = whole_list->start + end_index; } else { - list->whole = whole_list; - list->start = start_index; - list->end = end_index; + list->whole = whole_list; + list->start = start_index; + list->end = end_index; } return list; diff --git a/lib/gl_sublist.h b/lib/gl_sublist.h index a14498b6c..bd3539ecd 100644 --- a/lib/gl_sublist.h +++ b/lib/gl_sublist.h @@ -34,7 +34,7 @@ extern "C" { - The sublist must not be passed to the gl_list_sortedlist_add() function. */ extern gl_list_t gl_sublist_create (gl_list_t whole_list, - size_t start_index, size_t end_index); + size_t start_index, size_t end_index); #ifdef __cplusplus diff --git a/lib/glob-libc.h b/lib/glob-libc.h index 6f67607e4..bf701f36c 100644 --- a/lib/glob-libc.h +++ b/lib/glob-libc.h @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef _GLOB_H -#define _GLOB_H 1 +#ifndef _GLOB_H +#define _GLOB_H 1 #ifndef __GLOB_GNULIB # include @@ -59,39 +59,39 @@ typedef __SIZE_TYPE__ size_t; #endif /* Bits set in the FLAGS argument to `glob'. */ -#define GLOB_ERR (1 << 0)/* Return on read errors. */ -#define GLOB_MARK (1 << 1)/* Append a slash to each name. */ -#define GLOB_NOSORT (1 << 2)/* Don't sort the names. */ -#define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */ -#define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */ -#define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */ -#define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */ -#define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */ +#define GLOB_ERR (1 << 0)/* Return on read errors. */ +#define GLOB_MARK (1 << 1)/* Append a slash to each name. */ +#define GLOB_NOSORT (1 << 2)/* Don't sort the names. */ +#define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */ +#define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */ +#define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */ +#define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */ +#define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */ #if !defined __USE_POSIX2 || defined __USE_BSD || defined __USE_GNU -# define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */ +# define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */ # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */ -# define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */ -# define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */ -# define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */ -# define GLOB_ONLYDIR (1 << 13)/* Match only directories. */ +# define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */ +# define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */ +# define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */ +# define GLOB_ONLYDIR (1 << 13)/* Match only directories. */ # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error - if the user name is not available. */ -# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ - GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ - GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \ - GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK) + if the user name is not available. */ +# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ + GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ + GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \ + GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK) #else -# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ - GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ - GLOB_PERIOD) +# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ + GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ + GLOB_PERIOD) #endif /* Error returns from `glob'. */ -#define GLOB_NOSPACE 1 /* Ran out of memory. */ -#define GLOB_ABORTED 2 /* Read error. */ -#define GLOB_NOMATCH 3 /* No matches found. */ -#define GLOB_NOSYS 4 /* Not implemented. */ +#define GLOB_NOSPACE 1 /* Ran out of memory. */ +#define GLOB_ABORTED 2 /* Read error. */ +#define GLOB_NOMATCH 3 /* No matches found. */ +#define GLOB_NOSYS 4 /* Not implemented. */ #ifdef __USE_GNU /* Previous versions of this file defined GLOB_ABEND instead of GLOB_ABORTED. Provide a compatibility definition here. */ @@ -104,10 +104,10 @@ struct stat; #endif typedef struct { - __size_t gl_pathc; /* Count of paths matched by the pattern. */ - char **gl_pathv; /* List of matched pathnames. */ - __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */ - int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */ + __size_t gl_pathc; /* Count of paths matched by the pattern. */ + char **gl_pathv; /* List of matched pathnames. */ + __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */ + int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */ /* If the GLOB_ALTDIRFUNC flag is set, the following functions are used instead of the normal file access functions. */ @@ -172,24 +172,24 @@ typedef struct Otherwise, `glob' returns zero. */ #if !defined __USE_FILE_OFFSET64 || __GNUC__ < 2 || defined __GLOB_GNULIB extern int glob (const char *_Restrict_ __pattern, int __flags, - int (*__errfunc) (const char *, int), - glob_t *_Restrict_ __pglob) __THROW; + int (*__errfunc) (const char *, int), + glob_t *_Restrict_ __pglob) __THROW; /* Free storage allocated in PGLOB by a previous `glob' call. */ extern void globfree (glob_t *__pglob) __THROW; #else extern int __REDIRECT_NTH (glob, (const char *_Restrict_ __pattern, - int __flags, - int (*__errfunc) (const char *, int), - glob_t *_Restrict_ __pglob), glob64); + int __flags, + int (*__errfunc) (const char *, int), + glob_t *_Restrict_ __pglob), glob64); extern void __REDIRECT_NTH (globfree, (glob_t *__pglob), globfree64); #endif #if defined __USE_LARGEFILE64 && !defined __GLOB_GNULIB extern int glob64 (const char *_Restrict_ __pattern, int __flags, - int (*__errfunc) (const char *, int), - glob64_t *_Restrict_ __pglob) __THROW; + int (*__errfunc) (const char *, int), + glob64_t *_Restrict_ __pglob) __THROW; extern void globfree64 (glob64_t *__pglob) __THROW; #endif diff --git a/lib/glob.c b/lib/glob.c index 5aea0b31a..f46159bd6 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -32,7 +32,7 @@ #include -#include /* Needed on stupid SunOS for assert. */ +#include /* Needed on stupid SunOS for assert. */ #if !defined _LIBC || !defined GLOB_ONLY_P @@ -67,20 +67,20 @@ HAVE_STRUCT_DIRENT_D_TYPE plays the same role in GNULIB. */ #if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE /* True if the directory entry D must be of type T. */ -# define DIRENT_MUST_BE(d, t) ((d)->d_type == (t)) +# define DIRENT_MUST_BE(d, t) ((d)->d_type == (t)) /* True if the directory entry D might be a symbolic link. */ # define DIRENT_MIGHT_BE_SYMLINK(d) \ ((d)->d_type == DT_UNKNOWN || (d)->d_type == DT_LNK) /* True if the directory entry D might be a directory. */ -# define DIRENT_MIGHT_BE_DIR(d) \ +# define DIRENT_MIGHT_BE_DIR(d) \ ((d)->d_type == DT_DIR || DIRENT_MIGHT_BE_SYMLINK (d)) #else /* !HAVE_D_TYPE */ -# define DIRENT_MUST_BE(d, t) false -# define DIRENT_MIGHT_BE_SYMLINK(d) true -# define DIRENT_MIGHT_BE_DIR(d) true +# define DIRENT_MUST_BE(d, t) false +# define DIRENT_MIGHT_BE_SYMLINK(d) true +# define DIRENT_MIGHT_BE_DIR(d) true #endif /* HAVE_D_TYPE */ /* If the system has the `struct dirent64' type we use it internally. */ @@ -100,8 +100,8 @@ # endif # define CONVERT_DIRENT_DIRENT64(d64, d32) \ - memcpy ((d64)->d_name, (d32)->d_name, _D_EXACT_NAMLEN (d32) + 1); \ - CONVERT_D_INO (d64, d32) \ + memcpy ((d64)->d_name, (d32)->d_name, _D_EXACT_NAMLEN (d32) + 1); \ + CONVERT_D_INO (d64, d32) \ CONVERT_D_TYPE (d64, d32) #endif @@ -137,29 +137,29 @@ # ifndef __stat64 # define __stat64(fname, buf) __xstat64 (_STAT_VER, fname, buf) # endif -# define struct_stat64 struct stat64 +# define struct_stat64 struct stat64 #else /* !_LIBC */ -# define __stat64(fname, buf) stat (fname, buf) +# define __stat64(fname, buf) stat (fname, buf) # define __fxstatat64(_, d, f, st, flag) fstatat (d, f, st, flag) -# define struct_stat64 struct stat -# define __stat(fname, buf) stat (fname, buf) -# define __alloca alloca -# define __readdir readdir -# define __readdir64 readdir64 -# define __glob_pattern_p glob_pattern_p +# define struct_stat64 struct stat +# define __stat(fname, buf) stat (fname, buf) +# define __alloca alloca +# define __readdir readdir +# define __readdir64 readdir64 +# define __glob_pattern_p glob_pattern_p #endif /* _LIBC */ #include #ifdef _SC_GETPW_R_SIZE_MAX -# define GETPW_R_SIZE_MAX() sysconf (_SC_GETPW_R_SIZE_MAX) +# define GETPW_R_SIZE_MAX() sysconf (_SC_GETPW_R_SIZE_MAX) #else -# define GETPW_R_SIZE_MAX() (-1) +# define GETPW_R_SIZE_MAX() (-1) #endif #ifdef _SC_LOGIN_NAME_MAX -# define GET_LOGIN_NAME_MAX() sysconf (_SC_LOGIN_NAME_MAX) +# define GET_LOGIN_NAME_MAX() sysconf (_SC_LOGIN_NAME_MAX) #else -# define GET_LOGIN_NAME_MAX() (-1) +# define GET_LOGIN_NAME_MAX() (-1) #endif static const char *next_brace_sub (const char *begin, int flags) __THROW; @@ -204,8 +204,8 @@ static const char *next_brace_sub (const char *begin, int flags) __THROW; #endif static int glob_in_dir (const char *pattern, const char *directory, - int flags, int (*errfunc) (const char *, int), - glob_t *pglob); + int flags, int (*errfunc) (const char *, int), + glob_t *pglob); extern int __glob_pattern_type (const char *pattern, int quote) attribute_hidden; @@ -222,17 +222,17 @@ next_brace_sub (const char *cp, int flags) while (*cp != '\0') if ((flags & GLOB_NOESCAPE) == 0 && *cp == '\\') { - if (*++cp == '\0') - break; - ++cp; + if (*++cp == '\0') + break; + ++cp; } else { - if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0)) - break; + if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0)) + break; - if (*cp++ == '{') - depth++; + if (*cp++ == '{') + depth++; } return *cp != '\0' ? cp : NULL; @@ -283,145 +283,145 @@ glob (pattern, flags, errfunc, pglob) const char *begin; if (flags & GLOB_NOESCAPE) - begin = strchr (pattern, '{'); + begin = strchr (pattern, '{'); else - { - begin = pattern; - while (1) - { - if (*begin == '\0') - { - begin = NULL; - break; - } - - if (*begin == '\\' && begin[1] != '\0') - ++begin; - else if (*begin == '{') - break; - - ++begin; - } - } + { + begin = pattern; + while (1) + { + if (*begin == '\0') + { + begin = NULL; + break; + } + + if (*begin == '\\' && begin[1] != '\0') + ++begin; + else if (*begin == '{') + break; + + ++begin; + } + } if (begin != NULL) - { - /* Allocate working buffer large enough for our work. Note that - we have at least an opening and closing brace. */ - size_t firstc; - char *alt_start; - const char *p; - const char *next; - const char *rest; - size_t rest_len; + { + /* Allocate working buffer large enough for our work. Note that + we have at least an opening and closing brace. */ + size_t firstc; + char *alt_start; + const char *p; + const char *next; + const char *rest; + size_t rest_len; #ifdef __GNUC__ - char onealt[strlen (pattern) - 1]; + char onealt[strlen (pattern) - 1]; #else - char *onealt = malloc (strlen (pattern) - 1); - if (onealt == NULL) - { - if (!(flags & GLOB_APPEND)) - { - pglob->gl_pathc = 0; - pglob->gl_pathv = NULL; - } - return GLOB_NOSPACE; - } + char *onealt = malloc (strlen (pattern) - 1); + if (onealt == NULL) + { + if (!(flags & GLOB_APPEND)) + { + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + } + return GLOB_NOSPACE; + } #endif - /* We know the prefix for all sub-patterns. */ - alt_start = mempcpy (onealt, pattern, begin - pattern); + /* We know the prefix for all sub-patterns. */ + alt_start = mempcpy (onealt, pattern, begin - pattern); - /* Find the first sub-pattern and at the same time find the - rest after the closing brace. */ - next = next_brace_sub (begin + 1, flags); - if (next == NULL) - { - /* It is an invalid expression. */ + /* Find the first sub-pattern and at the same time find the + rest after the closing brace. */ + next = next_brace_sub (begin + 1, flags); + if (next == NULL) + { + /* It is an invalid expression. */ #ifndef __GNUC__ - free (onealt); + free (onealt); #endif - return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); - } - - /* Now find the end of the whole brace expression. */ - rest = next; - while (*rest != '}') - { - rest = next_brace_sub (rest + 1, flags); - if (rest == NULL) - { - /* It is an invalid expression. */ + return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); + } + + /* Now find the end of the whole brace expression. */ + rest = next; + while (*rest != '}') + { + rest = next_brace_sub (rest + 1, flags); + if (rest == NULL) + { + /* It is an invalid expression. */ #ifndef __GNUC__ - free (onealt); + free (onealt); #endif - return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); - } - } - /* Please note that we now can be sure the brace expression - is well-formed. */ - rest_len = strlen (++rest) + 1; - - /* We have a brace expression. BEGIN points to the opening {, - NEXT points past the terminator of the first element, and END - points past the final }. We will accumulate result names from - recursive runs for each brace alternative in the buffer using - GLOB_APPEND. */ - - if (!(flags & GLOB_APPEND)) - { - /* This call is to set a new vector, so clear out the - vector so we can append to it. */ - pglob->gl_pathc = 0; - pglob->gl_pathv = NULL; - } - firstc = pglob->gl_pathc; - - p = begin + 1; - while (1) - { - int result; - - /* Construct the new glob expression. */ - mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len); - - result = glob (onealt, - ((flags & ~(GLOB_NOCHECK | GLOB_NOMAGIC)) - | GLOB_APPEND), errfunc, pglob); - - /* If we got an error, return it. */ - if (result && result != GLOB_NOMATCH) - { + return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob); + } + } + /* Please note that we now can be sure the brace expression + is well-formed. */ + rest_len = strlen (++rest) + 1; + + /* We have a brace expression. BEGIN points to the opening {, + NEXT points past the terminator of the first element, and END + points past the final }. We will accumulate result names from + recursive runs for each brace alternative in the buffer using + GLOB_APPEND. */ + + if (!(flags & GLOB_APPEND)) + { + /* This call is to set a new vector, so clear out the + vector so we can append to it. */ + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + } + firstc = pglob->gl_pathc; + + p = begin + 1; + while (1) + { + int result; + + /* Construct the new glob expression. */ + mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len); + + result = glob (onealt, + ((flags & ~(GLOB_NOCHECK | GLOB_NOMAGIC)) + | GLOB_APPEND), errfunc, pglob); + + /* If we got an error, return it. */ + if (result && result != GLOB_NOMATCH) + { #ifndef __GNUC__ - free (onealt); + free (onealt); #endif - if (!(flags & GLOB_APPEND)) - { - globfree (pglob); - pglob->gl_pathc = 0; - } - return result; - } - - if (*next == '}') - /* We saw the last entry. */ - break; - - p = next + 1; - next = next_brace_sub (p, flags); - assert (next != NULL); - } + if (!(flags & GLOB_APPEND)) + { + globfree (pglob); + pglob->gl_pathc = 0; + } + return result; + } + + if (*next == '}') + /* We saw the last entry. */ + break; + + p = next + 1; + next = next_brace_sub (p, flags); + assert (next != NULL); + } #ifndef __GNUC__ - free (onealt); + free (onealt); #endif - if (pglob->gl_pathc != firstc) - /* We found some entries. */ - return 0; - else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC))) - return GLOB_NOMATCH; - } + if (pglob->gl_pathc != firstc) + /* We found some entries. */ + return 0; + else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC))) + return GLOB_NOMATCH; + } } /* Find the filename. */ @@ -438,31 +438,31 @@ glob (pattern, flags, errfunc, pglob) if (filename == NULL) { /* This can mean two things: a simple name or "~name". The latter - case is nothing but a notation for a directory. */ + case is nothing but a notation for a directory. */ if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern[0] == '~') - { - dirname = pattern; - dirlen = strlen (pattern); - - /* Set FILENAME to NULL as a special flag. This is ugly but - other solutions would require much more code. We test for - this special case below. */ - filename = NULL; - } + { + dirname = pattern; + dirlen = strlen (pattern); + + /* Set FILENAME to NULL as a special flag. This is ugly but + other solutions would require much more code. We test for + this special case below. */ + filename = NULL; + } else - { - filename = pattern; + { + filename = pattern; #ifdef _AMIGA - dirname = ""; + dirname = ""; #else - dirname = "."; + dirname = "."; #endif - dirlen = 0; - } + dirlen = 0; + } } else if (filename == pattern - || (filename == pattern + 1 && pattern[0] == '\\' - && (flags & GLOB_NOESCAPE) == 0)) + || (filename == pattern + 1 && pattern[0] == '\\' + && (flags & GLOB_NOESCAPE) == 0)) { /* "/pattern" or "\\/pattern". */ dirname = "/"; @@ -475,21 +475,21 @@ glob (pattern, flags, errfunc, pglob) dirlen = filename - pattern; #if defined __MSDOS__ || defined WINDOWS32 if (*filename == ':' - || (filename > pattern + 1 && filename[-1] == ':')) - { - char *drive_spec; - - ++dirlen; - drive_spec = __alloca (dirlen + 1); - *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0'; - /* For now, disallow wildcards in the drive spec, to - prevent infinite recursion in glob. */ - if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE))) - return GLOB_NOMATCH; - /* If this is "d:pattern", we need to copy `:' to DIRNAME - as well. If it's "d:/pattern", don't remove the slash - from "d:/", since "d:" and "d:/" are not the same.*/ - } + || (filename > pattern + 1 && filename[-1] == ':')) + { + char *drive_spec; + + ++dirlen; + drive_spec = __alloca (dirlen + 1); + *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0'; + /* For now, disallow wildcards in the drive spec, to + prevent infinite recursion in glob. */ + if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE))) + return GLOB_NOMATCH; + /* If this is "d:pattern", we need to copy `:' to DIRNAME + as well. If it's "d:/pattern", don't remove the slash + from "d:/", since "d:" and "d:/" are not the same.*/ + } #endif newp = __alloca (dirlen + 1); *((char *) mempcpy (newp, pattern, dirlen)) = '\0'; @@ -499,41 +499,41 @@ glob (pattern, flags, errfunc, pglob) if (filename[0] == '\0' #if defined __MSDOS__ || defined WINDOWS32 && dirname[dirlen - 1] != ':' - && (dirlen < 3 || dirname[dirlen - 2] != ':' - || dirname[dirlen - 1] != '/') + && (dirlen < 3 || dirname[dirlen - 2] != ':' + || dirname[dirlen - 1] != '/') #endif - && dirlen > 1) - /* "pattern/". Expand "pattern", appending slashes. */ - { - int orig_flags = flags; - int val; - if (!(flags & GLOB_NOESCAPE) && dirname[dirlen - 1] == '\\') - { - /* "pattern\\/". Remove the final backslash if it hasn't - been quoted. */ - char *p = (char *) &dirname[dirlen - 1]; - - while (p > dirname && p[-1] == '\\') --p; - if ((&dirname[dirlen] - p) & 1) - { - *(char *) &dirname[--dirlen] = '\0'; - flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC); - } - } - val = glob (dirname, flags | GLOB_MARK, errfunc, pglob); - if (val == 0) - pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK) - | (flags & GLOB_MARK)); - else if (val == GLOB_NOMATCH && flags != orig_flags) - { - /* Make sure globfree (&dirs); is a nop. */ - dirs.gl_pathv = NULL; - flags = orig_flags; - oldcount = pglob->gl_pathc + pglob->gl_offs; - goto no_matches; - } - return val; - } + && dirlen > 1) + /* "pattern/". Expand "pattern", appending slashes. */ + { + int orig_flags = flags; + int val; + if (!(flags & GLOB_NOESCAPE) && dirname[dirlen - 1] == '\\') + { + /* "pattern\\/". Remove the final backslash if it hasn't + been quoted. */ + char *p = (char *) &dirname[dirlen - 1]; + + while (p > dirname && p[-1] == '\\') --p; + if ((&dirname[dirlen] - p) & 1) + { + *(char *) &dirname[--dirlen] = '\0'; + flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC); + } + } + val = glob (dirname, flags | GLOB_MARK, errfunc, pglob); + if (val == 0) + pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK) + | (flags & GLOB_MARK)); + else if (val == GLOB_NOMATCH && flags != orig_flags) + { + /* Make sure globfree (&dirs); is a nop. */ + dirs.gl_pathv = NULL; + flags = orig_flags; + oldcount = pglob->gl_pathc + pglob->gl_offs; + goto no_matches; + } + return val; + } } if (!(flags & GLOB_APPEND)) @@ -542,15 +542,15 @@ glob (pattern, flags, errfunc, pglob) if (!(flags & GLOB_DOOFFS)) pglob->gl_pathv = NULL; else - { - size_t i; - pglob->gl_pathv = malloc ((pglob->gl_offs + 1) * sizeof (char *)); - if (pglob->gl_pathv == NULL) - return GLOB_NOSPACE; - - for (i = 0; i <= pglob->gl_offs; ++i) - pglob->gl_pathv[i] = NULL; - } + { + size_t i; + pglob->gl_pathv = malloc ((pglob->gl_offs + 1) * sizeof (char *)); + if (pglob->gl_pathv == NULL) + return GLOB_NOSPACE; + + for (i = 0; i <= pglob->gl_offs; ++i) + pglob->gl_pathv[i] = NULL; + } } oldcount = pglob->gl_pathc + pglob->gl_offs; @@ -558,235 +558,235 @@ glob (pattern, flags, errfunc, pglob) if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && dirname[0] == '~') { if (dirname[1] == '\0' || dirname[1] == '/' - || (!(flags & GLOB_NOESCAPE) && dirname[1] == '\\' - && (dirname[2] == '\0' || dirname[2] == '/'))) - { - /* Look up home directory. */ - const char *home_dir = getenv ("HOME"); + || (!(flags & GLOB_NOESCAPE) && dirname[1] == '\\' + && (dirname[2] == '\0' || dirname[2] == '/'))) + { + /* Look up home directory. */ + const char *home_dir = getenv ("HOME"); # ifdef _AMIGA - if (home_dir == NULL || home_dir[0] == '\0') - home_dir = "SYS:"; + if (home_dir == NULL || home_dir[0] == '\0') + home_dir = "SYS:"; # else # ifdef WINDOWS32 - /* Windows NT defines HOMEDRIVE and HOMEPATH. But give preference - to HOME, because the user can change HOME. */ - if (home_dir == NULL || home_dir[0] == '\0') - { - const char *home_drive = getenv ("HOMEDRIVE"); - const char *home_path = getenv ("HOMEPATH"); - - if (home_drive != NULL && home_path != NULL) - { - size_t home_drive_len = strlen (home_drive); - size_t home_path_len = strlen (home_path); - char *mem = alloca (home_drive_len + home_path_len + 1); - - memcpy (mem, home_drive, home_drive_len); - memcpy (mem + home_drive_len, home_path, home_path_len + 1); - home_dir = mem; - } - else - home_dir = "c:/users/default"; /* poor default */ - } + /* Windows NT defines HOMEDRIVE and HOMEPATH. But give preference + to HOME, because the user can change HOME. */ + if (home_dir == NULL || home_dir[0] == '\0') + { + const char *home_drive = getenv ("HOMEDRIVE"); + const char *home_path = getenv ("HOMEPATH"); + + if (home_drive != NULL && home_path != NULL) + { + size_t home_drive_len = strlen (home_drive); + size_t home_path_len = strlen (home_path); + char *mem = alloca (home_drive_len + home_path_len + 1); + + memcpy (mem, home_drive, home_drive_len); + memcpy (mem + home_drive_len, home_path, home_path_len + 1); + home_dir = mem; + } + else + home_dir = "c:/users/default"; /* poor default */ + } # else - if (home_dir == NULL || home_dir[0] == '\0') - { - int success; - char *name; - size_t buflen = GET_LOGIN_NAME_MAX () + 1; - - if (buflen == 0) - /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try - a moderate value. */ - buflen = 20; - name = __alloca (buflen); - - success = getlogin_r (name, buflen) == 0; - if (success) - { - struct passwd *p; + if (home_dir == NULL || home_dir[0] == '\0') + { + int success; + char *name; + size_t buflen = GET_LOGIN_NAME_MAX () + 1; + + if (buflen == 0) + /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try + a moderate value. */ + buflen = 20; + name = __alloca (buflen); + + success = getlogin_r (name, buflen) == 0; + if (success) + { + struct passwd *p; # if defined HAVE_GETPWNAM_R || defined _LIBC - long int pwbuflen = GETPW_R_SIZE_MAX (); - char *pwtmpbuf; - struct passwd pwbuf; - int save = errno; + long int pwbuflen = GETPW_R_SIZE_MAX (); + char *pwtmpbuf; + struct passwd pwbuf; + int save = errno; # ifndef _LIBC - if (pwbuflen == -1) - /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. - Try a moderate value. */ - pwbuflen = 1024; + if (pwbuflen == -1) + /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. + Try a moderate value. */ + pwbuflen = 1024; # endif - pwtmpbuf = __alloca (pwbuflen); - - while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p) - != 0) - { - if (errno != ERANGE) - { - p = NULL; - break; - } + pwtmpbuf = __alloca (pwbuflen); + + while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p) + != 0) + { + if (errno != ERANGE) + { + p = NULL; + break; + } # ifdef _LIBC - pwtmpbuf = extend_alloca (pwtmpbuf, pwbuflen, - 2 * pwbuflen); + pwtmpbuf = extend_alloca (pwtmpbuf, pwbuflen, + 2 * pwbuflen); # else - pwbuflen *= 2; - pwtmpbuf = __alloca (pwbuflen); + pwbuflen *= 2; + pwtmpbuf = __alloca (pwbuflen); # endif - __set_errno (save); - } + __set_errno (save); + } # else - p = getpwnam (name); + p = getpwnam (name); # endif - if (p != NULL) - home_dir = p->pw_dir; - } - } - if (home_dir == NULL || home_dir[0] == '\0') - { - if (flags & GLOB_TILDE_CHECK) - return GLOB_NOMATCH; - else - home_dir = "~"; /* No luck. */ - } + if (p != NULL) + home_dir = p->pw_dir; + } + } + if (home_dir == NULL || home_dir[0] == '\0') + { + if (flags & GLOB_TILDE_CHECK) + return GLOB_NOMATCH; + else + home_dir = "~"; /* No luck. */ + } # endif /* WINDOWS32 */ # endif - /* Now construct the full directory. */ - if (dirname[1] == '\0') - { - dirname = home_dir; - dirlen = strlen (dirname); - } - else - { - char *newp; - size_t home_len = strlen (home_dir); - newp = __alloca (home_len + dirlen); - mempcpy (mempcpy (newp, home_dir, home_len), - &dirname[1], dirlen); - dirname = newp; - dirlen += home_len - 1; - } - dirname_modified = 1; - } + /* Now construct the full directory. */ + if (dirname[1] == '\0') + { + dirname = home_dir; + dirlen = strlen (dirname); + } + else + { + char *newp; + size_t home_len = strlen (home_dir); + newp = __alloca (home_len + dirlen); + mempcpy (mempcpy (newp, home_dir, home_len), + &dirname[1], dirlen); + dirname = newp; + dirlen += home_len - 1; + } + dirname_modified = 1; + } # if !defined _AMIGA && !defined WINDOWS32 else - { - char *end_name = strchr (dirname, '/'); - const char *user_name; - const char *home_dir; - char *unescape = NULL; - - if (!(flags & GLOB_NOESCAPE)) - { - if (end_name == NULL) - { - unescape = strchr (dirname, '\\'); - if (unescape) - end_name = strchr (unescape, '\0'); - } - else - unescape = memchr (dirname, '\\', end_name - dirname); - } - if (end_name == NULL) - user_name = dirname + 1; - else - { - char *newp; - newp = __alloca (end_name - dirname); - *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) - = '\0'; - if (unescape != NULL) - { - char *p = mempcpy (newp, dirname + 1, - unescape - dirname - 1); - char *q = unescape; - while (*q != '\0') - { - if (*q == '\\') - { - if (q[1] == '\0') - { - /* "~fo\\o\\" unescape to user_name "foo\\", - but "~fo\\o\\/" unescape to user_name - "foo". */ - if (filename == NULL) - *p++ = '\\'; - break; - } - ++q; - } - *p++ = *q++; - } - *p = '\0'; - } - else - *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) - = '\0'; - user_name = newp; - } - - /* Look up specific user's home directory. */ - { - struct passwd *p; + { + char *end_name = strchr (dirname, '/'); + const char *user_name; + const char *home_dir; + char *unescape = NULL; + + if (!(flags & GLOB_NOESCAPE)) + { + if (end_name == NULL) + { + unescape = strchr (dirname, '\\'); + if (unescape) + end_name = strchr (unescape, '\0'); + } + else + unescape = memchr (dirname, '\\', end_name - dirname); + } + if (end_name == NULL) + user_name = dirname + 1; + else + { + char *newp; + newp = __alloca (end_name - dirname); + *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) + = '\0'; + if (unescape != NULL) + { + char *p = mempcpy (newp, dirname + 1, + unescape - dirname - 1); + char *q = unescape; + while (*q != '\0') + { + if (*q == '\\') + { + if (q[1] == '\0') + { + /* "~fo\\o\\" unescape to user_name "foo\\", + but "~fo\\o\\/" unescape to user_name + "foo". */ + if (filename == NULL) + *p++ = '\\'; + break; + } + ++q; + } + *p++ = *q++; + } + *p = '\0'; + } + else + *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) + = '\0'; + user_name = newp; + } + + /* Look up specific user's home directory. */ + { + struct passwd *p; # if defined HAVE_GETPWNAM_R || defined _LIBC - long int buflen = GETPW_R_SIZE_MAX (); - char *pwtmpbuf; - struct passwd pwbuf; - int save = errno; + long int buflen = GETPW_R_SIZE_MAX (); + char *pwtmpbuf; + struct passwd pwbuf; + int save = errno; # ifndef _LIBC - if (buflen == -1) - /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a - moderate value. */ - buflen = 1024; + if (buflen == -1) + /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX. Try a + moderate value. */ + buflen = 1024; # endif - pwtmpbuf = __alloca (buflen); - - while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0) - { - if (errno != ERANGE) - { - p = NULL; - break; - } + pwtmpbuf = __alloca (buflen); + + while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0) + { + if (errno != ERANGE) + { + p = NULL; + break; + } # ifdef _LIBC - pwtmpbuf = extend_alloca (pwtmpbuf, buflen, 2 * buflen); + pwtmpbuf = extend_alloca (pwtmpbuf, buflen, 2 * buflen); # else - buflen *= 2; - pwtmpbuf = __alloca (buflen); + buflen *= 2; + pwtmpbuf = __alloca (buflen); # endif - __set_errno (save); - } + __set_errno (save); + } # else - p = getpwnam (user_name); + p = getpwnam (user_name); # endif - if (p != NULL) - home_dir = p->pw_dir; - else - home_dir = NULL; - } - /* If we found a home directory use this. */ - if (home_dir != NULL) - { - char *newp; - size_t home_len = strlen (home_dir); - size_t rest_len = end_name == NULL ? 0 : strlen (end_name); - newp = __alloca (home_len + rest_len + 1); - *((char *) mempcpy (mempcpy (newp, home_dir, home_len), - end_name, rest_len)) = '\0'; - dirname = newp; - dirlen = home_len + rest_len; - dirname_modified = 1; - } - else - if (flags & GLOB_TILDE_CHECK) - /* We have to regard it as an error if we cannot find the - home directory. */ - return GLOB_NOMATCH; - } -# endif /* Not Amiga && not WINDOWS32. */ + if (p != NULL) + home_dir = p->pw_dir; + else + home_dir = NULL; + } + /* If we found a home directory use this. */ + if (home_dir != NULL) + { + char *newp; + size_t home_len = strlen (home_dir); + size_t rest_len = end_name == NULL ? 0 : strlen (end_name); + newp = __alloca (home_len + rest_len + 1); + *((char *) mempcpy (mempcpy (newp, home_dir, home_len), + end_name, rest_len)) = '\0'; + dirname = newp; + dirlen = home_len + rest_len; + dirname_modified = 1; + } + else + if (flags & GLOB_TILDE_CHECK) + /* We have to regard it as an error if we cannot find the + home directory. */ + return GLOB_NOMATCH; + } +# endif /* Not Amiga && not WINDOWS32. */ } /* Now test whether we looked for "~" or "~NAME". In this case we @@ -798,48 +798,48 @@ glob (pattern, flags, errfunc, pglob) /* Return the directory if we don't check for error or if it exists. */ if ((flags & GLOB_NOCHECK) - || (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) - ? ((*pglob->gl_stat) (dirname, &st) == 0 - && S_ISDIR (st.st_mode)) - : (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode))))) - { - int newcount = pglob->gl_pathc + pglob->gl_offs; - char **new_gl_pathv; - - new_gl_pathv - = realloc (pglob->gl_pathv, (newcount + 1 + 1) * sizeof (char *)); - if (new_gl_pathv == NULL) - { - nospace: - free (pglob->gl_pathv); - pglob->gl_pathv = NULL; - pglob->gl_pathc = 0; - return GLOB_NOSPACE; - } - pglob->gl_pathv = new_gl_pathv; - - if (flags & GLOB_MARK) - { - char *p; - pglob->gl_pathv[newcount] = malloc (dirlen + 2); - if (pglob->gl_pathv[newcount] == NULL) - goto nospace; - p = mempcpy (pglob->gl_pathv[newcount], dirname, dirlen); - p[0] = '/'; - p[1] = '\0'; - } - else - { - pglob->gl_pathv[newcount] = strdup (dirname); - if (pglob->gl_pathv[newcount] == NULL) - goto nospace; - } - pglob->gl_pathv[++newcount] = NULL; - ++pglob->gl_pathc; - pglob->gl_flags = flags; - - return 0; - } + || (((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) + ? ((*pglob->gl_stat) (dirname, &st) == 0 + && S_ISDIR (st.st_mode)) + : (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode))))) + { + int newcount = pglob->gl_pathc + pglob->gl_offs; + char **new_gl_pathv; + + new_gl_pathv + = realloc (pglob->gl_pathv, (newcount + 1 + 1) * sizeof (char *)); + if (new_gl_pathv == NULL) + { + nospace: + free (pglob->gl_pathv); + pglob->gl_pathv = NULL; + pglob->gl_pathc = 0; + return GLOB_NOSPACE; + } + pglob->gl_pathv = new_gl_pathv; + + if (flags & GLOB_MARK) + { + char *p; + pglob->gl_pathv[newcount] = malloc (dirlen + 2); + if (pglob->gl_pathv[newcount] == NULL) + goto nospace; + p = mempcpy (pglob->gl_pathv[newcount], dirname, dirlen); + p[0] = '/'; + p[1] = '\0'; + } + else + { + pglob->gl_pathv[newcount] = strdup (dirname); + if (pglob->gl_pathv[newcount] == NULL) + goto nospace; + } + pglob->gl_pathv[++newcount] = NULL; + ++pglob->gl_pathc; + pglob->gl_flags = flags; + + return 0; + } /* Not found. */ return GLOB_NOMATCH; @@ -854,137 +854,137 @@ glob (pattern, flags, errfunc, pglob) if (meta & 5) { /* The directory name contains metacharacters, so we - have to glob for the directory, and then glob for - the pattern in each directory found. */ + have to glob for the directory, and then glob for + the pattern in each directory found. */ size_t i; if (!(flags & GLOB_NOESCAPE) && dirlen > 0 && dirname[dirlen - 1] == '\\') - { - /* "foo\\/bar". Remove the final backslash from dirname - if it has not been quoted. */ - char *p = (char *) &dirname[dirlen - 1]; + { + /* "foo\\/bar". Remove the final backslash from dirname + if it has not been quoted. */ + char *p = (char *) &dirname[dirlen - 1]; - while (p > dirname && p[-1] == '\\') --p; - if ((&dirname[dirlen] - p) & 1) - *(char *) &dirname[--dirlen] = '\0'; - } + while (p > dirname && p[-1] == '\\') --p; + if ((&dirname[dirlen] - p) & 1) + *(char *) &dirname[--dirlen] = '\0'; + } if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) != 0, 0)) - { - /* Use the alternative access functions also in the recursive - call. */ - dirs.gl_opendir = pglob->gl_opendir; - dirs.gl_readdir = pglob->gl_readdir; - dirs.gl_closedir = pglob->gl_closedir; - dirs.gl_stat = pglob->gl_stat; - dirs.gl_lstat = pglob->gl_lstat; - } + { + /* Use the alternative access functions also in the recursive + call. */ + dirs.gl_opendir = pglob->gl_opendir; + dirs.gl_readdir = pglob->gl_readdir; + dirs.gl_closedir = pglob->gl_closedir; + dirs.gl_stat = pglob->gl_stat; + dirs.gl_lstat = pglob->gl_lstat; + } status = glob (dirname, - ((flags & (GLOB_ERR | GLOB_NOESCAPE - | GLOB_ALTDIRFUNC)) - | GLOB_NOSORT | GLOB_ONLYDIR), - errfunc, &dirs); + ((flags & (GLOB_ERR | GLOB_NOESCAPE + | GLOB_ALTDIRFUNC)) + | GLOB_NOSORT | GLOB_ONLYDIR), + errfunc, &dirs); if (status != 0) - { - if ((flags & GLOB_NOCHECK) == 0 || status != GLOB_NOMATCH) - return status; - goto no_matches; - } + { + if ((flags & GLOB_NOCHECK) == 0 || status != GLOB_NOMATCH) + return status; + goto no_matches; + } /* We have successfully globbed the preceding directory name. - For each name we found, call glob_in_dir on it and FILENAME, - appending the results to PGLOB. */ + For each name we found, call glob_in_dir on it and FILENAME, + appending the results to PGLOB. */ for (i = 0; i < dirs.gl_pathc; ++i) - { - int old_pathc; - -#ifdef SHELL - { - /* Make globbing interruptible in the bash shell. */ - extern int interrupt_state; - - if (interrupt_state) - { - globfree (&dirs); - return GLOB_ABORTED; - } - } + { + int old_pathc; + +#ifdef SHELL + { + /* Make globbing interruptible in the bash shell. */ + extern int interrupt_state; + + if (interrupt_state) + { + globfree (&dirs); + return GLOB_ABORTED; + } + } #endif /* SHELL. */ - old_pathc = pglob->gl_pathc; - status = glob_in_dir (filename, dirs.gl_pathv[i], - ((flags | GLOB_APPEND) - & ~(GLOB_NOCHECK | GLOB_NOMAGIC)), - errfunc, pglob); - if (status == GLOB_NOMATCH) - /* No matches in this directory. Try the next. */ - continue; - - if (status != 0) - { - globfree (&dirs); - globfree (pglob); - pglob->gl_pathc = 0; - return status; - } - - /* Stick the directory on the front of each name. */ - if (prefix_array (dirs.gl_pathv[i], - &pglob->gl_pathv[old_pathc + pglob->gl_offs], - pglob->gl_pathc - old_pathc)) - { - globfree (&dirs); - globfree (pglob); - pglob->gl_pathc = 0; - return GLOB_NOSPACE; - } - } + old_pathc = pglob->gl_pathc; + status = glob_in_dir (filename, dirs.gl_pathv[i], + ((flags | GLOB_APPEND) + & ~(GLOB_NOCHECK | GLOB_NOMAGIC)), + errfunc, pglob); + if (status == GLOB_NOMATCH) + /* No matches in this directory. Try the next. */ + continue; + + if (status != 0) + { + globfree (&dirs); + globfree (pglob); + pglob->gl_pathc = 0; + return status; + } + + /* Stick the directory on the front of each name. */ + if (prefix_array (dirs.gl_pathv[i], + &pglob->gl_pathv[old_pathc + pglob->gl_offs], + pglob->gl_pathc - old_pathc)) + { + globfree (&dirs); + globfree (pglob); + pglob->gl_pathc = 0; + return GLOB_NOSPACE; + } + } flags |= GLOB_MAGCHAR; /* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls. - But if we have not found any matching entry and the GLOB_NOCHECK - flag was set we must return the input pattern itself. */ + But if we have not found any matching entry and the GLOB_NOCHECK + flag was set we must return the input pattern itself. */ if (pglob->gl_pathc + pglob->gl_offs == oldcount) - { - no_matches: - /* No matches. */ - if (flags & GLOB_NOCHECK) - { - int newcount = pglob->gl_pathc + pglob->gl_offs; - char **new_gl_pathv; - - new_gl_pathv = realloc (pglob->gl_pathv, - (newcount + 2) * sizeof (char *)); - if (new_gl_pathv == NULL) - { - globfree (&dirs); - return GLOB_NOSPACE; - } - pglob->gl_pathv = new_gl_pathv; - - pglob->gl_pathv[newcount] = strdup (pattern); - if (pglob->gl_pathv[newcount] == NULL) - { - globfree (&dirs); - globfree (pglob); - pglob->gl_pathc = 0; - return GLOB_NOSPACE; - } - - ++pglob->gl_pathc; - ++newcount; - - pglob->gl_pathv[newcount] = NULL; - pglob->gl_flags = flags; - } - else - { - globfree (&dirs); - return GLOB_NOMATCH; - } - } + { + no_matches: + /* No matches. */ + if (flags & GLOB_NOCHECK) + { + int newcount = pglob->gl_pathc + pglob->gl_offs; + char **new_gl_pathv; + + new_gl_pathv = realloc (pglob->gl_pathv, + (newcount + 2) * sizeof (char *)); + if (new_gl_pathv == NULL) + { + globfree (&dirs); + return GLOB_NOSPACE; + } + pglob->gl_pathv = new_gl_pathv; + + pglob->gl_pathv[newcount] = strdup (pattern); + if (pglob->gl_pathv[newcount] == NULL) + { + globfree (&dirs); + globfree (pglob); + pglob->gl_pathc = 0; + return GLOB_NOSPACE; + } + + ++pglob->gl_pathc; + ++newcount; + + pglob->gl_pathv[newcount] = NULL; + pglob->gl_flags = flags; + } + else + { + globfree (&dirs); + return GLOB_NOMATCH; + } + } globfree (&dirs); } @@ -994,54 +994,54 @@ glob (pattern, flags, errfunc, pglob) int orig_flags = flags; if (meta & 2) - { - char *p = strchr (dirname, '\\'), *q; - /* We need to unescape the dirname string. It is certainly - allocated by alloca, as otherwise filename would be NULL - or dirname wouldn't contain backslashes. */ - q = p; - do - { - if (*p == '\\') - { - *q = *++p; - --dirlen; - } - else - *q = *p; - ++q; - } - while (*p++ != '\0'); - dirname_modified = 1; - } + { + char *p = strchr (dirname, '\\'), *q; + /* We need to unescape the dirname string. It is certainly + allocated by alloca, as otherwise filename would be NULL + or dirname wouldn't contain backslashes. */ + q = p; + do + { + if (*p == '\\') + { + *q = *++p; + --dirlen; + } + else + *q = *p; + ++q; + } + while (*p++ != '\0'); + dirname_modified = 1; + } if (dirname_modified) - flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC); + flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC); status = glob_in_dir (filename, dirname, flags, errfunc, pglob); if (status != 0) - { - if (status == GLOB_NOMATCH && flags != orig_flags - && pglob->gl_pathc + pglob->gl_offs == oldcount) - { - /* Make sure globfree (&dirs); is a nop. */ - dirs.gl_pathv = NULL; - flags = orig_flags; - goto no_matches; - } - return status; - } + { + if (status == GLOB_NOMATCH && flags != orig_flags + && pglob->gl_pathc + pglob->gl_offs == oldcount) + { + /* Make sure globfree (&dirs); is a nop. */ + dirs.gl_pathv = NULL; + flags = orig_flags; + goto no_matches; + } + return status; + } if (dirlen > 0) - { - /* Stick the directory on the front of each name. */ - if (prefix_array (dirname, - &pglob->gl_pathv[old_pathc + pglob->gl_offs], - pglob->gl_pathc - old_pathc)) - { - globfree (pglob); - pglob->gl_pathc = 0; - return GLOB_NOSPACE; - } - } + { + /* Stick the directory on the front of each name. */ + if (prefix_array (dirname, + &pglob->gl_pathv[old_pathc + pglob->gl_offs], + pglob->gl_pathc - old_pathc)) + { + globfree (pglob); + pglob->gl_pathc = 0; + return GLOB_NOSPACE; + } + } } if (flags & GLOB_MARK) @@ -1052,31 +1052,31 @@ glob (pattern, flags, errfunc, pglob) struct_stat64 st64; for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; ++i) - if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? ((*pglob->gl_stat) (pglob->gl_pathv[i], &st) == 0 - && S_ISDIR (st.st_mode)) - : (__stat64 (pglob->gl_pathv[i], &st64) == 0 - && S_ISDIR (st64.st_mode)))) - { - size_t len = strlen (pglob->gl_pathv[i]) + 2; - char *new = realloc (pglob->gl_pathv[i], len); - if (new == NULL) - { - globfree (pglob); - pglob->gl_pathc = 0; - return GLOB_NOSPACE; - } - strcpy (&new[len - 2], "/"); - pglob->gl_pathv[i] = new; - } + if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) + ? ((*pglob->gl_stat) (pglob->gl_pathv[i], &st) == 0 + && S_ISDIR (st.st_mode)) + : (__stat64 (pglob->gl_pathv[i], &st64) == 0 + && S_ISDIR (st64.st_mode)))) + { + size_t len = strlen (pglob->gl_pathv[i]) + 2; + char *new = realloc (pglob->gl_pathv[i], len); + if (new == NULL) + { + globfree (pglob); + pglob->gl_pathc = 0; + return GLOB_NOSPACE; + } + strcpy (&new[len - 2], "/"); + pglob->gl_pathv[i] = new; + } } if (!(flags & GLOB_NOSORT)) { /* Sort the vector. */ qsort (&pglob->gl_pathv[oldcount], - pglob->gl_pathc + pglob->gl_offs - oldcount, - sizeof (char *), collated_compare); + pglob->gl_pathc + pglob->gl_offs - oldcount, + sizeof (char *), collated_compare); } return 0; @@ -1097,8 +1097,8 @@ globfree (pglob) { size_t i; for (i = 0; i < pglob->gl_pathc; ++i) - if (pglob->gl_pathv[pglob->gl_offs + i] != NULL) - free (pglob->gl_pathv[pglob->gl_offs + i]); + if (pglob->gl_pathv[pglob->gl_offs + i] != NULL) + free (pglob->gl_pathv[pglob->gl_offs + i]); free (pglob->gl_pathv); pglob->gl_pathv = NULL; } @@ -1149,14 +1149,14 @@ prefix_array (const char *dirname, char **array, size_t n) else if (dirlen > 1) { if (dirname[dirlen - 1] == '/' && dirname[dirlen - 2] == ':') - /* DIRNAME is "d:/". Don't prepend the slash from DIRNAME. */ - --dirlen; + /* DIRNAME is "d:/". Don't prepend the slash from DIRNAME. */ + --dirlen; else if (dirname[dirlen - 1] == ':') - { - /* DIRNAME is "d:". Use `:' instead of `/'. */ - --dirlen; - sep_char = ':'; - } + { + /* DIRNAME is "d:". Use `:' instead of `/'. */ + --dirlen; + sep_char = ':'; + } } #endif @@ -1165,16 +1165,16 @@ prefix_array (const char *dirname, char **array, size_t n) size_t eltlen = strlen (array[i]) + 1; char *new = malloc (dirlen + 1 + eltlen); if (new == NULL) - { - while (i > 0) - free (array[--i]); - return 1; - } + { + while (i > 0) + free (array[--i]); + return 1; + } { - char *endp = mempcpy (new, dirname, dirlen); - *endp++ = DIRSEP_CHAR; - mempcpy (endp, array[i], eltlen); + char *endp = mempcpy (new, dirname, dirlen); + *endp++ = DIRSEP_CHAR; + mempcpy (endp, array[i], eltlen); } free (array[i]); array[i] = new; @@ -1199,25 +1199,25 @@ __glob_pattern_type (pattern, quote) { case '?': case '*': - return 1; + return 1; case '\\': - if (quote) - { - if (p[1] != '\0') - ++p; - ret |= 2; - } - break; + if (quote) + { + if (p[1] != '\0') + ++p; + ret |= 2; + } + break; case '[': - ret |= 4; - break; + ret |= 4; + break; case ']': - if (ret & 4) - return 1; - break; + if (ret & 4) + return 1; + break; } return ret; @@ -1246,18 +1246,18 @@ weak_alias (__glob_pattern_p, glob_pattern_p) static int __attribute_noinline__ link_exists2_p (const char *dir, size_t dirlen, const char *fname, - glob_t *pglob + glob_t *pglob # if !defined _LIBC && !HAVE_FSTATAT - , int flags + , int flags # endif - ) + ) { size_t fnamelen = strlen (fname); char *fullname = __alloca (dirlen + 1 + fnamelen + 1); struct stat st; mempcpy (mempcpy (mempcpy (fullname, dir, dirlen), "/", 1), - fname, fnamelen + 1); + fname, fnamelen + 1); # if !defined _LIBC && !HAVE_FSTATAT if (__builtin_expect ((flags & GLOB_ALTDIRFUNC) == 0, 1)) @@ -1272,7 +1272,7 @@ link_exists2_p (const char *dir, size_t dirlen, const char *fname, /* Return true if DIR/FNAME exists. */ static int link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, - glob_t *pglob, int flags) + glob_t *pglob, int flags) { # if defined _LIBC || HAVE_FSTATAT if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) @@ -1295,8 +1295,8 @@ link_exists_p (int dfd, const char *dir, size_t dirlen, const char *fname, The GLOB_APPEND flag is assumed to be set (always appends). */ static int glob_in_dir (const char *pattern, const char *directory, int flags, - int (*errfunc) (const char *, int), - glob_t *pglob) + int (*errfunc) (const char *, int), + glob_t *pglob) { size_t dirlen = strlen (directory); void *stream = NULL; @@ -1324,135 +1324,135 @@ glob_in_dir (const char *pattern, const char *directory, int flags, if (meta == 0 && (flags & (GLOB_NOCHECK|GLOB_NOMAGIC))) { /* We need not do any tests. The PATTERN contains no meta - characters and we must not return an error therefore the - result will always contain exactly one name. */ + characters and we must not return an error therefore the + result will always contain exactly one name. */ flags |= GLOB_NOCHECK; } else if (meta == 0) { /* Since we use the normal file functions we can also use stat() - to verify the file is there. */ + to verify the file is there. */ struct stat st; struct_stat64 st64; size_t patlen = strlen (pattern); char *fullname = __alloca (dirlen + 1 + patlen + 1); mempcpy (mempcpy (mempcpy (fullname, directory, dirlen), - "/", 1), - pattern, patlen + 1); + "/", 1), + pattern, patlen + 1); if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? (*pglob->gl_stat) (fullname, &st) - : __stat64 (fullname, &st64)) == 0) - /* We found this file to be existing. Now tell the rest - of the function to copy this name into the result. */ - flags |= GLOB_NOCHECK; + ? (*pglob->gl_stat) (fullname, &st) + : __stat64 (fullname, &st64)) == 0) + /* We found this file to be existing. Now tell the rest + of the function to copy this name into the result. */ + flags |= GLOB_NOCHECK; } else { stream = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? (*pglob->gl_opendir) (directory) - : opendir (directory)); + ? (*pglob->gl_opendir) (directory) + : opendir (directory)); if (stream == NULL) - { - if (errno != ENOTDIR - && ((errfunc != NULL && (*errfunc) (directory, errno)) - || (flags & GLOB_ERR))) - return GLOB_ABORTED; - } + { + if (errno != ENOTDIR + && ((errfunc != NULL && (*errfunc) (directory, errno)) + || (flags & GLOB_ERR))) + return GLOB_ABORTED; + } else - { - int dfd = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? -1 : dirfd ((DIR *) stream)); - int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) - | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) + { + int dfd = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) + ? -1 : dirfd ((DIR *) stream)); + int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0) + | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) #if defined _AMIGA || defined VMS - | FNM_CASEFOLD + | FNM_CASEFOLD #endif - ); - flags |= GLOB_MAGCHAR; + ); + flags |= GLOB_MAGCHAR; - while (1) - { - const char *name; - size_t len; + while (1) + { + const char *name; + size_t len; #if defined _LIBC && !defined COMPILE_GLOB64 - struct dirent64 *d; - union - { - struct dirent64 d64; - char room [offsetof (struct dirent64, d_name[0]) - + NAME_MAX + 1]; - } - d64buf; - - if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) - { - struct dirent *d32 = (*pglob->gl_readdir) (stream); - if (d32 != NULL) - { - CONVERT_DIRENT_DIRENT64 (&d64buf.d64, d32); - d = &d64buf.d64; - } - else - d = NULL; - } - else - d = __readdir64 (stream); + struct dirent64 *d; + union + { + struct dirent64 d64; + char room [offsetof (struct dirent64, d_name[0]) + + NAME_MAX + 1]; + } + d64buf; + + if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) + { + struct dirent *d32 = (*pglob->gl_readdir) (stream); + if (d32 != NULL) + { + CONVERT_DIRENT_DIRENT64 (&d64buf.d64, d32); + d = &d64buf.d64; + } + else + d = NULL; + } + else + d = __readdir64 (stream); #else - struct dirent *d = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? ((struct dirent *) - (*pglob->gl_readdir) (stream)) - : __readdir (stream)); + struct dirent *d = (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) + ? ((struct dirent *) + (*pglob->gl_readdir) (stream)) + : __readdir (stream)); #endif - if (d == NULL) - break; - if (! REAL_DIR_ENTRY (d)) - continue; - - /* If we shall match only directories use the information - provided by the dirent call if possible. */ - if ((flags & GLOB_ONLYDIR) && !DIRENT_MIGHT_BE_DIR (d)) - continue; - - name = d->d_name; - - if (fnmatch (pattern, name, fnm_flags) == 0) - { - /* If the file we found is a symlink we have to - make sure the target file exists. */ - if (!DIRENT_MIGHT_BE_SYMLINK (d) - || link_exists_p (dfd, directory, dirlen, name, pglob, - flags)) - { - if (cur == names->count) - { - struct globnames *newnames; - size_t count = names->count * 2; - size_t size = (sizeof (struct globnames) - + ((count - INITIAL_COUNT) - * sizeof (char *))); - allocasize += size; - if (__libc_use_alloca (allocasize)) - newnames = names_alloca = __alloca (size); - else if ((newnames = malloc (size)) - == NULL) - goto memory_error; - newnames->count = count; - newnames->next = names; - names = newnames; - cur = 0; - } - len = _D_EXACT_NAMLEN (d); - names->name[cur] = malloc (len + 1); - if (names->name[cur] == NULL) - goto memory_error; - *((char *) mempcpy (names->name[cur++], name, len)) - = '\0'; - ++nfound; - } - } - } - } + if (d == NULL) + break; + if (! REAL_DIR_ENTRY (d)) + continue; + + /* If we shall match only directories use the information + provided by the dirent call if possible. */ + if ((flags & GLOB_ONLYDIR) && !DIRENT_MIGHT_BE_DIR (d)) + continue; + + name = d->d_name; + + if (fnmatch (pattern, name, fnm_flags) == 0) + { + /* If the file we found is a symlink we have to + make sure the target file exists. */ + if (!DIRENT_MIGHT_BE_SYMLINK (d) + || link_exists_p (dfd, directory, dirlen, name, pglob, + flags)) + { + if (cur == names->count) + { + struct globnames *newnames; + size_t count = names->count * 2; + size_t size = (sizeof (struct globnames) + + ((count - INITIAL_COUNT) + * sizeof (char *))); + allocasize += size; + if (__libc_use_alloca (allocasize)) + newnames = names_alloca = __alloca (size); + else if ((newnames = malloc (size)) + == NULL) + goto memory_error; + newnames->count = count; + newnames->next = names; + names = newnames; + cur = 0; + } + len = _D_EXACT_NAMLEN (d); + names->name[cur] = malloc (len + 1); + if (names->name[cur] == NULL) + goto memory_error; + *((char *) mempcpy (names->name[cur++], name, len)) + = '\0'; + ++nfound; + } + } + } + } } if (nfound == 0 && (flags & GLOB_NOCHECK)) @@ -1461,7 +1461,7 @@ glob_in_dir (const char *pattern, const char *directory, int flags, nfound = 1; names->name[cur] = malloc (len + 1); if (names->name[cur] == NULL) - goto memory_error; + goto memory_error; *((char *) mempcpy (names->name[cur++], pattern, len)) = '\0'; } @@ -1469,79 +1469,79 @@ glob_in_dir (const char *pattern, const char *directory, int flags, if (nfound != 0) { char **new_gl_pathv - = realloc (pglob->gl_pathv, - (pglob->gl_pathc + pglob->gl_offs + nfound + 1) - * sizeof (char *)); + = realloc (pglob->gl_pathv, + (pglob->gl_pathc + pglob->gl_offs + nfound + 1) + * sizeof (char *)); result = 0; if (new_gl_pathv == NULL) - { - memory_error: - while (1) - { - struct globnames *old = names; - size_t i; - for (i = 0; i < cur; ++i) - free (names->name[i]); - names = names->next; - /* NB: we will not leak memory here if we exit without - freeing the current block assigned to OLD. At least - the very first block is always allocated on the stack - and this is the block assigned to OLD here. */ - if (names == NULL) - { - assert (old == &init_names); - break; - } - cur = names->count; - if (old == names_alloca) - names_alloca = names; - else - free (old); - } - result = GLOB_NOSPACE; - } + { + memory_error: + while (1) + { + struct globnames *old = names; + size_t i; + for (i = 0; i < cur; ++i) + free (names->name[i]); + names = names->next; + /* NB: we will not leak memory here if we exit without + freeing the current block assigned to OLD. At least + the very first block is always allocated on the stack + and this is the block assigned to OLD here. */ + if (names == NULL) + { + assert (old == &init_names); + break; + } + cur = names->count; + if (old == names_alloca) + names_alloca = names; + else + free (old); + } + result = GLOB_NOSPACE; + } else - { - while (1) - { - struct globnames *old = names; - size_t i; - for (i = 0; i < cur; ++i) - new_gl_pathv[pglob->gl_offs + pglob->gl_pathc++] - = names->name[i]; - names = names->next; - /* NB: we will not leak memory here if we exit without - freeing the current block assigned to OLD. At least - the very first block is always allocated on the stack - and this is the block assigned to OLD here. */ - if (names == NULL) - { - assert (old == &init_names); - break; - } - cur = names->count; - if (old == names_alloca) - names_alloca = names; - else - free (old); - } - - pglob->gl_pathv = new_gl_pathv; - - pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; - - pglob->gl_flags = flags; - } + { + while (1) + { + struct globnames *old = names; + size_t i; + for (i = 0; i < cur; ++i) + new_gl_pathv[pglob->gl_offs + pglob->gl_pathc++] + = names->name[i]; + names = names->next; + /* NB: we will not leak memory here if we exit without + freeing the current block assigned to OLD. At least + the very first block is always allocated on the stack + and this is the block assigned to OLD here. */ + if (names == NULL) + { + assert (old == &init_names); + break; + } + cur = names->count; + if (old == names_alloca) + names_alloca = names; + else + free (old); + } + + pglob->gl_pathv = new_gl_pathv; + + pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; + + pglob->gl_flags = flags; + } } if (stream != NULL) { save = errno; if (__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)) - (*pglob->gl_closedir) (stream); + (*pglob->gl_closedir) (stream); else - closedir (stream); + closedir (stream); __set_errno (save); } diff --git a/lib/glob.in.h b/lib/glob.in.h index 058981780..09e106b76 100644 --- a/lib/glob.in.h +++ b/lib/glob.in.h @@ -41,7 +41,7 @@ #endif #ifndef __size_t -# define __size_t size_t +# define __size_t size_t #endif #ifndef __USE_GNU # define __USE_GNU 1 diff --git a/lib/glthread/cond.c b/lib/glthread/cond.c index bc7623358..cca848957 100644 --- a/lib/glthread/cond.c +++ b/lib/glthread/cond.c @@ -30,8 +30,8 @@ int glthread_cond_timedwait_multithreaded (gl_cond_t *cond, - gl_lock_t *lock, - struct timespec *abstime) + gl_lock_t *lock, + struct timespec *abstime) { int ret, status; pth_event_t ev; @@ -58,8 +58,8 @@ glthread_cond_timedwait_multithreaded (gl_cond_t *cond, int glthread_cond_timedwait_multithreaded (gl_cond_t *cond, - gl_lock_t *lock, - struct timespec *abstime) + gl_lock_t *lock, + struct timespec *abstime) { int ret; @@ -160,7 +160,7 @@ gl_waitqueue_notify_first (gl_waitqueue_t *wq) if (wq->wq_list.wql_next != &wq->wq_list) { struct gl_waitqueue_element *elt = - (struct gl_waitqueue_element *) wq->wq_list.wql_next; + (struct gl_waitqueue_element *) wq->wq_list.wql_next; struct gl_waitqueue_link *prev; struct gl_waitqueue_link *next; @@ -174,7 +174,7 @@ gl_waitqueue_notify_first (gl_waitqueue_t *wq) SetEvent (elt->event); /* After the SetEvent, this thread cannot access *elt any more, because - the woken-up thread will quickly call free (elt). */ + the woken-up thread will quickly call free (elt). */ } } @@ -200,7 +200,7 @@ gl_waitqueue_notify_all (gl_waitqueue_t *wq) SetEvent (elt->event); /* After the SetEvent, this thread cannot access *elt any more, because - the woken-up thread will quickly call free (elt). */ + the woken-up thread will quickly call free (elt). */ l = next; } @@ -225,14 +225,14 @@ glthread_cond_wait_func (gl_cond_t *cond, gl_lock_t *lock) if (!cond->guard.done) { if (InterlockedIncrement (&cond->guard.started) == 0) - /* This thread is the first one to need this condition variable. - Initialize it. */ - glthread_cond_init (cond); + /* This thread is the first one to need this condition variable. + Initialize it. */ + glthread_cond_init (cond); else - /* Yield the CPU while waiting for another thread to finish - initializing this condition variable. */ - while (!cond->guard.done) - Sleep (0); + /* Yield the CPU while waiting for another thread to finish + initializing this condition variable. */ + while (!cond->guard.done) + Sleep (0); } EnterCriticalSection (&cond->lock); @@ -241,43 +241,43 @@ glthread_cond_wait_func (gl_cond_t *cond, gl_lock_t *lock) LeaveCriticalSection (&cond->lock); if (elt == NULL) { - /* Allocation failure. Weird. */ - return EAGAIN; + /* Allocation failure. Weird. */ + return EAGAIN; } else { - HANDLE event = elt->event; - int err; - DWORD result; - - /* Now release the lock and let any other thread take it. */ - err = glthread_lock_unlock (lock); - if (err != 0) - { - EnterCriticalSection (&cond->lock); - gl_waitqueue_remove (&cond->waiters, elt); - LeaveCriticalSection (&cond->lock); - CloseHandle (event); - free (elt); - return err; - } - /* POSIX says: - "If another thread is able to acquire the mutex after the - about-to-block thread has released it, then a subsequent call to - pthread_cond_broadcast() or pthread_cond_signal() in that thread - shall behave as if it were issued after the about-to-block thread - has blocked." - This is fulfilled here, because the thread signalling is done - through SetEvent, not PulseEvent. */ - /* Wait until another thread signals this event. */ - result = WaitForSingleObject (event, INFINITE); - if (result == WAIT_FAILED || result == WAIT_TIMEOUT) - abort (); - CloseHandle (event); - free (elt); - /* The thread which signalled the event already did the bookkeeping: - removed us from the waiters. */ - return glthread_lock_lock (lock); + HANDLE event = elt->event; + int err; + DWORD result; + + /* Now release the lock and let any other thread take it. */ + err = glthread_lock_unlock (lock); + if (err != 0) + { + EnterCriticalSection (&cond->lock); + gl_waitqueue_remove (&cond->waiters, elt); + LeaveCriticalSection (&cond->lock); + CloseHandle (event); + free (elt); + return err; + } + /* POSIX says: + "If another thread is able to acquire the mutex after the + about-to-block thread has released it, then a subsequent call to + pthread_cond_broadcast() or pthread_cond_signal() in that thread + shall behave as if it were issued after the about-to-block thread + has blocked." + This is fulfilled here, because the thread signalling is done + through SetEvent, not PulseEvent. */ + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + free (elt); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiters. */ + return glthread_lock_lock (lock); } } } @@ -290,20 +290,20 @@ glthread_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec gettimeofday (&currtime, NULL); if (currtime.tv_sec > abstime->tv_sec || (currtime.tv_sec == abstime->tv_sec - && currtime.tv_usec * 1000 >= abstime->tv_nsec)) + && currtime.tv_usec * 1000 >= abstime->tv_nsec)) return ETIMEDOUT; if (!cond->guard.done) { if (InterlockedIncrement (&cond->guard.started) == 0) - /* This thread is the first one to need this condition variable. - Initialize it. */ - glthread_cond_init (cond); + /* This thread is the first one to need this condition variable. + Initialize it. */ + glthread_cond_init (cond); else - /* Yield the CPU while waiting for another thread to finish - initializing this condition variable. */ - while (!cond->guard.done) - Sleep (0); + /* Yield the CPU while waiting for another thread to finish + initializing this condition variable. */ + while (!cond->guard.done) + Sleep (0); } EnterCriticalSection (&cond->lock); @@ -312,103 +312,103 @@ glthread_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec LeaveCriticalSection (&cond->lock); if (elt == NULL) { - /* Allocation failure. Weird. */ - return EAGAIN; + /* Allocation failure. Weird. */ + return EAGAIN; } else { - HANDLE event = elt->event; - int err; - DWORD timeout; - DWORD result; - - /* Now release the lock and let any other thread take it. */ - err = glthread_lock_unlock (lock); - if (err != 0) - { - EnterCriticalSection (&cond->lock); - gl_waitqueue_remove (&cond->waiters, elt); - LeaveCriticalSection (&cond->lock); - CloseHandle (event); - free (elt); - return err; - } - /* POSIX says: - "If another thread is able to acquire the mutex after the - about-to-block thread has released it, then a subsequent call to - pthread_cond_broadcast() or pthread_cond_signal() in that thread - shall behave as if it were issued after the about-to-block thread - has blocked." - This is fulfilled here, because the thread signalling is done - through SetEvent, not PulseEvent. */ - /* Wait until another thread signals this event or until the abstime - passes. */ - gettimeofday (&currtime, NULL); - if (currtime.tv_sec > abstime->tv_sec) - timeout = 0; - else - { - unsigned long seconds = abstime->tv_sec - currtime.tv_sec; - timeout = seconds * 1000; - if (timeout / 1000 != seconds) /* overflow? */ - timeout = INFINITE; - else - { - long milliseconds = - abstime->tv_nsec / 1000000 - currtime.tv_usec / 1000; - if (milliseconds >= 0) - { - timeout += milliseconds; - if (timeout < milliseconds) /* overflow? */ - timeout = INFINITE; - } - else - { - if (timeout >= - milliseconds) - timeout -= (- milliseconds); - else - timeout = 0; - } - } - } - result = WaitForSingleObject (event, timeout); - if (result == WAIT_FAILED) - abort (); - if (result == WAIT_TIMEOUT) - { - EnterCriticalSection (&cond->lock); - if (gl_waitqueue_remove (&cond->waiters, elt)) - { - /* The event was not signaled between the WaitForSingleObject - call and the EnterCriticalSection call. */ - if (!(WaitForSingleObject (event, 0) == WAIT_TIMEOUT)) - abort (); - } - else - { - /* The event was signaled between the WaitForSingleObject - call and the EnterCriticalSection call. */ - if (!(WaitForSingleObject (event, 0) == WAIT_OBJECT_0)) - abort (); - /* Produce the right return value. */ - result = WAIT_OBJECT_0; - } - LeaveCriticalSection (&cond->lock); - } - else - { - /* The thread which signalled the event already did the - bookkeeping: removed us from the waiters. */ - } - CloseHandle (event); - free (elt); - /* Take the lock again. It does not matter whether this is done - before or after the bookkeeping for WAIT_TIMEOUT. */ - err = glthread_lock_lock (lock); - return (err ? err : - result == WAIT_OBJECT_0 ? 0 : - result == WAIT_TIMEOUT ? ETIMEDOUT : - /* WAIT_FAILED shouldn't happen */ EAGAIN); + HANDLE event = elt->event; + int err; + DWORD timeout; + DWORD result; + + /* Now release the lock and let any other thread take it. */ + err = glthread_lock_unlock (lock); + if (err != 0) + { + EnterCriticalSection (&cond->lock); + gl_waitqueue_remove (&cond->waiters, elt); + LeaveCriticalSection (&cond->lock); + CloseHandle (event); + free (elt); + return err; + } + /* POSIX says: + "If another thread is able to acquire the mutex after the + about-to-block thread has released it, then a subsequent call to + pthread_cond_broadcast() or pthread_cond_signal() in that thread + shall behave as if it were issued after the about-to-block thread + has blocked." + This is fulfilled here, because the thread signalling is done + through SetEvent, not PulseEvent. */ + /* Wait until another thread signals this event or until the abstime + passes. */ + gettimeofday (&currtime, NULL); + if (currtime.tv_sec > abstime->tv_sec) + timeout = 0; + else + { + unsigned long seconds = abstime->tv_sec - currtime.tv_sec; + timeout = seconds * 1000; + if (timeout / 1000 != seconds) /* overflow? */ + timeout = INFINITE; + else + { + long milliseconds = + abstime->tv_nsec / 1000000 - currtime.tv_usec / 1000; + if (milliseconds >= 0) + { + timeout += milliseconds; + if (timeout < milliseconds) /* overflow? */ + timeout = INFINITE; + } + else + { + if (timeout >= - milliseconds) + timeout -= (- milliseconds); + else + timeout = 0; + } + } + } + result = WaitForSingleObject (event, timeout); + if (result == WAIT_FAILED) + abort (); + if (result == WAIT_TIMEOUT) + { + EnterCriticalSection (&cond->lock); + if (gl_waitqueue_remove (&cond->waiters, elt)) + { + /* The event was not signaled between the WaitForSingleObject + call and the EnterCriticalSection call. */ + if (!(WaitForSingleObject (event, 0) == WAIT_TIMEOUT)) + abort (); + } + else + { + /* The event was signaled between the WaitForSingleObject + call and the EnterCriticalSection call. */ + if (!(WaitForSingleObject (event, 0) == WAIT_OBJECT_0)) + abort (); + /* Produce the right return value. */ + result = WAIT_OBJECT_0; + } + LeaveCriticalSection (&cond->lock); + } + else + { + /* The thread which signalled the event already did the + bookkeeping: removed us from the waiters. */ + } + CloseHandle (event); + free (elt); + /* Take the lock again. It does not matter whether this is done + before or after the bookkeeping for WAIT_TIMEOUT. */ + err = glthread_lock_lock (lock); + return (err ? err : + result == WAIT_OBJECT_0 ? 0 : + result == WAIT_TIMEOUT ? ETIMEDOUT : + /* WAIT_FAILED shouldn't happen */ EAGAIN); } } } diff --git a/lib/glthread/lock.c b/lib/glthread/lock.c index dc44d0869..842474ac5 100644 --- a/lib/glthread/lock.c +++ b/lib/glthread/lock.c @@ -56,19 +56,19 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) err = pthread_mutex_lock (&lock->guard); if (err != 0) - return err; + return err; if (!lock->initialized) - { - err = glthread_rwlock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } + { + 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 err; } return pthread_rwlock_rdlock (&lock->rwlock); } @@ -82,19 +82,19 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) err = pthread_mutex_lock (&lock->guard); if (err != 0) - return err; + return err; if (!lock->initialized) - { - err = glthread_rwlock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } + { + 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 err; } return pthread_rwlock_wrlock (&lock->rwlock); } @@ -161,13 +161,13 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) { /* This thread has to wait for a while. Enqueue it among the - waiting_readers. */ + waiting_readers. */ err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); if (err != 0) - { - pthread_mutex_unlock (&lock->lock); - return err; - } + { + pthread_mutex_unlock (&lock->lock); + return err; + } } lock->runcount++; return pthread_mutex_unlock (&lock->lock); @@ -185,15 +185,15 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) while (!(lock->runcount == 0)) { /* This thread has to wait for a while. Enqueue it among the - waiting_writers. */ + 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--; + pthread_mutex_unlock (&lock->lock); + return err; + } lock->waiting_writers_count--; } lock->runcount--; /* runcount becomes -1 */ @@ -212,46 +212,46 @@ glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) { /* Drop a writer lock. */ if (!(lock->runcount == -1)) - { - pthread_mutex_unlock (&lock->lock); - return EINVAL; - } + { + 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; - } + { + 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". */ + 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; - } - } + { + /* 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; - } - } + { + /* 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); } @@ -347,19 +347,19 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) err = pthread_mutex_lock (&lock->guard); if (err != 0) - return err; + return err; if (!lock->initialized) - { - err = glthread_recursive_lock_init_multithreaded (lock); - if (err != 0) - { - pthread_mutex_unlock (&lock->guard); - return err; - } - } + { + 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 err; } return pthread_mutex_lock (&lock->recmutex); } @@ -413,7 +413,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) err = pthread_mutex_lock (&lock->mutex); if (err != 0) - return err; + return err; lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ @@ -552,7 +552,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) err = mutex_lock (&lock->mutex); if (err != 0) - return err; + return err; lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ @@ -597,15 +597,15 @@ glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void int err; /* Use the mutex to guarantee that if another thread is already calling - the initfunction, this thread waits until it's finished. */ + the initfunction, this thread waits until it's finished. */ err = mutex_lock (&once_control->mutex); if (err != 0) - return err; + return err; if (!once_control->inited) - { - once_control->inited = 1; - initfunction (); - } + { + once_control->inited = 1; + initfunction (); + } return mutex_unlock (&once_control->mutex); } else @@ -647,13 +647,13 @@ 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); + /* 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); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); } EnterCriticalSection (&lock->lock); return 0; @@ -704,28 +704,28 @@ gl_waitqueue_add (gl_waitqueue_t *wq) { unsigned int new_alloc = 2 * wq->alloc + 1; HANDLE *new_array = - (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); + (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); if (new_array == NULL) - /* No more memory. */ - return INVALID_HANDLE_VALUE; + /* No more memory. */ + return INVALID_HANDLE_VALUE; /* Now is a good opportunity to rotate the array so that its contents - starts at offset 0. */ + 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; - } + { + 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; } @@ -764,7 +764,7 @@ gl_waitqueue_notify_all (gl_waitqueue_t *wq) { unsigned int index = wq->offset + i; if (index >= wq->alloc) - index -= wq->alloc; + index -= wq->alloc; SetEvent (wq->array[index]); } wq->count = 0; @@ -787,13 +787,13 @@ 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); + /* 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); + /* 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 @@ -801,34 +801,34 @@ glthread_rwlock_rdlock_func (gl_rwlock_t *lock) if (!(lock->runcount + 1 > 0)) { /* This thread has to wait for a while. Enqueue it among the - waiting_readers. */ + 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; - } + { + 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)); - } + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount + 1 > 0)); + } } lock->runcount++; LeaveCriticalSection (&lock->lock); @@ -841,47 +841,47 @@ 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); + /* 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); + /* 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. */ + 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; - } + { + 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)); - } + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount == 0)); + } } lock->runcount--; /* runcount becomes -1 */ LeaveCriticalSection (&lock->lock); @@ -898,35 +898,35 @@ glthread_rwlock_unlock_func (gl_rwlock_t *lock) { /* Drop a writer lock. */ if (!(lock->runcount == -1)) - abort (); + abort (); lock->runcount = 0; } else { /* Drop a reader lock. */ if (!(lock->runcount > 0)) - { - LeaveCriticalSection (&lock->lock); - return EPERM; - } + { + 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". */ + 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); - } + { + /* 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); - } + { + /* Wake up all waiting readers. */ + lock->runcount += lock->waiting_readers.count; + gl_waitqueue_notify_all (&lock->waiting_readers); + } } LeaveCriticalSection (&lock->lock); return 0; @@ -965,25 +965,25 @@ 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); + /* 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); + /* 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; + EnterCriticalSection (&lock->lock); + lock->owner = self; } if (++(lock->depth) == 0) /* wraparound? */ { - lock->depth--; - return EAGAIN; + lock->depth--; + return EAGAIN; } } return 0; @@ -1022,34 +1022,34 @@ 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); - } + { + /* 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 (); - } - } + { + /* 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 (); + } + } } } diff --git a/lib/glthread/thread.c b/lib/glthread/thread.c index fa8aede79..ba108d0a6 100644 --- a/lib/glthread/thread.c +++ b/lib/glthread/thread.c @@ -80,8 +80,8 @@ get_current_thread_handle (void) /* GetCurrentThread() returns a pseudo-handle, i.e. only a symbolic identifier, not a real handle. */ if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), - GetCurrentProcess (), &this_handle, - 0, FALSE, DUPLICATE_SAME_ACCESS)) + GetCurrentProcess (), &this_handle, + 0, FALSE, DUPLICATE_SAME_ACCESS)) abort (); return this_handle; } @@ -97,18 +97,18 @@ gl_thread_self_func (void) if (thread == NULL) { /* This happens only in threads that have not been created through - glthread_create(), such as the main thread. */ + glthread_create(), such as the main thread. */ for (;;) - { - thread = - (struct gl_thread_struct *) - malloc (sizeof (struct gl_thread_struct)); - if (thread != NULL) - break; - /* Memory allocation failed. There is not much we can do. Have to - busy-loop, waiting for the availability of memory. */ - Sleep (1); - } + { + thread = + (struct gl_thread_struct *) + malloc (sizeof (struct gl_thread_struct)); + if (thread != NULL) + break; + /* Memory allocation failed. There is not much we can do. Have to + busy-loop, waiting for the availability of memory. */ + Sleep (1); + } thread->handle = get_current_thread_handle (); InitializeCriticalSection (&thread->handle_lock); @@ -164,9 +164,9 @@ glthread_create_func (gl_thread_t *threadp, void * (*func) (void *), void *arg) /* calls CreateThread with the same arguments */ if (thread_handle == NULL) { - DeleteCriticalSection (&thread->handle_lock); - free (thread); - return EAGAIN; + DeleteCriticalSection (&thread->handle_lock); + free (thread); + return EAGAIN; } EnterCriticalSection (&thread->handle_lock); diff --git a/lib/glthread/threadlib.c b/lib/glthread/threadlib.c index 791c43094..41b0cc60e 100644 --- a/lib/glthread/threadlib.c +++ b/lib/glthread/threadlib.c @@ -48,16 +48,16 @@ glthread_in_use (void) pthread_t thread; if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) - /* Thread creation failed. */ - result = 0; + /* Thread creation failed. */ + result = 0; else - { - /* Thread creation works. */ - void *retval; - if (pthread_join (thread, &retval) != 0) - abort (); - result = 1; - } + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } tested = 1; } return result; diff --git a/lib/hard-locale.c b/lib/hard-locale.c index 25e66bce3..f45854373 100644 --- a/lib/hard-locale.c +++ b/lib/hard-locale.c @@ -41,29 +41,29 @@ hard_locale (int category) if (p) { if (2 <= GLIBC_VERSION) - { - if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) - hard = false; - } + { + if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) + hard = false; + } else - { - char *locale = strdup (p); - if (locale) - { - /* Temporarily set the locale to the "C" and "POSIX" locales - to find their names, so that we can determine whether one - or the other is the caller's locale. */ - if (((p = setlocale (category, "C")) - && strcmp (p, locale) == 0) - || ((p = setlocale (category, "POSIX")) - && strcmp (p, locale) == 0)) - hard = false; + { + char *locale = strdup (p); + if (locale) + { + /* Temporarily set the locale to the "C" and "POSIX" locales + to find their names, so that we can determine whether one + or the other is the caller's locale. */ + if (((p = setlocale (category, "C")) + && strcmp (p, locale) == 0) + || ((p = setlocale (category, "POSIX")) + && strcmp (p, locale) == 0)) + hard = false; - /* Restore the caller's locale. */ - setlocale (category, locale); - free (locale); - } - } + /* Restore the caller's locale. */ + setlocale (category, locale); + free (locale); + } + } } return hard; diff --git a/lib/hash.c b/lib/hash.c index 3ab7136be..911440403 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -180,16 +180,16 @@ hash_get_max_bucket_length (const Hash_table *table) for (bucket = table->bucket; bucket < table->bucket_limit; bucket++) { if (bucket->data) - { - struct hash_entry const *cursor = bucket; - size_t bucket_length = 1; + { + struct hash_entry const *cursor = bucket; + size_t bucket_length = 1; - while (cursor = cursor->next, cursor) - bucket_length++; + while (cursor = cursor->next, cursor) + bucket_length++; - if (bucket_length > max_bucket_length) - max_bucket_length = bucket_length; - } + if (bucket_length > max_bucket_length) + max_bucket_length = bucket_length; + } } return max_bucket_length; @@ -208,17 +208,17 @@ hash_table_ok (const Hash_table *table) for (bucket = table->bucket; bucket < table->bucket_limit; bucket++) { if (bucket->data) - { - struct hash_entry const *cursor = bucket; + { + struct hash_entry const *cursor = bucket; - /* Count bucket head. */ - n_buckets_used++; - n_entries++; + /* Count bucket head. */ + n_buckets_used++; + n_entries++; - /* Count bucket overflow. */ - while (cursor = cursor->next, cursor) - 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) @@ -238,10 +238,10 @@ hash_print_statistics (const Hash_table *table, FILE *stream) 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); + (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); + (unsigned long int) max_bucket_length); } /* If ENTRY matches an entry already in the hash table, return the @@ -327,7 +327,7 @@ hash_get_next (const Hash_table *table, const void *entry) size_t hash_get_entries (const Hash_table *table, void **buffer, - size_t buffer_size) + size_t buffer_size) { size_t counter = 0; struct hash_entry const *bucket; @@ -336,14 +336,14 @@ hash_get_entries (const Hash_table *table, void **buffer, 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; - } - } + { + for (cursor = bucket; cursor; cursor = cursor->next) + { + if (counter >= buffer_size) + return counter; + buffer[counter++] = cursor->data; + } + } } return counter; @@ -359,7 +359,7 @@ hash_get_entries (const Hash_table *table, void **buffer, size_t hash_do_for_each (const Hash_table *table, Hash_processor processor, - void *processor_data) + void *processor_data) { size_t counter = 0; struct hash_entry const *bucket; @@ -368,14 +368,14 @@ hash_do_for_each (const Hash_table *table, Hash_processor processor, 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++; - } - } + { + for (cursor = bucket; cursor; cursor = cursor->next) + { + if (! processor (cursor->data, processor_data)) + return counter; + counter++; + } + } } return counter; @@ -540,7 +540,7 @@ compute_bucket_size (size_t candidate, const Hash_tuning *tuning) { float new_candidate = candidate / tuning->growth_threshold; if (SIZE_MAX <= new_candidate) - return 0; + return 0; candidate = new_candidate; } candidate = next_prime (candidate); @@ -585,8 +585,8 @@ compute_bucket_size (size_t candidate, const Hash_tuning *tuning) Hash_table * hash_initialize (size_t candidate, const Hash_tuning *tuning, - Hash_hasher hasher, Hash_comparator comparator, - Hash_data_freer data_freer) + Hash_hasher hasher, Hash_comparator comparator, + Hash_data_freer data_freer) { Hash_table *table; @@ -605,10 +605,10 @@ hash_initialize (size_t candidate, const Hash_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. */ + 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; } @@ -650,30 +650,30 @@ hash_clear (Hash_table *table) 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; - } + { + 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; @@ -696,13 +696,13 @@ hash_free (Hash_table *table) 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 (bucket->data) + { + for (cursor = bucket; cursor; cursor = cursor->next) + table->data_freer (cursor->data); + } + } } #if USE_OBSTACK @@ -715,10 +715,10 @@ hash_free (Hash_table *table) for (bucket = table->bucket; bucket < table->bucket_limit; bucket++) { for (cursor = bucket->next; cursor; cursor = next) - { - next = cursor->next; - free (cursor); - } + { + next = cursor->next; + free (cursor); + } } /* Also reclaim the internal list of previously freed entries. */ @@ -781,7 +781,7 @@ free_entry (Hash_table *table, struct hash_entry *entry) static void * hash_find_entry (Hash_table *table, const void *entry, - struct hash_entry **bucket_head, bool delete) + struct hash_entry **bucket_head, bool delete) { struct hash_entry *bucket = table->bucket + table->hasher (entry, table->n_buckets); @@ -802,21 +802,21 @@ hash_find_entry (Hash_table *table, const void *entry, 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; - } - } + { + 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; } @@ -825,22 +825,22 @@ hash_find_entry (Hash_table *table, const void *entry, 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; - } + || 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. */ @@ -862,74 +862,74 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool safe) 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 = (dst->bucket + dst->hasher (data, dst->n_buckets)); - - if (! (new_bucket < dst->bucket_limit)) - abort (); - - 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 = (dst->bucket + dst->hasher (data, dst->n_buckets)); - - if (! (new_bucket < dst->bucket_limit)) - abort (); - - 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--; + 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 = (dst->bucket + dst->hasher (data, dst->n_buckets)); + + if (! (new_bucket < dst->bucket_limit)) + abort (); + + 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 = (dst->bucket + dst->hasher (data, dst->n_buckets)); + + if (! (new_bucket < dst->bucket_limit)) + abort (); + + 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; } @@ -1014,7 +1014,7 @@ hash_rehash (Hash_table *table, size_t candidate) 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))) + && transfer_entries (table, new_table, false))) abort (); /* table->n_entries already holds its value. */ free (new_table->bucket); @@ -1050,29 +1050,29 @@ hash_insert (Hash_table *table, const void *entry) > 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. */ + 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 NULL; - - /* If the rehash fails, arrange to return NULL. */ - if (!hash_rehash (table, candidate)) - return NULL; - - /* Update the bucket we are interested in. */ - if (hash_find_entry (table, entry, &bucket, false) != NULL) - abort (); - } + > 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 NULL; + + /* If the rehash fails, arrange to return NULL. */ + if (!hash_rehash (table, candidate)) + return NULL; + + /* 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. */ @@ -1082,7 +1082,7 @@ hash_insert (Hash_table *table, const void *entry) struct hash_entry *new_entry = allocate_entry (table); if (new_entry == NULL) - return NULL; + return NULL; /* Add ENTRY in the overflow of the bucket. */ @@ -1122,45 +1122,45 @@ hash_delete (Hash_table *table, const void *entry) table->n_buckets_used--; /* If the shrink threshold of the buckets in use has been reached, - rehash into a smaller table. */ + 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. */ + < 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; + 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; @@ -1180,15 +1180,15 @@ hash_print (const Hash_table *table) struct hash_entry *cursor; if (bucket) - printf ("%lu:\n", (unsigned long int) (bucket - table->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); - } + { + char const *s = cursor->data; + /* FIXME */ + if (s) + printf (" %s\n", s); + } } } diff --git a/lib/hash.h b/lib/hash.h index c1e60ca10..267c3b296 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -47,11 +47,11 @@ 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 */ + 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; @@ -79,8 +79,8 @@ size_t hash_do_for_each (const Hash_table *, Hash_processor, void *); size_t hash_string (const char *, size_t); void hash_reset_tuning (Hash_tuning *); Hash_table *hash_initialize (size_t, const Hash_tuning *, - Hash_hasher, Hash_comparator, - Hash_data_freer) ATTRIBUTE_WUR; + Hash_hasher, Hash_comparator, + Hash_data_freer) ATTRIBUTE_WUR; void hash_clear (Hash_table *); void hash_free (Hash_table *); diff --git a/lib/hmac-md5.c b/lib/hmac-md5.c index d4e807ef0..9025fae9a 100644 --- a/lib/hmac-md5.c +++ b/lib/hmac-md5.c @@ -31,7 +31,7 @@ int hmac_md5 (const void *key, size_t keylen, - const void *in, size_t inlen, void *resbuf) + const void *in, size_t inlen, void *resbuf) { struct md5_ctx inner; struct md5_ctx outer; diff --git a/lib/hmac-sha1.c b/lib/hmac-sha1.c index c84545b9d..6b24ae5b5 100644 --- a/lib/hmac-sha1.c +++ b/lib/hmac-sha1.c @@ -31,7 +31,7 @@ int hmac_sha1 (const void *key, size_t keylen, - const void *in, size_t inlen, void *resbuf) + const void *in, size_t inlen, void *resbuf) { struct sha1_ctx inner; struct sha1_ctx outer; diff --git a/lib/hmac.h b/lib/hmac.h index b1359aac8..67e51014a 100644 --- a/lib/hmac.h +++ b/lib/hmac.h @@ -28,7 +28,7 @@ RESBUF buffer. Return 0 on success. */ int hmac_md5 (const void *key, size_t keylen, - const void *buffer, size_t buflen, void *resbuf); + const void *buffer, size_t buflen, void *resbuf); /* Compute Hashed Message Authentication Code with SHA-1, over BUFFER data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the @@ -36,6 +36,6 @@ hmac_md5 (const void *key, size_t keylen, success. */ int hmac_sha1 (const void *key, size_t keylen, - const void *in, size_t inlen, void *resbuf); + const void *in, size_t inlen, void *resbuf); #endif /* HMAC_H */ diff --git a/lib/human.c b/lib/human.c index c7291b732..ec7062752 100644 --- a/lib/human.c +++ b/lib/human.c @@ -36,15 +36,15 @@ static const char power_letter[] = { - 0, /* not used */ - 'K', /* kibi ('k' for kilo is a special case) */ - 'M', /* mega or mebi */ - 'G', /* giga or gibi */ - 'T', /* tera or tebi */ - 'P', /* peta or pebi */ - 'E', /* exa or exbi */ - 'Z', /* zetta or 2**70 */ - 'Y' /* yotta or 2**80 */ + 0, /* not used */ + 'K', /* kibi ('k' for kilo is a special case) */ + 'M', /* mega or mebi */ + 'G', /* giga or gibi */ + 'T', /* tera or tebi */ + 'P', /* peta or pebi */ + 'E', /* exa or exbi */ + 'Z', /* zetta or 2**70 */ + 'Y' /* yotta or 2**80 */ }; @@ -78,7 +78,7 @@ adjust_value (int inexact_style, long double value) static char * group_number (char *number, size_t numberlen, - char const *grouping, char const *thousands_sep) + char const *grouping, char const *thousands_sep) { register char *d; size_t grouplen = SIZE_MAX; @@ -97,19 +97,19 @@ group_number (char *number, size_t numberlen, unsigned char g = *grouping; if (g) - { - grouplen = g < CHAR_MAX ? g : i; - grouping++; - } + { + grouplen = g < CHAR_MAX ? g : i; + grouping++; + } if (i < grouplen) - grouplen = i; + grouplen = i; d -= grouplen; i -= grouplen; memcpy (d, buf + i, grouplen); if (i == 0) - return d; + return d; d -= thousands_seplen; memcpy (d, thousands_sep, thousands_seplen); @@ -152,7 +152,7 @@ group_number (char *number, size_t numberlen, char * human_readable (uintmax_t n, char *buf, int opts, - uintmax_t from_block_size, uintmax_t to_block_size) + uintmax_t from_block_size, uintmax_t to_block_size) { int inexact_style = opts & (human_round_to_nearest | human_floor | human_ceiling); @@ -195,16 +195,16 @@ human_readable (uintmax_t n, char *buf, int opts, if (to_block_size <= from_block_size) { if (from_block_size % to_block_size == 0) - { - uintmax_t multiplier = from_block_size / to_block_size; - amt = n * multiplier; - if (amt / multiplier == n) - { - tenths = 0; - rounding = 0; - goto use_integer_arithmetic; - } - } + { + uintmax_t multiplier = from_block_size / to_block_size; + amt = n * multiplier; + if (amt / multiplier == n) + { + tenths = 0; + rounding = 0; + goto use_integer_arithmetic; + } + } } else if (from_block_size != 0 && to_block_size % from_block_size == 0) { @@ -229,37 +229,37 @@ human_readable (uintmax_t n, char *buf, int opts, if (! (opts & human_autoscale)) { - sprintf (buf, "%.0Lf", adjust_value (inexact_style, damt)); - buflen = strlen (buf); - nonintegerlen = 0; + sprintf (buf, "%.0Lf", adjust_value (inexact_style, damt)); + buflen = strlen (buf); + nonintegerlen = 0; } else { - long double e = 1; - exponent = 0; - - do - { - e *= base; - exponent++; - } - while (e * base <= damt && exponent < exponent_max); - - damt /= e; - - sprintf (buf, "%.1Lf", adjust_value (inexact_style, damt)); - buflen = strlen (buf); - nonintegerlen = decimal_pointlen + 1; - - if (1 + nonintegerlen + ! (opts & human_base_1024) < buflen - || ((opts & human_suppress_point_zero) - && buf[buflen - 1] == '0')) - { - sprintf (buf, "%.0Lf", - adjust_value (inexact_style, damt * 10) / 10); - buflen = strlen (buf); - nonintegerlen = 0; - } + long double e = 1; + exponent = 0; + + do + { + e *= base; + exponent++; + } + while (e * base <= damt && exponent < exponent_max); + + damt /= e; + + sprintf (buf, "%.1Lf", adjust_value (inexact_style, damt)); + buflen = strlen (buf); + nonintegerlen = decimal_pointlen + 1; + + if (1 + nonintegerlen + ! (opts & human_base_1024) < buflen + || ((opts & human_suppress_point_zero) + && buf[buflen - 1] == '0')) + { + sprintf (buf, "%.0Lf", + adjust_value (inexact_style, damt * 10) / 10); + buflen = strlen (buf); + nonintegerlen = 0; + } } p = psuffix - buflen; @@ -277,77 +277,77 @@ human_readable (uintmax_t n, char *buf, int opts, if (opts & human_autoscale) { - exponent = 0; - - if (base <= amt) - { - do - { - unsigned int r10 = (amt % base) * 10 + tenths; - unsigned int r2 = (r10 % base) * 2 + (rounding >> 1); - amt /= base; - tenths = r10 / base; - rounding = (r2 < base - ? (r2 + rounding) != 0 - : 2 + (base < r2 + rounding)); - exponent++; - } - while (base <= amt && exponent < exponent_max); - - if (amt < 10) - { - if (inexact_style == human_round_to_nearest - ? 2 < rounding + (tenths & 1) - : inexact_style == human_ceiling && 0 < rounding) - { - tenths++; - rounding = 0; - - if (tenths == 10) - { - amt++; - tenths = 0; - } - } - - if (amt < 10 - && (tenths || ! (opts & human_suppress_point_zero))) - { - *--p = '0' + tenths; - p -= decimal_pointlen; - memcpy (p, decimal_point, decimal_pointlen); - tenths = rounding = 0; - } - } - } + exponent = 0; + + if (base <= amt) + { + do + { + unsigned int r10 = (amt % base) * 10 + tenths; + unsigned int r2 = (r10 % base) * 2 + (rounding >> 1); + amt /= base; + tenths = r10 / base; + rounding = (r2 < base + ? (r2 + rounding) != 0 + : 2 + (base < r2 + rounding)); + exponent++; + } + while (base <= amt && exponent < exponent_max); + + if (amt < 10) + { + if (inexact_style == human_round_to_nearest + ? 2 < rounding + (tenths & 1) + : inexact_style == human_ceiling && 0 < rounding) + { + tenths++; + rounding = 0; + + if (tenths == 10) + { + amt++; + tenths = 0; + } + } + + if (amt < 10 + && (tenths || ! (opts & human_suppress_point_zero))) + { + *--p = '0' + tenths; + p -= decimal_pointlen; + memcpy (p, decimal_point, decimal_pointlen); + tenths = rounding = 0; + } + } + } } if (inexact_style == human_round_to_nearest - ? 5 < tenths + (0 < rounding + (amt & 1)) - : inexact_style == human_ceiling && 0 < tenths + rounding) + ? 5 < tenths + (0 < rounding + (amt & 1)) + : inexact_style == human_ceiling && 0 < tenths + rounding) { - amt++; - - if ((opts & human_autoscale) - && amt == base && exponent < exponent_max) - { - exponent++; - if (! (opts & human_suppress_point_zero)) - { - *--p = '0'; - p -= decimal_pointlen; - memcpy (p, decimal_point, decimal_pointlen); - } - amt = 1; - } + amt++; + + if ((opts & human_autoscale) + && amt == base && exponent < exponent_max) + { + exponent++; + if (! (opts & human_suppress_point_zero)) + { + *--p = '0'; + p -= decimal_pointlen; + memcpy (p, decimal_point, decimal_pointlen); + } + amt = 1; + } } integerlim = p; do { - int digit = amt % 10; - *--p = digit + '0'; + int digit = amt % 10; + *--p = digit + '0'; } while ((amt /= 10) != 0); } @@ -359,28 +359,28 @@ human_readable (uintmax_t n, char *buf, int opts, if (opts & human_SI) { if (exponent < 0) - { - uintmax_t power; - exponent = 0; - for (power = 1; power < to_block_size; power *= base) - if (++exponent == exponent_max) - break; - } + { + uintmax_t power; + exponent = 0; + for (power = 1; power < to_block_size; power *= base) + if (++exponent == exponent_max) + break; + } if ((exponent | (opts & human_B)) && (opts & human_space_before_unit)) - *psuffix++ = ' '; + *psuffix++ = ' '; if (exponent) - *psuffix++ = (! (opts & human_base_1024) && exponent == 1 - ? 'k' - : power_letter[exponent]); + *psuffix++ = (! (opts & human_base_1024) && exponent == 1 + ? 'k' + : power_letter[exponent]); if (opts & human_B) - { - if ((opts & human_base_1024) && exponent) - *psuffix++ = 'i'; - *psuffix++ = 'B'; - } + { + if ((opts & human_base_1024) && exponent) + *psuffix++ = 'i'; + *psuffix++ = 'B'; + } } *psuffix = '\0'; @@ -421,37 +421,37 @@ humblock (char const *spec, uintmax_t *block_size, int *options) else { if (*spec == '\'') - { - opts |= human_group_digits; - spec++; - } + { + opts |= human_group_digits; + spec++; + } if (0 <= (i = ARGMATCH (spec, block_size_args, block_size_opts))) - { - opts |= block_size_opts[i]; - *block_size = 1; - } + { + opts |= block_size_opts[i]; + *block_size = 1; + } else - { - char *ptr; - strtol_error e = xstrtoumax (spec, &ptr, 0, block_size, - "eEgGkKmMpPtTyYzZ0"); - if (e != LONGINT_OK) - { - *options = 0; - return e; - } - for (; ! ('0' <= *spec && *spec <= '9'); spec++) - if (spec == ptr) - { - opts |= human_SI; - if (ptr[-1] == 'B') - opts |= human_B; - if (ptr[-1] != 'B' || ptr[-2] == 'i') - opts |= human_base_1024; - break; - } - } + { + char *ptr; + strtol_error e = xstrtoumax (spec, &ptr, 0, block_size, + "eEgGkKmMpPtTyYzZ0"); + if (e != LONGINT_OK) + { + *options = 0; + return e; + } + for (; ! ('0' <= *spec && *spec <= '9'); spec++) + if (spec == ptr) + { + opts |= human_SI; + if (ptr[-1] == 'B') + opts |= human_B; + if (ptr[-1] != 'B' || ptr[-2] == 'i') + opts |= human_base_1024; + break; + } + } } *options = opts; diff --git a/lib/iconv.c b/lib/iconv.c index ced09f2b1..587790b61 100644 --- a/lib/iconv.c +++ b/lib/iconv.c @@ -59,25 +59,25 @@ utf16be_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n) { ucs4_t wc = (s[0] << 8) + s[1]; if (wc >= 0xd800 && wc < 0xdc00) - { - if (n >= 4) - { - ucs4_t wc2 = (s[2] << 8) + s[3]; - if (!(wc2 >= 0xdc00 && wc2 < 0xe000)) - return RET_ILSEQ; - *pwc = 0x10000 + ((wc - 0xd800) << 10) + (wc2 - 0xdc00); - return 4; - } - } + { + if (n >= 4) + { + ucs4_t wc2 = (s[2] << 8) + s[3]; + if (!(wc2 >= 0xdc00 && wc2 < 0xe000)) + return RET_ILSEQ; + *pwc = 0x10000 + ((wc - 0xd800) << 10) + (wc2 - 0xdc00); + return 4; + } + } else if (wc >= 0xdc00 && wc < 0xe000) - { - return RET_ILSEQ; - } + { + return RET_ILSEQ; + } else - { - *pwc = wc; - return 2; - } + { + *pwc = wc; + return 2; + } } return RET_TOOFEW; } @@ -88,31 +88,31 @@ utf16be_wctomb (unsigned char *r, ucs4_t wc, size_t n) if (!(wc >= 0xd800 && wc < 0xe000)) { if (wc < 0x10000) - { - if (n >= 2) - { - r[0] = (unsigned char) (wc >> 8); - r[1] = (unsigned char) wc; - return 2; - } - else - return RET_TOOSMALL; - } + { + if (n >= 2) + { + r[0] = (unsigned char) (wc >> 8); + r[1] = (unsigned char) wc; + return 2; + } + else + return RET_TOOSMALL; + } else if (wc < 0x110000) - { - if (n >= 4) - { - ucs4_t wc1 = 0xd800 + ((wc - 0x10000) >> 10); - ucs4_t wc2 = 0xdc00 + ((wc - 0x10000) & 0x3ff); - r[0] = (unsigned char) (wc1 >> 8); - r[1] = (unsigned char) wc1; - r[2] = (unsigned char) (wc2 >> 8); - r[3] = (unsigned char) wc2; - return 4; - } - else - return RET_TOOSMALL; - } + { + if (n >= 4) + { + ucs4_t wc1 = 0xd800 + ((wc - 0x10000) >> 10); + ucs4_t wc2 = 0xdc00 + ((wc - 0x10000) & 0x3ff); + r[0] = (unsigned char) (wc1 >> 8); + r[1] = (unsigned char) wc1; + r[2] = (unsigned char) (wc2 >> 8); + r[3] = (unsigned char) wc2; + return 4; + } + else + return RET_TOOSMALL; + } } return RET_ILUNI; } @@ -130,25 +130,25 @@ utf16le_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n) { ucs4_t wc = s[0] + (s[1] << 8); if (wc >= 0xd800 && wc < 0xdc00) - { - if (n >= 4) - { - ucs4_t wc2 = s[2] + (s[3] << 8); - if (!(wc2 >= 0xdc00 && wc2 < 0xe000)) - return RET_ILSEQ; - *pwc = 0x10000 + ((wc - 0xd800) << 10) + (wc2 - 0xdc00); - return 4; - } - } + { + if (n >= 4) + { + ucs4_t wc2 = s[2] + (s[3] << 8); + if (!(wc2 >= 0xdc00 && wc2 < 0xe000)) + return RET_ILSEQ; + *pwc = 0x10000 + ((wc - 0xd800) << 10) + (wc2 - 0xdc00); + return 4; + } + } else if (wc >= 0xdc00 && wc < 0xe000) - { - return RET_ILSEQ; - } + { + return RET_ILSEQ; + } else - { - *pwc = wc; - return 2; - } + { + *pwc = wc; + return 2; + } } return RET_TOOFEW; } @@ -159,31 +159,31 @@ utf16le_wctomb (unsigned char *r, ucs4_t wc, size_t n) if (!(wc >= 0xd800 && wc < 0xe000)) { if (wc < 0x10000) - { - if (n >= 2) - { - r[0] = (unsigned char) wc; - r[1] = (unsigned char) (wc >> 8); - return 2; - } - else - return RET_TOOSMALL; - } + { + if (n >= 2) + { + r[0] = (unsigned char) wc; + r[1] = (unsigned char) (wc >> 8); + return 2; + } + else + return RET_TOOSMALL; + } else if (wc < 0x110000) - { - if (n >= 4) - { - ucs4_t wc1 = 0xd800 + ((wc - 0x10000) >> 10); - ucs4_t wc2 = 0xdc00 + ((wc - 0x10000) & 0x3ff); - r[0] = (unsigned char) wc1; - r[1] = (unsigned char) (wc1 >> 8); - r[2] = (unsigned char) wc2; - r[3] = (unsigned char) (wc2 >> 8); - return 4; - } - else - return RET_TOOSMALL; - } + { + if (n >= 4) + { + ucs4_t wc1 = 0xd800 + ((wc - 0x10000) >> 10); + ucs4_t wc2 = 0xdc00 + ((wc - 0x10000) & 0x3ff); + r[0] = (unsigned char) wc1; + r[1] = (unsigned char) (wc1 >> 8); + r[2] = (unsigned char) wc2; + r[3] = (unsigned char) (wc2 >> 8); + return 4; + } + else + return RET_TOOSMALL; + } } return RET_ILUNI; } @@ -201,12 +201,12 @@ utf32be_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n) { ucs4_t wc = (s[0] << 24) + (s[1] << 16) + (s[2] << 8) + s[3]; if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000)) - { - *pwc = wc; - return 4; - } + { + *pwc = wc; + return 4; + } else - return RET_ILSEQ; + return RET_ILSEQ; } return RET_TOOFEW; } @@ -217,15 +217,15 @@ utf32be_wctomb (unsigned char *r, ucs4_t wc, size_t n) if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000)) { if (n >= 4) - { - r[0] = 0; - r[1] = (unsigned char) (wc >> 16); - r[2] = (unsigned char) (wc >> 8); - r[3] = (unsigned char) wc; - return 4; - } + { + r[0] = 0; + r[1] = (unsigned char) (wc >> 16); + r[2] = (unsigned char) (wc >> 8); + r[3] = (unsigned char) wc; + return 4; + } else - return RET_TOOSMALL; + return RET_TOOSMALL; } return RET_ILUNI; } @@ -243,12 +243,12 @@ utf32le_mbtowc (ucs4_t *pwc, const unsigned char *s, size_t n) { ucs4_t wc = s[0] + (s[1] << 8) + (s[2] << 16) + (s[3] << 24); if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000)) - { - *pwc = wc; - return 4; - } + { + *pwc = wc; + return 4; + } else - return RET_ILSEQ; + return RET_ILSEQ; } return RET_TOOFEW; } @@ -259,15 +259,15 @@ utf32le_wctomb (unsigned char *r, ucs4_t wc, size_t n) if (wc < 0x110000 && !(wc >= 0xd800 && wc < 0xe000)) { if (n >= 4) - { - r[0] = (unsigned char) wc; - r[1] = (unsigned char) (wc >> 8); - r[2] = (unsigned char) (wc >> 16); - r[3] = 0; - return 4; + { + r[0] = (unsigned char) wc; + r[1] = (unsigned char) (wc >> 8); + r[2] = (unsigned char) (wc >> 16); + r[3] = 0; + return 4; } else - return RET_TOOSMALL; + return RET_TOOSMALL; } return RET_ILUNI; } @@ -276,173 +276,173 @@ utf32le_wctomb (unsigned char *r, ucs4_t wc, size_t n) size_t rpl_iconv (iconv_t cd, - ICONV_CONST char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) + ICONV_CONST char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) #undef iconv { #if REPLACE_ICONV_UTF switch ((uintptr_t) cd) { { - int (*xxx_wctomb) (unsigned char *, ucs4_t, size_t); - - case (uintptr_t) _ICONV_UTF8_UTF16BE: - xxx_wctomb = utf16be_wctomb; - goto loop_from_utf8; - case (uintptr_t) _ICONV_UTF8_UTF16LE: - xxx_wctomb = utf16le_wctomb; - goto loop_from_utf8; - case (uintptr_t) _ICONV_UTF8_UTF32BE: - xxx_wctomb = utf32be_wctomb; - goto loop_from_utf8; - case (uintptr_t) _ICONV_UTF8_UTF32LE: - xxx_wctomb = utf32le_wctomb; - goto loop_from_utf8; + int (*xxx_wctomb) (unsigned char *, ucs4_t, size_t); + + case (uintptr_t) _ICONV_UTF8_UTF16BE: + xxx_wctomb = utf16be_wctomb; + goto loop_from_utf8; + case (uintptr_t) _ICONV_UTF8_UTF16LE: + xxx_wctomb = utf16le_wctomb; + goto loop_from_utf8; + case (uintptr_t) _ICONV_UTF8_UTF32BE: + xxx_wctomb = utf32be_wctomb; + goto loop_from_utf8; + case (uintptr_t) _ICONV_UTF8_UTF32LE: + xxx_wctomb = utf32le_wctomb; + goto loop_from_utf8; loop_from_utf8: - if (inbuf == NULL || *inbuf == NULL) - return 0; - { - ICONV_CONST char *inptr = *inbuf; - size_t inleft = *inbytesleft; - char *outptr = *outbuf; - size_t outleft = *outbytesleft; - size_t res = 0; - while (inleft > 0) - { - ucs4_t uc; - int m = u8_mbtoucr (&uc, (const uint8_t *) inptr, inleft); - if (m <= 0) - { - if (m == -1) - { - errno = EILSEQ; - res = (size_t)(-1); - break; - } - if (m == -2) - { - errno = EINVAL; - res = (size_t)(-1); - break; - } - abort (); - } - else - { - int n = xxx_wctomb ((uint8_t *) outptr, uc, outleft); - if (n < 0) - { - if (n == RET_ILUNI) - { - errno = EILSEQ; - res = (size_t)(-1); - break; - } - if (n == RET_TOOSMALL) - { - errno = E2BIG; - res = (size_t)(-1); - break; - } - abort (); - } - else - { - inptr += m; - inleft -= m; - outptr += n; - outleft -= n; - } - } - } - *inbuf = inptr; - *inbytesleft = inleft; - *outbuf = outptr; - *outbytesleft = outleft; - return res; - } + if (inbuf == NULL || *inbuf == NULL) + return 0; + { + ICONV_CONST char *inptr = *inbuf; + size_t inleft = *inbytesleft; + char *outptr = *outbuf; + size_t outleft = *outbytesleft; + size_t res = 0; + while (inleft > 0) + { + ucs4_t uc; + int m = u8_mbtoucr (&uc, (const uint8_t *) inptr, inleft); + if (m <= 0) + { + if (m == -1) + { + errno = EILSEQ; + res = (size_t)(-1); + break; + } + if (m == -2) + { + errno = EINVAL; + res = (size_t)(-1); + break; + } + abort (); + } + else + { + int n = xxx_wctomb ((uint8_t *) outptr, uc, outleft); + if (n < 0) + { + if (n == RET_ILUNI) + { + errno = EILSEQ; + res = (size_t)(-1); + break; + } + if (n == RET_TOOSMALL) + { + errno = E2BIG; + res = (size_t)(-1); + break; + } + abort (); + } + else + { + inptr += m; + inleft -= m; + outptr += n; + outleft -= n; + } + } + } + *inbuf = inptr; + *inbytesleft = inleft; + *outbuf = outptr; + *outbytesleft = outleft; + return res; + } } { - int (*xxx_mbtowc) (ucs4_t *, const unsigned char *, size_t); - - case (uintptr_t) _ICONV_UTF16BE_UTF8: - xxx_mbtowc = utf16be_mbtowc; - goto loop_to_utf8; - case (uintptr_t) _ICONV_UTF16LE_UTF8: - xxx_mbtowc = utf16le_mbtowc; - goto loop_to_utf8; - case (uintptr_t) _ICONV_UTF32BE_UTF8: - xxx_mbtowc = utf32be_mbtowc; - goto loop_to_utf8; - case (uintptr_t) _ICONV_UTF32LE_UTF8: - xxx_mbtowc = utf32le_mbtowc; - goto loop_to_utf8; + int (*xxx_mbtowc) (ucs4_t *, const unsigned char *, size_t); + + case (uintptr_t) _ICONV_UTF16BE_UTF8: + xxx_mbtowc = utf16be_mbtowc; + goto loop_to_utf8; + case (uintptr_t) _ICONV_UTF16LE_UTF8: + xxx_mbtowc = utf16le_mbtowc; + goto loop_to_utf8; + case (uintptr_t) _ICONV_UTF32BE_UTF8: + xxx_mbtowc = utf32be_mbtowc; + goto loop_to_utf8; + case (uintptr_t) _ICONV_UTF32LE_UTF8: + xxx_mbtowc = utf32le_mbtowc; + goto loop_to_utf8; loop_to_utf8: - if (inbuf == NULL || *inbuf == NULL) - return 0; - { - ICONV_CONST char *inptr = *inbuf; - size_t inleft = *inbytesleft; - char *outptr = *outbuf; - size_t outleft = *outbytesleft; - size_t res = 0; - while (inleft > 0) - { - ucs4_t uc; - int m = xxx_mbtowc (&uc, (const uint8_t *) inptr, inleft); - if (m <= 0) - { - if (m == RET_ILSEQ) - { - errno = EILSEQ; - res = (size_t)(-1); - break; - } - if (m == RET_TOOFEW) - { - errno = EINVAL; - res = (size_t)(-1); - break; - } - abort (); - } - else - { - int n = u8_uctomb ((uint8_t *) outptr, uc, outleft); - if (n < 0) - { - if (n == -1) - { - errno = EILSEQ; - res = (size_t)(-1); - break; - } - if (n == -2) - { - errno = E2BIG; - res = (size_t)(-1); - break; - } - abort (); - } - else - { - inptr += m; - inleft -= m; - outptr += n; - outleft -= n; - } - } - } - *inbuf = inptr; - *inbytesleft = inleft; - *outbuf = outptr; - *outbytesleft = outleft; - return res; - } + if (inbuf == NULL || *inbuf == NULL) + return 0; + { + ICONV_CONST char *inptr = *inbuf; + size_t inleft = *inbytesleft; + char *outptr = *outbuf; + size_t outleft = *outbytesleft; + size_t res = 0; + while (inleft > 0) + { + ucs4_t uc; + int m = xxx_mbtowc (&uc, (const uint8_t *) inptr, inleft); + if (m <= 0) + { + if (m == RET_ILSEQ) + { + errno = EILSEQ; + res = (size_t)(-1); + break; + } + if (m == RET_TOOFEW) + { + errno = EINVAL; + res = (size_t)(-1); + break; + } + abort (); + } + else + { + int n = u8_uctomb ((uint8_t *) outptr, uc, outleft); + if (n < 0) + { + if (n == -1) + { + errno = EILSEQ; + res = (size_t)(-1); + break; + } + if (n == -2) + { + errno = E2BIG; + res = (size_t)(-1); + break; + } + abort (); + } + else + { + inptr += m; + inleft -= m; + outptr += n; + outleft -= n; + } + } + } + *inbuf = inptr; + *inbytesleft = inleft; + *outbuf = outptr; + *outbytesleft = outleft; + return res; + } } } #endif diff --git a/lib/iconv.in.h b/lib/iconv.in.h index 096bf9c4c..b0ee68e59 100644 --- a/lib/iconv.in.h +++ b/lib/iconv.in.h @@ -56,8 +56,8 @@ extern iconv_t iconv_open (const char *tocode, const char *fromcode); #if @REPLACE_ICONV@ # define iconv rpl_iconv extern size_t iconv (iconv_t cd, - @ICONV_CONST@ char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft); + @ICONV_CONST@ char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); # define iconv_close rpl_iconv_close extern int iconv_close (iconv_t cd); #endif diff --git a/lib/iconv_open.c b/lib/iconv_open.c index 664b705ec..4e9d26f69 100644 --- a/lib/iconv_open.c +++ b/lib/iconv_open.c @@ -67,33 +67,33 @@ rpl_iconv_open (const char *tocode, const char *fromcode) && fromcode[3] == '-') { if (c_toupper (tocode[0]) == 'U' - && c_toupper (tocode[1]) == 'T' - && c_toupper (tocode[2]) == 'F' - && tocode[3] == '-') - { - if (strcmp (fromcode + 4, "8") == 0) - { - if (c_strcasecmp (tocode + 4, "16BE") == 0) - return _ICONV_UTF8_UTF16BE; - if (c_strcasecmp (tocode + 4, "16LE") == 0) - return _ICONV_UTF8_UTF16LE; - if (c_strcasecmp (tocode + 4, "32BE") == 0) - return _ICONV_UTF8_UTF32BE; - if (c_strcasecmp (tocode + 4, "32LE") == 0) - return _ICONV_UTF8_UTF32LE; - } - else if (strcmp (tocode + 4, "8") == 0) - { - if (c_strcasecmp (fromcode + 4, "16BE") == 0) - return _ICONV_UTF16BE_UTF8; - if (c_strcasecmp (fromcode + 4, "16LE") == 0) - return _ICONV_UTF16LE_UTF8; - if (c_strcasecmp (fromcode + 4, "32BE") == 0) - return _ICONV_UTF32BE_UTF8; - if (c_strcasecmp (fromcode + 4, "32LE") == 0) - return _ICONV_UTF32LE_UTF8; - } - } + && c_toupper (tocode[1]) == 'T' + && c_toupper (tocode[2]) == 'F' + && tocode[3] == '-') + { + if (strcmp (fromcode + 4, "8") == 0) + { + if (c_strcasecmp (tocode + 4, "16BE") == 0) + return _ICONV_UTF8_UTF16BE; + if (c_strcasecmp (tocode + 4, "16LE") == 0) + return _ICONV_UTF8_UTF16LE; + if (c_strcasecmp (tocode + 4, "32BE") == 0) + return _ICONV_UTF8_UTF32BE; + if (c_strcasecmp (tocode + 4, "32LE") == 0) + return _ICONV_UTF8_UTF32LE; + } + else if (strcmp (tocode + 4, "8") == 0) + { + if (c_strcasecmp (fromcode + 4, "16BE") == 0) + return _ICONV_UTF16BE_UTF8; + if (c_strcasecmp (fromcode + 4, "16LE") == 0) + return _ICONV_UTF16LE_UTF8; + if (c_strcasecmp (fromcode + 4, "32BE") == 0) + return _ICONV_UTF32BE_UTF8; + if (c_strcasecmp (fromcode + 4, "32LE") == 0) + return _ICONV_UTF32LE_UTF8; + } + } } #endif @@ -116,20 +116,20 @@ rpl_iconv_open (const char *tocode, const char *fromcode) /* Convert the encodings to upper case, because 1. in the arguments of iconv_open() on AIX, HP-UX, and OSF/1 the case - matters, + matters, 2. it makes searching in the table faster. */ { const char *p = fromcode; char *q = fromcode_upper; while ((*q = c_toupper (*p)) != '\0') { - p++; - q++; - if (q == &fromcode_upper[SIZEOF (fromcode_upper)]) - { - errno = EINVAL; - return (iconv_t)(-1); - } + p++; + q++; + if (q == &fromcode_upper[SIZEOF (fromcode_upper)]) + { + errno = EINVAL; + return (iconv_t)(-1); + } } fromcode_upper_end = q; } @@ -139,13 +139,13 @@ rpl_iconv_open (const char *tocode, const char *fromcode) char *q = tocode_upper; while ((*q = c_toupper (*p)) != '\0') { - p++; - q++; - if (q == &tocode_upper[SIZEOF (tocode_upper)]) - { - errno = EINVAL; - return (iconv_t)(-1); - } + p++; + q++; + if (q == &tocode_upper[SIZEOF (tocode_upper)]) + { + errno = EINVAL; + return (iconv_t)(-1); + } } tocode_upper_end = q; } diff --git a/lib/iconveh.h b/lib/iconveh.h index bc125b0c1..e4bfe1201 100644 --- a/lib/iconveh.h +++ b/lib/iconveh.h @@ -27,9 +27,9 @@ extern "C" { /* Handling of unconvertible characters. */ enum iconv_ilseq_handler { - iconveh_error, /* return and set errno = EILSEQ */ - iconveh_question_mark, /* use one '?' per unconvertible character */ - iconveh_escape_sequence /* use escape sequence \uxxxx or \Uxxxxxxxx */ + iconveh_error, /* return and set errno = EILSEQ */ + iconveh_question_mark, /* use one '?' per unconvertible character */ + iconveh_escape_sequence /* use escape sequence \uxxxx or \Uxxxxxxxx */ }; diff --git a/lib/idcache.c b/lib/idcache.c index 4951873d1..00b807850 100644 --- a/lib/idcache.c +++ b/lib/idcache.c @@ -73,10 +73,10 @@ getuser (uid_t uid) for (tail = user_alist; tail; tail = tail->next) { if (tail->id.u == uid) - { - match = tail; - break; - } + { + match = tail; + break; + } } if (match == NULL) @@ -123,7 +123,7 @@ getuidbyname (const char *user) if (!pwent && strspn (user, digits) < strlen (user)) { setenv ("USER", user, 1); - pwent = getpwnam (user); /* now it will succeed */ + pwent = getpwnam (user); /* now it will succeed */ } #endif @@ -155,10 +155,10 @@ getgroup (gid_t gid) for (tail = group_alist; tail; tail = tail->next) { if (tail->id.g == gid) - { - match = tail; - break; - } + { + match = tail; + break; + } } if (match == NULL) @@ -205,7 +205,7 @@ getgidbyname (const char *group) if (!grent && strspn (group, digits) < strlen (group)) { setenv ("GROUP", group, 1); - grent = getgrnam (group); /* now it will succeed */ + grent = getgrnam (group); /* now it will succeed */ } #endif diff --git a/lib/idpriv-drop.c b/lib/idpriv-drop.c index e1fa02f8b..9ebf123c6 100644 --- a/lib/idpriv-drop.c +++ b/lib/idpriv-drop.c @@ -88,9 +88,9 @@ idpriv_drop (void) uid_t effective; uid_t saved; if (getresuid (&real, &effective, &saved) < 0 - || real != uid - || effective != uid - || saved != uid) + || real != uid + || effective != uid + || saved != uid) abort (); } #else @@ -109,9 +109,9 @@ idpriv_drop (void) gid_t effective; gid_t saved; if (getresgid (&real, &effective, &saved) < 0 - || real != gid - || effective != gid - || saved != gid) + || real != gid + || effective != gid + || saved != gid) abort (); } #else diff --git a/lib/idpriv-droptemp.c b/lib/idpriv-droptemp.c index a7f26660a..5d778e323 100644 --- a/lib/idpriv-droptemp.c +++ b/lib/idpriv-droptemp.c @@ -78,9 +78,9 @@ idpriv_temp_drop (void) uid_t effective; uid_t saved; if (getresuid (&real, &effective, &saved) < 0 - || real != uid - || effective != uid - || saved != saved_uid) + || real != uid + || effective != uid + || saved != saved_uid) abort (); } # else @@ -97,9 +97,9 @@ idpriv_temp_drop (void) uid_t effective; uid_t saved; if (getresgid (&real, &effective, &saved) < 0 - || real != gid - || effective != gid - || saved != saved_gid) + || real != gid + || effective != gid + || saved != saved_gid) abort (); } # else @@ -163,9 +163,9 @@ idpriv_temp_restore (void) uid_t effective; uid_t saved; if (getresuid (&real, &effective, &saved) < 0 - || real != uid - || effective != saved_uid - || saved != saved_uid) + || real != uid + || effective != saved_uid + || saved != saved_uid) abort (); } # else @@ -182,9 +182,9 @@ idpriv_temp_restore (void) uid_t effective; uid_t saved; if (getresgid (&real, &effective, &saved) < 0 - || real != gid - || effective != saved_gid - || saved != saved_gid) + || real != gid + || effective != saved_gid + || saved != saved_gid) abort (); } # else diff --git a/lib/imaxdiv.c b/lib/imaxdiv.c index 81e7d8002..61cbf712e 100644 --- a/lib/imaxdiv.c +++ b/lib/imaxdiv.c @@ -35,28 +35,28 @@ imaxdiv (intmax_t numer, intmax_t denom) often called "truncation toward zero".) If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a." */ if (!(denom == 0 - || (INTMAX_MIN + INTMAX_MAX < 0 - && denom == -1 - && numer < - INTMAX_MAX))) + || (INTMAX_MIN + INTMAX_MAX < 0 + && denom == -1 + && numer < - INTMAX_MAX))) { if (!(result.quot * denom + result.rem == numer)) - /* The compiler's implementation of / and % is broken. */ - abort (); + /* The compiler's implementation of / and % is broken. */ + abort (); if (!(numer >= 0 - ? result.rem >= 0 - && (denom >= 0 - ? result.rem < denom - : /* Don't write result.rem < - denom, - as it gives integer overflow if denom == INTMAX_MIN. */ - - result.rem > denom) - : result.rem <= 0 - && (denom >= 0 - ? result.rem > - denom - : result.rem > denom))) - /* The compiler's implementation of / and % may be ok according to - C89, but not to C99. Please report this to . - This might be a big portability problem. */ - abort (); + ? result.rem >= 0 + && (denom >= 0 + ? result.rem < denom + : /* Don't write result.rem < - denom, + as it gives integer overflow if denom == INTMAX_MIN. */ + - result.rem > denom) + : result.rem <= 0 + && (denom >= 0 + ? result.rem > - denom + : result.rem > denom))) + /* The compiler's implementation of / and % may be ok according to + C89, but not to C99. Please report this to . + This might be a big portability problem. */ + abort (); } return result; diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c index 033847a94..4a6f3d208 100644 --- a/lib/inet_ntop.c +++ b/lib/inet_ntop.c @@ -59,15 +59,15 @@ static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t si /* char * * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. + * convert a network format address to presentation format. * return: - * pointer to presentation format address (`dst'), or NULL (see errno). + * pointer to presentation format address (`dst'), or NULL (see errno). * author: - * Paul Vixie, 1996. + * Paul Vixie, 1996. */ const char * inet_ntop (int af, const void *restrict src, - char *restrict dst, socklen_t cnt) + char *restrict dst, socklen_t cnt) { switch (af) { @@ -90,14 +90,14 @@ inet_ntop (int af, const void *restrict src, /* const char * * inet_ntop4(src, dst, size) - * format an IPv4 address + * format an IPv4 address * return: - * `dst' (as a const) + * `dst' (as a const) * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input + * (1) uses no statics + * (2) takes a u_char* not an in_addr as input * author: - * Paul Vixie, 1996. + * Paul Vixie, 1996. */ static const char * inet_ntop4 (const unsigned char *src, char *dst, socklen_t size) @@ -122,9 +122,9 @@ inet_ntop4 (const unsigned char *src, char *dst, socklen_t size) /* const char * * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format + * convert IPv6 binary address into presentation (printable) format * author: - * Paul Vixie, 1996. + * Paul Vixie, 1996. */ static const char * inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) @@ -157,26 +157,26 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { if (words[i] == 0) - { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } + { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else - { - if (cur.base != -1) - { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } + { + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } } if (cur.base != -1) { if (best.base == -1 || cur.len > best.len) - best = cur; + best = cur; } if (best.base != -1 && best.len < 2) best.base = -1; @@ -189,28 +189,28 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) { /* Are we inside the best run of 0x00's? */ if (best.base != -1 && i >= best.base && i < (best.base + best.len)) - { - if (i == best.base) - *tp++ = ':'; - continue; - } + { + if (i == best.base) + *tp++ = ':'; + continue; + } /* Are we following an initial run of 0x00s or any real hex? */ if (i != 0) - *tp++ = ':'; + *tp++ = ':'; /* Is this address an encapsulated IPv4? */ if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) - { - if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen (tp); - break; - } + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + { + if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) + return (NULL); + tp += strlen (tp); + break; + } { - int len = sprintf (tp, "%x", words[i]); - if (len < 0) - return NULL; - tp += len; + int len = sprintf (tp, "%x", words[i]); + if (len < 0) + return NULL; + tp += len; } } /* Was it a trailing run of 0x00's? */ diff --git a/lib/inet_pton.c b/lib/inet_pton.c index a9c9bafde..8907b3504 100644 --- a/lib/inet_pton.c +++ b/lib/inet_pton.c @@ -57,14 +57,14 @@ static int inet_pton6 (const char *src, unsigned char *dst); /* int * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). + * convert from presentation format (which usually means ASCII printable) + * to network format (which is usually some kind of binary format). * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) + * 1 if the address was valid for the specified address family + * 0 if the address wasn't valid (`dst' is untouched in this case) + * -1 if some other error occurred (`dst' is untouched in this case, too) * author: - * Paul Vixie, 1996. + * Paul Vixie, 1996. */ int inet_pton (int af, const char *restrict src, void *restrict dst) @@ -88,14 +88,14 @@ inet_pton (int af, const char *restrict src, void *restrict dst) /* int * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal, octal (with the - * exception of 0) and shorthand. + * like inet_aton() but without all the hexadecimal, octal (with the + * exception of 0) and shorthand. * return: - * 1 if `src' is a valid dotted quad, else 0. + * 1 if `src' is a valid dotted quad, else 0. * notice: - * does not touch `dst' unless it's returning 1. + * does not touch `dst' unless it's returning 1. * author: - * Paul Vixie, 1996. + * Paul Vixie, 1996. */ static int inet_pton4 (const char *restrict src, unsigned char *restrict dst) @@ -110,30 +110,30 @@ inet_pton4 (const char *restrict src, unsigned char *restrict dst) { if (ch >= '0' && ch <= '9') - { - unsigned new = *tp * 10 + (ch - '0'); - - if (saw_digit && *tp == 0) - return (0); - if (new > 255) - return (0); - *tp = new; - if (!saw_digit) - { - if (++octets > 4) - return (0); - saw_digit = 1; - } - } + { + unsigned new = *tp * 10 + (ch - '0'); + + if (saw_digit && *tp == 0) + return (0); + if (new > 255) + return (0); + *tp = new; + if (!saw_digit) + { + if (++octets > 4) + return (0); + saw_digit = 1; + } + } else if (ch == '.' && saw_digit) - { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } + { + if (octets == 4) + return (0); + *++tp = 0; + saw_digit = 0; + } else - return (0); + return (0); } if (octets < 4) return (0); @@ -145,16 +145,16 @@ inet_pton4 (const char *restrict src, unsigned char *restrict dst) /* int * inet_pton6(src, dst) - * convert presentation level address to network order binary form. + * convert presentation level address to network order binary form. * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. + * 1 if `src' is a valid [RFC1884 2.2] address, else 0. * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. + * (1) does not touch `dst' unless it's returning 1. + * (2) :: in a full address is silently ignored. * credit: - * inspired by Mark Andrews. + * inspired by Mark Andrews. * author: - * Paul Vixie, 1996. + * Paul Vixie, 1996. */ static int inet_pton6 (const char *restrict src, unsigned char *restrict dst) @@ -181,49 +181,49 @@ inet_pton6 (const char *restrict src, unsigned char *restrict dst) pch = strchr (xdigits, ch); if (pch != NULL) - { - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - continue; - } + { + val <<= 4; + val |= (pch - xdigits); + if (val > 0xffff) + return (0); + saw_xdigit = 1; + continue; + } if (ch == ':') - { - curtok = src; - if (!saw_xdigit) - { - if (colonp) - return (0); - colonp = tp; - continue; - } - else if (*src == '\0') - { - return (0); - } - if (tp + NS_INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; - val = 0; - continue; - } + { + curtok = src; + if (!saw_xdigit) + { + if (colonp) + return (0); + colonp = tp; + continue; + } + else if (*src == '\0') + { + return (0); + } + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + saw_xdigit = 0; + val = 0; + continue; + } if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && - inet_pton4 (curtok, tp) > 0) - { - tp += NS_INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } + inet_pton4 (curtok, tp) > 0) + { + tp += NS_INADDRSZ; + saw_xdigit = 0; + break; /* '\0' was seen by inet_pton4(). */ + } return (0); } if (saw_xdigit) { if (tp + NS_INT16SZ > endp) - return (0); + return (0); *tp++ = (u_char) (val >> 8) & 0xff; *tp++ = (u_char) val & 0xff; } @@ -237,12 +237,12 @@ inet_pton6 (const char *restrict src, unsigned char *restrict dst) int i; if (tp == endp) - return (0); + return (0); for (i = 1; i <= n; i++) - { - endp[-i] = colonp[n - i]; - colonp[n - i] = 0; - } + { + endp[-i] = colonp[n - i]; + colonp[n - i] = 0; + } tp = endp; } if (tp != endp) diff --git a/lib/intprops.h b/lib/intprops.h index 325c39799..a0f466943 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -47,14 +47,14 @@ your host. */ # define TYPE_MINIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ - ? (t) 0 \ - : TYPE_SIGNED_MAGNITUDE (t) \ - ? ~ (t) 0 \ - : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) + ? (t) 0 \ + : TYPE_SIGNED_MAGNITUDE (t) \ + ? ~ (t) 0 \ + : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) # define TYPE_MAXIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ - ? (t) -1 \ - : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) + ? (t) -1 \ + : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) /* Return zero if T can be determined to be an unsigned type. Otherwise, return 1. diff --git a/lib/inttostr.c b/lib/inttostr.c index c7c0d736a..0b60a4d04 100644 --- a/lib/inttostr.c +++ b/lib/inttostr.c @@ -37,7 +37,7 @@ inttostr (inttype i, char *buf) if (i < 0) { do - *--p = '0' - i % 10; + *--p = '0' - i % 10; while ((i /= 10) != 0); *--p = '-'; @@ -46,7 +46,7 @@ inttostr (inttype i, char *buf) #endif { do - *--p = '0' + i % 10; + *--p = '0' + i % 10; while ((i /= 10) != 0); } diff --git a/lib/isapipe.c b/lib/isapipe.c index 495cba6a6..933863e40 100644 --- a/lib/isapipe.c +++ b/lib/isapipe.c @@ -87,28 +87,28 @@ isapipe (int fd) On Darwin 7.7, pipes are sockets, so check for those instead. */ if (! ((HAVE_FIFO_PIPES == 0 || HAVE_FIFO_PIPES == 1) - && PIPE_LINK_COUNT_MAX != (nlink_t) -1) + && PIPE_LINK_COUNT_MAX != (nlink_t) -1) && (S_ISFIFO (st.st_mode) | S_ISSOCK (st.st_mode))) { int fd_pair[2]; int pipe_result = pipe (fd_pair); if (pipe_result != 0) - return pipe_result; + return pipe_result; else - { - struct stat pipe_st; - int fstat_pipe_result = fstat (fd_pair[0], &pipe_st); - int fstat_pipe_errno = errno; - close (fd_pair[0]); - close (fd_pair[1]); - if (fstat_pipe_result != 0) - { - errno = fstat_pipe_errno; - return fstat_pipe_result; - } - check_for_fifo = (S_ISFIFO (pipe_st.st_mode) != 0); - pipe_link_count_max = pipe_st.st_nlink; - } + { + struct stat pipe_st; + int fstat_pipe_result = fstat (fd_pair[0], &pipe_st); + int fstat_pipe_errno = errno; + close (fd_pair[0]); + close (fd_pair[1]); + if (fstat_pipe_result != 0) + { + errno = fstat_pipe_errno; + return fstat_pipe_result; + } + check_for_fifo = (S_ISFIFO (pipe_st.st_mode) != 0); + pipe_link_count_max = pipe_st.st_nlink; + } } return diff --git a/lib/isnan.c b/lib/isnan.c index e748c1c90..cae819c51 100644 --- a/lib/isnan.c +++ b/lib/isnan.c @@ -140,10 +140,10 @@ FUNC (DOUBLE x) -Infinity, which have the same exponent. */ m.value = x; if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD]) - & (EXP_MASK << EXPBIT0_BIT)) - == 0) + & (EXP_MASK << EXPBIT0_BIT)) + == 0) return (memcmp (&m.value, &plus_inf, SIZE) != 0 - && memcmp (&m.value, &minus_inf, SIZE) != 0); + && memcmp (&m.value, &minus_inf, SIZE) != 0); else return 0; } diff --git a/lib/javacomp.c b/lib/javacomp.c index 7d0a94273..0b532e66e 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -81,12 +81,12 @@ We try the Java compilers in the following order: 1. getenv ("JAVAC"), because the user must be able to override our - preferences, + preferences, 2. "gcj -C", because it is a completely free compiler, 3. "javac", because it is a standard compiler, 4. "jikes", comes last because it has some deviating interpretation - of the Java Language Specification and because it requires a - CLASSPATH environment variable. + of the Java Language Specification and because it requires a + CLASSPATH environment variable. We unset the JAVA_HOME environment variable, because a wrong setting of this variable can confuse the JDK's javac. @@ -104,10 +104,10 @@ default_target_version (void) /* Determine the version from the found JVM. */ java_version_cache = javaexec_version (); if (java_version_cache == NULL - || !(java_version_cache[0] == '1' && java_version_cache[1] == '.' - && (java_version_cache[2] >= '1' && java_version_cache[2] <= '6') - && java_version_cache[3] == '\0')) - java_version_cache = "1.1"; + || !(java_version_cache[0] == '1' && java_version_cache[1] == '.' + && (java_version_cache[2] >= '1' && java_version_cache[2] <= '6') + && java_version_cache[3] == '\0')) + java_version_cache = "1.1"; } return java_version_cache; } @@ -199,11 +199,11 @@ corresponding_classfile_version (const char *target_version) Return a failure indicator (true upon error). */ static bool compile_using_envjavac (const char *javac, - const char * const *java_sources, - unsigned int java_sources_count, - const char *directory, - bool optimize, bool debug, - bool verbose, bool null_stderr) + const char * const *java_sources, + unsigned int java_sources_count, + const char *directory, + bool optimize, bool debug, + bool verbose, bool null_stderr) { /* Because $JAVAC may consist of a command and options, we use the shell. Because $JAVAC has been set by the user, we leave all @@ -268,7 +268,7 @@ compile_using_envjavac (const char *javac, argv[2] = command; argv[3] = NULL; exitstatus = execute (javac, "/bin/sh", argv, false, false, false, - null_stderr, true, true, NULL); + null_stderr, true, true, NULL); err = (exitstatus != 0); freea (command); @@ -280,13 +280,13 @@ compile_using_envjavac (const char *javac, Return a failure indicator (true upon error). */ static bool compile_using_gcj (const char * const *java_sources, - unsigned int java_sources_count, - bool no_assert_option, - bool fsource_option, const char *source_version, - bool ftarget_option, const char *target_version, - const char *directory, - bool optimize, bool debug, - bool verbose, bool null_stderr) + unsigned int java_sources_count, + bool no_assert_option, + bool fsource_option, const char *source_version, + bool ftarget_option, const char *target_version, + const char *directory, + bool optimize, bool debug, + bool verbose, bool null_stderr) { bool err; unsigned int argc; @@ -350,7 +350,7 @@ compile_using_gcj (const char * const *java_sources, } exitstatus = execute ("gcj", "gcj", argv, false, false, false, null_stderr, - true, true, NULL); + true, true, NULL); err = (exitstatus != 0); if (ftarget_arg != NULL) @@ -366,12 +366,12 @@ compile_using_gcj (const char * const *java_sources, Return a failure indicator (true upon error). */ static bool compile_using_javac (const char * const *java_sources, - unsigned int java_sources_count, - bool source_option, const char *source_version, - bool target_option, const char *target_version, - const char *directory, - bool optimize, bool debug, - bool verbose, bool null_stderr) + unsigned int java_sources_count, + bool source_option, const char *source_version, + bool target_option, const char *target_version, + const char *directory, + bool optimize, bool debug, + bool verbose, bool null_stderr) { bool err; unsigned int argc; @@ -421,7 +421,7 @@ compile_using_javac (const char * const *java_sources, } exitstatus = execute ("javac", "javac", argv, false, false, false, - null_stderr, true, true, NULL); + null_stderr, true, true, NULL); err = (exitstatus != 0); freea (argv); @@ -433,10 +433,10 @@ compile_using_javac (const char * const *java_sources, Return a failure indicator (true upon error). */ static bool compile_using_jikes (const char * const *java_sources, - unsigned int java_sources_count, - const char *directory, - bool optimize, bool debug, - bool verbose, bool null_stderr) + unsigned int java_sources_count, + const char *directory, + bool optimize, bool debug, + bool verbose, bool null_stderr) { bool err; unsigned int argc; @@ -476,7 +476,7 @@ compile_using_jikes (const char * const *java_sources, } exitstatus = execute ("jikes", "jikes", argv, false, false, false, - null_stderr, true, true, NULL); + null_stderr, true, true, NULL); err = (exitstatus != 0); freea (argv); @@ -492,7 +492,7 @@ compile_using_jikes (const char * const *java_sources, Return a failure indicator (true upon error). */ static bool write_temp_file (struct temp_dir *tmpdir, const char *file_name, - const char *contents) + const char *contents) { FILE *fp; @@ -526,12 +526,12 @@ get_classfile_version (const char *compiled_file_name) { /* Read its first 8 bytes. */ if (safe_read (fd, header, 8) == 8) - { - /* Verify the class file signature. */ - if (header[0] == 0xCA && header[1] == 0xFE - && header[2] == 0xBA && header[3] == 0xBE) - return header[7]; - } + { + /* Verify the class file signature. */ + if (header[0] == 0xCA && header[1] == 0xFE + && header[2] == 0xBA && header[3] == 0xBE) + return header[7]; + } close (fd); } @@ -549,7 +549,7 @@ is_envjavac_gcj (const char *javac) if (!envjavac_tested) { /* Test whether $JAVAC is gcj: - "$JAVAC --version 2>/dev/null | sed -e 1q | grep gcj > /dev/null" */ + "$JAVAC --version 2>/dev/null | sed -e 1q | grep gcj > /dev/null" */ unsigned int command_length; char *command; char *argv[4]; @@ -567,14 +567,14 @@ is_envjavac_gcj (const char *javac) command = (char *) xmalloca (command_length); p = command; /* Don't shell_quote $JAVAC, because it may consist of a command - and options. */ + and options. */ memcpy (p, javac, strlen (javac)); p += strlen (javac); memcpy (p, " --version", 1 + 9 + 1); p += 1 + 9 + 1; /* Ensure command_length was correctly calculated. */ if (p - command > command_length) - abort (); + abort (); /* Call $JAVAC --version 2>/dev/null. */ argv[0] = "/bin/sh"; @@ -582,33 +582,33 @@ is_envjavac_gcj (const char *javac) argv[2] = command; argv[3] = NULL; child = create_pipe_in (javac, "/bin/sh", argv, DEV_NULL, true, true, - false, fd); + false, fd); if (child == -1) - goto failed; + goto failed; /* Retrieve its result. */ fp = fdopen (fd[0], "r"); if (fp == NULL) - goto failed; + goto failed; line = NULL; linesize = 0; linelen = getline (&line, &linesize, fp); if (linelen == (size_t)(-1)) - { - fclose (fp); - goto failed; - } + { + fclose (fp); + goto failed; + } /* It is safe to call c_strstr() instead of strstr() here; see the - comments in c-strstr.h. */ + comments in c-strstr.h. */ envjavac_gcj = (c_strstr (line, "gcj") != NULL); fclose (fp); /* Remove zombie process from process list, and retrieve exit status. */ exitstatus = - wait_subprocess (child, javac, true, true, true, false, NULL); + wait_subprocess (child, javac, true, true, true, false, NULL); if (exitstatus != 0) - envjavac_gcj = false; + envjavac_gcj = false; failed: freea (command); @@ -630,8 +630,8 @@ is_envjavac_gcj43 (const char *javac) if (!envjavac_tested) { /* Test whether $JAVAC is gcj: - "$JAVAC --version 2>/dev/null | sed -e 's,^[^0-9]*,,' -e 1q \ - | sed -e '/^4\.[012]/d' | grep '^[4-9]' >/dev/null" */ + "$JAVAC --version 2>/dev/null | sed -e 's,^[^0-9]*,,' -e 1q \ + | sed -e '/^4\.[012]/d' | grep '^[4-9]' >/dev/null" */ unsigned int command_length; char *command; char *argv[4]; @@ -649,14 +649,14 @@ is_envjavac_gcj43 (const char *javac) command = (char *) xmalloca (command_length); p = command; /* Don't shell_quote $JAVAC, because it may consist of a command - and options. */ + and options. */ memcpy (p, javac, strlen (javac)); p += strlen (javac); memcpy (p, " --version", 1 + 9 + 1); p += 1 + 9 + 1; /* Ensure command_length was correctly calculated. */ if (p - command > command_length) - abort (); + abort (); /* Call $JAVAC --version 2>/dev/null. */ argv[0] = "/bin/sh"; @@ -664,36 +664,36 @@ is_envjavac_gcj43 (const char *javac) argv[2] = command; argv[3] = NULL; child = create_pipe_in (javac, "/bin/sh", argv, DEV_NULL, true, true, - false, fd); + false, fd); if (child == -1) - goto failed; + goto failed; /* Retrieve its result. */ fp = fdopen (fd[0], "r"); if (fp == NULL) - goto failed; + goto failed; line = NULL; linesize = 0; linelen = getline (&line, &linesize, fp); if (linelen == (size_t)(-1)) - { - fclose (fp); - goto failed; - } + { + fclose (fp); + goto failed; + } p = line; while (*p != '\0' && !(*p >= '0' && *p <= '9')) - p++; + p++; envjavac_gcj43 = !(*p == '4' && p[1] == '.' && p[2] >= '0' && p[2] <= '2') - && (*p >= '4' && *p <= '9'); + && (*p >= '4' && *p <= '9'); fclose (fp); /* Remove zombie process from process list, and retrieve exit status. */ exitstatus = - wait_subprocess (child, javac, true, true, true, false, NULL); + wait_subprocess (child, javac, true, true, true, false, NULL); if (exitstatus != 0) - envjavac_gcj43 = false; + envjavac_gcj43 = false; failed: freea (command); @@ -709,10 +709,10 @@ is_envjavac_gcj43 (const char *javac) Return a failure indicator (true upon error). */ static bool is_envjavac_gcj43_usable (const char *javac, - const char *source_version, - const char *target_version, - bool *usablep, - bool *fsource_option_p, bool *ftarget_option_p) + const char *source_version, + const char *target_version, + bool *usablep, + bool *fsource_option_p, bool *ftarget_option_p) { /* The cache depends on the source_version and target_version. */ struct result_t @@ -726,7 +726,7 @@ is_envjavac_gcj43_usable (const char *javac, struct result_t *resultp; resultp = &result_cache[source_version_index (source_version)] - [target_version_index (target_version)]; + [target_version_index (target_version)]; if (!resultp->tested) { /* Try $JAVAC. */ @@ -738,122 +738,122 @@ is_envjavac_gcj43_usable (const char *javac, tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet (source_version))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet (source_version))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_envjavac (javac, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* $JAVAC compiled conftest.java successfully. */ - /* Try adding -fsource option if it is useful. */ - char *javac_source = - xasprintf ("%s -fsource=%s", javac, source_version); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_source, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, failcode)) - { - free (conftest_file_name); - free (javac_source); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac, - java_sources, 1, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_envjavac (javac_source, - java_sources, 1, - tmpdir->dir_name, - false, false, false, true)) - /* $JAVAC compiled conftestfail.java successfully, and - "$JAVAC -fsource=$source_version" rejects it. So - the -fsource option is useful. */ - resultp->fsource_option = true; - } - } - } - - free (javac_source); - - resultp->usable = true; - } + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* $JAVAC compiled conftest.java successfully. */ + /* Try adding -fsource option if it is useful. */ + char *javac_source = + xasprintf ("%s -fsource=%s", javac, source_version); + + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac_source, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + const char *failcode = get_failcode_snippet (source_version); + + if (failcode != NULL) + { + free (compiled_file_name); + free (conftest_file_name); + + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, failcode)) + { + free (conftest_file_name); + free (javac_source); + cleanup_temp_dir (tmpdir); + return true; + } + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac, + java_sources, 1, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + { + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (compile_using_envjavac (javac_source, + java_sources, 1, + tmpdir->dir_name, + false, false, false, true)) + /* $JAVAC compiled conftestfail.java successfully, and + "$JAVAC -fsource=$source_version" rejects it. So + the -fsource option is useful. */ + resultp->fsource_option = true; + } + } + } + + free (javac_source); + + resultp->usable = true; + } else - { - /* Try with -fsource and -ftarget options. */ - char *javac_target = - xasprintf ("%s -fsource=%s -ftarget=%s", - javac, source_version, target_version); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "$JAVAC -fsource $source_version -ftarget $target_version" - compiled conftest.java successfully. */ - resultp->fsource_option = true; - resultp->ftarget_option = true; - resultp->usable = true; - } - - free (javac_target); - } + { + /* Try with -fsource and -ftarget options. */ + char *javac_target = + xasprintf ("%s -fsource=%s -ftarget=%s", + javac, source_version, target_version); + + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac_target, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* "$JAVAC -fsource $source_version -ftarget $target_version" + compiled conftest.java successfully. */ + resultp->fsource_option = true; + resultp->ftarget_option = true; + resultp->usable = true; + } + + free (javac_target); + } free (compiled_file_name); free (conftest_file_name); @@ -887,28 +887,28 @@ is_envjavac_oldgcj_14_14_usable (const char *javac, bool *usablep) tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet ("1.4"))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet ("1.4"))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_envjavac (javac, java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - /* Compilation succeeded. */ - envjavac_usable = true; + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + /* Compilation succeeded. */ + envjavac_usable = true; free (compiled_file_name); free (conftest_file_name); @@ -927,7 +927,7 @@ is_envjavac_oldgcj_14_14_usable (const char *javac, bool *usablep) Return a failure indicator (true upon error). */ static bool is_envjavac_oldgcj_14_13_usable (const char *javac, - bool *usablep, bool *need_no_assert_option_p) + bool *usablep, bool *need_no_assert_option_p) { static bool envjavac_tested; static bool envjavac_usable; @@ -936,7 +936,7 @@ is_envjavac_oldgcj_14_13_usable (const char *javac, if (!envjavac_tested) { /* Try $JAVAC and "$JAVAC -fno-assert". But add -fno-assert only if - it makes a difference. (It could already be part of $JAVAC.) */ + it makes a difference. (It could already be part of $JAVAC.) */ struct temp_dir *tmpdir; char *conftest_file_name; char *compiled_file_name; @@ -948,31 +948,31 @@ is_envjavac_oldgcj_14_13_usable (const char *javac, tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet ("1.3"))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet ("1.3"))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_envjavac (javac, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - /* Compilation succeeded. */ - javac_works = true; + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + /* Compilation succeeded. */ + javac_works = true; else - javac_works = false; + javac_works = false; unlink (compiled_file_name); @@ -980,71 +980,71 @@ is_envjavac_oldgcj_14_13_usable (const char *javac, java_sources[0] = conftest_file_name; if (!compile_using_envjavac (javac_noassert, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - /* Compilation succeeded. */ - javac_noassert_works = true; + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + /* Compilation succeeded. */ + javac_noassert_works = true; else - javac_noassert_works = false; + javac_noassert_works = false; free (compiled_file_name); free (conftest_file_name); if (javac_works && javac_noassert_works) - { - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, - get_failcode_snippet ("1.3"))) - { - free (conftest_file_name); - free (javac_noassert); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - /* Compilation succeeded. */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!(!compile_using_envjavac (javac_noassert, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0)) - /* Compilation failed. */ - /* "$JAVAC -fno-assert" works better than $JAVAC. */ - javac_works = true; - } - - free (compiled_file_name); - free (conftest_file_name); - } + { + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, "conftestfail.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, + get_failcode_snippet ("1.3"))) + { + free (conftest_file_name); + free (javac_noassert); + cleanup_temp_dir (tmpdir); + return true; + } + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, "conftestfail.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + { + /* Compilation succeeded. */ + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!(!compile_using_envjavac (javac_noassert, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0)) + /* Compilation failed. */ + /* "$JAVAC -fno-assert" works better than $JAVAC. */ + javac_works = true; + } + + free (compiled_file_name); + free (conftest_file_name); + } cleanup_temp_dir (tmpdir); if (javac_works) - { - envjavac_usable = true; - envjavac_need_no_assert_option = false; - } + { + envjavac_usable = true; + envjavac_need_no_assert_option = false; + } else if (javac_noassert_works) - { - envjavac_usable = true; - envjavac_need_no_assert_option = true; - } + { + envjavac_usable = true; + envjavac_need_no_assert_option = true; + } envjavac_tested = true; } @@ -1059,10 +1059,10 @@ is_envjavac_oldgcj_14_13_usable (const char *javac, Return a failure indicator (true upon error). */ static bool is_envjavac_nongcj_usable (const char *javac, - const char *source_version, - const char *target_version, - bool *usablep, - bool *source_option_p, bool *target_option_p) + const char *source_version, + const char *target_version, + bool *usablep, + bool *source_option_p, bool *target_option_p) { /* The cache depends on the source_version and target_version. */ struct result_t @@ -1076,7 +1076,7 @@ is_envjavac_nongcj_usable (const char *javac, struct result_t *resultp; resultp = &result_cache[source_version_index (source_version)] - [target_version_index (target_version)]; + [target_version_index (target_version)]; if (!resultp->tested) { /* Try $JAVAC. */ @@ -1088,215 +1088,215 @@ is_envjavac_nongcj_usable (const char *javac, tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet (source_version))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet (source_version))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_envjavac (javac, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* $JAVAC compiled conftest.java successfully. */ - /* Try adding -source option if it is useful. */ - char *javac_source = - xasprintf ("%s -source %s", javac, source_version); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_source, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, failcode)) - { - free (conftest_file_name); - free (javac_source); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac, - java_sources, 1, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_envjavac (javac_source, - java_sources, 1, - tmpdir->dir_name, - false, false, false, true)) - /* $JAVAC compiled conftestfail.java successfully, and - "$JAVAC -source $source_version" rejects it. So the - -source option is useful. */ - resultp->source_option = true; - } - } - } - - free (javac_source); - - resultp->usable = true; - } + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* $JAVAC compiled conftest.java successfully. */ + /* Try adding -source option if it is useful. */ + char *javac_source = + xasprintf ("%s -source %s", javac, source_version); + + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac_source, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + const char *failcode = get_failcode_snippet (source_version); + + if (failcode != NULL) + { + free (compiled_file_name); + free (conftest_file_name); + + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, failcode)) + { + free (conftest_file_name); + free (javac_source); + cleanup_temp_dir (tmpdir); + return true; + } + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac, + java_sources, 1, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + { + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (compile_using_envjavac (javac_source, + java_sources, 1, + tmpdir->dir_name, + false, false, false, true)) + /* $JAVAC compiled conftestfail.java successfully, and + "$JAVAC -source $source_version" rejects it. So the + -source option is useful. */ + resultp->source_option = true; + } + } + } + + free (javac_source); + + resultp->usable = true; + } else - { - /* Try with -target option alone. (Sun javac 1.3.1 has the -target - option but no -source option.) */ - char *javac_target = - xasprintf ("%s -target %s", javac, target_version); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "$JAVAC -target $target_version" compiled conftest.java - successfully. */ - /* Try adding -source option if it is useful. */ - char *javac_target_source = - xasprintf ("%s -source %s", javac_target, source_version); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target_source, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, - failcode)) - { - free (conftest_file_name); - free (javac_target_source); - free (javac_target); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target, - java_sources, 1, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_envjavac (javac_target_source, - java_sources, 1, - tmpdir->dir_name, - false, false, false, - true)) - /* "$JAVAC -target $target_version" compiled - conftestfail.java successfully, and - "$JAVAC -target $target_version -source $source_version" - rejects it. So the -source option is useful. */ - resultp->source_option = true; - } - } - } - - free (javac_target_source); - - resultp->target_option = true; - resultp->usable = true; - } - else - { - /* Maybe this -target option requires a -source option? Try with - -target and -source options. (Supported by Sun javac 1.4 and - higher.) */ - char *javac_target_source = - xasprintf ("%s -source %s", javac_target, source_version); - - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_envjavac (javac_target_source, - java_sources, 1, tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "$JAVAC -target $target_version -source $source_version" - compiled conftest.java successfully. */ - resultp->source_option = true; - resultp->target_option = true; - resultp->usable = true; - } - - free (javac_target_source); - } - - free (javac_target); - } + { + /* Try with -target option alone. (Sun javac 1.3.1 has the -target + option but no -source option.) */ + char *javac_target = + xasprintf ("%s -target %s", javac, target_version); + + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac_target, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* "$JAVAC -target $target_version" compiled conftest.java + successfully. */ + /* Try adding -source option if it is useful. */ + char *javac_target_source = + xasprintf ("%s -source %s", javac_target, source_version); + + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac_target_source, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + const char *failcode = get_failcode_snippet (source_version); + + if (failcode != NULL) + { + free (compiled_file_name); + free (conftest_file_name); + + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, + failcode)) + { + free (conftest_file_name); + free (javac_target_source); + free (javac_target); + cleanup_temp_dir (tmpdir); + return true; + } + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac_target, + java_sources, 1, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + { + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (compile_using_envjavac (javac_target_source, + java_sources, 1, + tmpdir->dir_name, + false, false, false, + true)) + /* "$JAVAC -target $target_version" compiled + conftestfail.java successfully, and + "$JAVAC -target $target_version -source $source_version" + rejects it. So the -source option is useful. */ + resultp->source_option = true; + } + } + } + + free (javac_target_source); + + resultp->target_option = true; + resultp->usable = true; + } + else + { + /* Maybe this -target option requires a -source option? Try with + -target and -source options. (Supported by Sun javac 1.4 and + higher.) */ + char *javac_target_source = + xasprintf ("%s -source %s", javac_target, source_version); + + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_envjavac (javac_target_source, + java_sources, 1, tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* "$JAVAC -target $target_version -source $source_version" + compiled conftest.java successfully. */ + resultp->source_option = true; + resultp->target_option = true; + resultp->usable = true; + } + + free (javac_target_source); + } + + free (javac_target); + } free (compiled_file_name); free (conftest_file_name); @@ -1319,9 +1319,9 @@ is_gcj_present (void) if (!gcj_tested) { /* Test for presence of gcj: - "gcj --version 2> /dev/null | \ - sed -e 's,^[^0-9]*,,' -e 1q | \ - sed -e '/^3\.[01]/d' | grep '^[3-9]' > /dev/null" */ + "gcj --version 2> /dev/null | \ + sed -e 's,^[^0-9]*,,' -e 1q | \ + sed -e '/^3\.[01]/d' | grep '^[3-9]' > /dev/null" */ char *argv[3]; pid_t child; int fd[1]; @@ -1331,94 +1331,94 @@ is_gcj_present (void) argv[1] = "--version"; argv[2] = NULL; child = create_pipe_in ("gcj", "gcj", argv, DEV_NULL, true, true, - false, fd); + false, fd); gcj_present = false; if (child != -1) - { - /* Read the subprocess output, drop all lines except the first, - drop all characters before the first digit, and test whether - the remaining string starts with a digit >= 3, but not with - "3.0" or "3.1". */ - char c[3]; - size_t count = 0; - - while (safe_read (fd[0], &c[count], 1) > 0) - { - if (c[count] == '\n') - break; - if (count == 0) - { - if (!(c[0] >= '0' && c[0] <= '9')) - continue; - gcj_present = (c[0] >= '3'); - } - count++; - if (count == 3) - { - if (c[0] == '3' && c[1] == '.' - && (c[2] == '0' || c[2] == '1')) - gcj_present = false; - break; - } - } - while (safe_read (fd[0], &c[0], 1) > 0) - ; - - close (fd[0]); - - /* Remove zombie process from process list, and retrieve exit - status. */ - exitstatus = - wait_subprocess (child, "gcj", false, true, true, false, NULL); - if (exitstatus != 0) - gcj_present = false; - } + { + /* Read the subprocess output, drop all lines except the first, + drop all characters before the first digit, and test whether + the remaining string starts with a digit >= 3, but not with + "3.0" or "3.1". */ + char c[3]; + size_t count = 0; + + while (safe_read (fd[0], &c[count], 1) > 0) + { + if (c[count] == '\n') + break; + if (count == 0) + { + if (!(c[0] >= '0' && c[0] <= '9')) + continue; + gcj_present = (c[0] >= '3'); + } + count++; + if (count == 3) + { + if (c[0] == '3' && c[1] == '.' + && (c[2] == '0' || c[2] == '1')) + gcj_present = false; + break; + } + } + while (safe_read (fd[0], &c[0], 1) > 0) + ; + + close (fd[0]); + + /* Remove zombie process from process list, and retrieve exit + status. */ + exitstatus = + wait_subprocess (child, "gcj", false, true, true, false, NULL); + if (exitstatus != 0) + gcj_present = false; + } if (gcj_present) - { - /* See if libgcj.jar is well installed. */ - struct temp_dir *tmpdir; - - tmpdir = create_temp_dir ("java", NULL, false); - if (tmpdir == NULL) - gcj_present = false; - else - { - char *conftest_file_name; - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftestlib.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, + { + /* See if libgcj.jar is well installed. */ + struct temp_dir *tmpdir; + + tmpdir = create_temp_dir ("java", NULL, false); + if (tmpdir == NULL) + gcj_present = false; + else + { + char *conftest_file_name; + + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, "conftestlib.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, "public class conftestlib {\n" " public static void main (String[] args) {\n" " }\n" "}\n")) - gcj_present = false; - else - { - char *compiled_file_name; - const char *java_sources[1]; - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestlib.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_gcj (java_sources, 1, false, - false, NULL, false, NULL, - tmpdir->dir_name, - false, false, false, true)) - gcj_present = false; - - free (compiled_file_name); - } - free (conftest_file_name); - } - cleanup_temp_dir (tmpdir); - } + gcj_present = false; + else + { + char *compiled_file_name; + const char *java_sources[1]; + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestlib.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (compile_using_gcj (java_sources, 1, false, + false, NULL, false, NULL, + tmpdir->dir_name, + false, false, false, true)) + gcj_present = false; + + free (compiled_file_name); + } + free (conftest_file_name); + } + cleanup_temp_dir (tmpdir); + } gcj_tested = true; } @@ -1435,9 +1435,9 @@ is_gcj_43 (void) if (!gcj_tested) { /* Test for presence of gcj: - "gcj --version 2> /dev/null | \ - sed -e 's,^[^0-9]*,,' -e 1q | \ - sed -e '/^4\.[012]/d' | grep '^[4-9]'" */ + "gcj --version 2> /dev/null | \ + sed -e 's,^[^0-9]*,,' -e 1q | \ + sed -e '/^4\.[012]/d' | grep '^[4-9]'" */ char *argv[3]; pid_t child; int fd[1]; @@ -1447,47 +1447,47 @@ is_gcj_43 (void) argv[1] = "--version"; argv[2] = NULL; child = create_pipe_in ("gcj", "gcj", argv, DEV_NULL, true, true, - false, fd); + false, fd); gcj_43 = false; if (child != -1) - { - /* Read the subprocess output, drop all lines except the first, - drop all characters before the first digit, and test whether - the remaining string starts with a digit >= 4, but not with - "4.0" or "4.1" or "4.2". */ - char c[3]; - size_t count = 0; - - while (safe_read (fd[0], &c[count], 1) > 0) - { - if (c[count] == '\n') - break; - if (count == 0) - { - if (!(c[0] >= '0' && c[0] <= '9')) - continue; - gcj_43 = (c[0] >= '4'); - } - count++; - if (count == 3) - { - if (c[0] == '4' && c[1] == '.' && c[2] >= '0' && c[2] <= '2') - gcj_43 = false; - break; - } - } - while (safe_read (fd[0], &c[0], 1) > 0) - ; - - close (fd[0]); - - /* Remove zombie process from process list, and retrieve exit - status. */ - exitstatus = - wait_subprocess (child, "gcj", false, true, true, false, NULL); - if (exitstatus != 0) - gcj_43 = false; - } + { + /* Read the subprocess output, drop all lines except the first, + drop all characters before the first digit, and test whether + the remaining string starts with a digit >= 4, but not with + "4.0" or "4.1" or "4.2". */ + char c[3]; + size_t count = 0; + + while (safe_read (fd[0], &c[count], 1) > 0) + { + if (c[count] == '\n') + break; + if (count == 0) + { + if (!(c[0] >= '0' && c[0] <= '9')) + continue; + gcj_43 = (c[0] >= '4'); + } + count++; + if (count == 3) + { + if (c[0] == '4' && c[1] == '.' && c[2] >= '0' && c[2] <= '2') + gcj_43 = false; + break; + } + } + while (safe_read (fd[0], &c[0], 1) > 0) + ; + + close (fd[0]); + + /* Remove zombie process from process list, and retrieve exit + status. */ + exitstatus = + wait_subprocess (child, "gcj", false, true, true, false, NULL); + if (exitstatus != 0) + gcj_43 = false; + } gcj_tested = true; } @@ -1500,9 +1500,9 @@ is_gcj_43 (void) Return a failure indicator (true upon error). */ static bool is_gcj43_usable (const char *source_version, - const char *target_version, - bool *usablep, - bool *fsource_option_p, bool *ftarget_option_p) + const char *target_version, + bool *usablep, + bool *fsource_option_p, bool *ftarget_option_p) { /* The cache depends on the source_version and target_version. */ struct result_t @@ -1516,7 +1516,7 @@ is_gcj43_usable (const char *source_version, struct result_t *resultp; resultp = &result_cache[source_version_index (source_version)] - [target_version_index (target_version)]; + [target_version_index (target_version)]; if (!resultp->tested) { /* Try gcj. */ @@ -1528,112 +1528,112 @@ is_gcj43_usable (const char *source_version, tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet (source_version))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet (source_version))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_gcj (java_sources, 1, false, false, NULL, false, NULL, - tmpdir->dir_name, false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* gcj compiled conftest.java successfully. */ - /* Try adding -fsource option if it is useful. */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_gcj (java_sources, 1, - false, true, source_version, false, NULL, - tmpdir->dir_name, false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, failcode)) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_gcj (java_sources, 1, - false, false, NULL, false, NULL, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_gcj (java_sources, 1, - false, true, source_version, - false, NULL, - tmpdir->dir_name, - false, false, false, true)) - /* gcj compiled conftestfail.java successfully, and - "gcj -fsource=$source_version" rejects it. So - the -fsource option is useful. */ - resultp->fsource_option = true; - } - } - } - - resultp->usable = true; - } + tmpdir->dir_name, false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* gcj compiled conftest.java successfully. */ + /* Try adding -fsource option if it is useful. */ + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_gcj (java_sources, 1, + false, true, source_version, false, NULL, + tmpdir->dir_name, false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + const char *failcode = get_failcode_snippet (source_version); + + if (failcode != NULL) + { + free (compiled_file_name); + free (conftest_file_name); + + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, failcode)) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_gcj (java_sources, 1, + false, false, NULL, false, NULL, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + { + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (compile_using_gcj (java_sources, 1, + false, true, source_version, + false, NULL, + tmpdir->dir_name, + false, false, false, true)) + /* gcj compiled conftestfail.java successfully, and + "gcj -fsource=$source_version" rejects it. So + the -fsource option is useful. */ + resultp->fsource_option = true; + } + } + } + + resultp->usable = true; + } else - { - /* Try with -fsource and -ftarget options. */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_gcj (java_sources, 1, - false, true, source_version, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "gcj -fsource $source_version -ftarget $target_version" - compiled conftest.java successfully. */ - resultp->fsource_option = true; - resultp->ftarget_option = true; - resultp->usable = true; - } - } + { + /* Try with -fsource and -ftarget options. */ + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_gcj (java_sources, 1, + false, true, source_version, + true, target_version, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* "gcj -fsource $source_version -ftarget $target_version" + compiled conftest.java successfully. */ + resultp->fsource_option = true; + resultp->ftarget_option = true; + resultp->usable = true; + } + } free (compiled_file_name); free (conftest_file_name); @@ -1667,28 +1667,28 @@ is_oldgcj_14_14_usable (bool *usablep) tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet ("1.4"))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet ("1.4"))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_gcj (java_sources, 1, false, false, NULL, false, NULL, - tmpdir->dir_name, false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - /* Compilation succeeded. */ - gcj_usable = true; + tmpdir->dir_name, false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + /* Compilation succeeded. */ + gcj_usable = true; free (compiled_file_name); free (conftest_file_name); @@ -1715,7 +1715,7 @@ is_oldgcj_14_13_usable (bool *usablep, bool *need_no_assert_option_p) if (!gcj_tested) { /* Try gcj and "gcj -fno-assert". But add -fno-assert only if - it works (not gcj < 3.3). */ + it works (not gcj < 3.3). */ struct temp_dir *tmpdir; char *conftest_file_name; char *compiled_file_name; @@ -1724,46 +1724,46 @@ is_oldgcj_14_13_usable (bool *usablep, bool *need_no_assert_option_p) tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet ("1.3"))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet ("1.3"))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_gcj (java_sources, 1, true, false, NULL, false, NULL, - tmpdir->dir_name, false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - /* Compilation succeeded. */ - { - gcj_usable = true; - gcj_need_no_assert_option = true; - } + tmpdir->dir_name, false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + /* Compilation succeeded. */ + { + gcj_usable = true; + gcj_need_no_assert_option = true; + } else - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_gcj (java_sources, 1, false, - false, NULL, false, NULL, - tmpdir->dir_name, false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - /* Compilation succeeded. */ - { - gcj_usable = true; - gcj_need_no_assert_option = false; - } - } + { + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_gcj (java_sources, 1, false, + false, NULL, false, NULL, + tmpdir->dir_name, false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + /* Compilation succeeded. */ + { + gcj_usable = true; + gcj_need_no_assert_option = false; + } + } free (compiled_file_name); free (conftest_file_name); @@ -1793,7 +1793,7 @@ is_javac_present (void) argv[0] = "javac"; argv[1] = NULL; exitstatus = execute ("javac", "javac", argv, false, false, true, true, - true, false, NULL); + true, false, NULL); javac_present = (exitstatus == 0 || exitstatus == 1 || exitstatus == 2); javac_tested = true; } @@ -1806,7 +1806,7 @@ is_javac_present (void) Return a failure indicator (true upon error). */ static bool is_javac_usable (const char *source_version, const char *target_version, - bool *usablep, bool *source_option_p, bool *target_option_p) + bool *usablep, bool *source_option_p, bool *target_option_p) { /* The cache depends on the source_version and target_version. */ struct result_t @@ -1820,7 +1820,7 @@ is_javac_usable (const char *source_version, const char *target_version, struct result_t *resultp; resultp = &result_cache[source_version_index (source_version)] - [target_version_index (target_version)]; + [target_version_index (target_version)]; if (!resultp->tested) { /* Try javac. */ @@ -1832,203 +1832,203 @@ is_javac_usable (const char *source_version, const char *target_version, tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) - return true; + return true; conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.java", NULL); if (write_temp_file (tmpdir, conftest_file_name, - get_goodcode_snippet (source_version))) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } + get_goodcode_snippet (source_version))) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); + xconcatenated_filename (tmpdir->dir_name, "conftest.class", NULL); register_temp_file (tmpdir, compiled_file_name); java_sources[0] = conftest_file_name; if (!compile_using_javac (java_sources, 1, - false, source_version, - false, target_version, - tmpdir->dir_name, false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* javac compiled conftest.java successfully. */ - /* Try adding -source option if it is useful. */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - true, source_version, - false, target_version, - tmpdir->dir_name, false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, failcode)) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - false, source_version, - false, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_javac (java_sources, 1, - true, source_version, - false, target_version, - tmpdir->dir_name, - false, false, false, true)) - /* javac compiled conftestfail.java successfully, and - "javac -source $source_version" rejects it. So the - -source option is useful. */ - resultp->source_option = true; - } - } - } - - resultp->usable = true; - } + false, source_version, + false, target_version, + tmpdir->dir_name, false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* javac compiled conftest.java successfully. */ + /* Try adding -source option if it is useful. */ + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_javac (java_sources, 1, + true, source_version, + false, target_version, + tmpdir->dir_name, false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + const char *failcode = get_failcode_snippet (source_version); + + if (failcode != NULL) + { + free (compiled_file_name); + free (conftest_file_name); + + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, failcode)) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_javac (java_sources, 1, + false, source_version, + false, target_version, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + { + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (compile_using_javac (java_sources, 1, + true, source_version, + false, target_version, + tmpdir->dir_name, + false, false, false, true)) + /* javac compiled conftestfail.java successfully, and + "javac -source $source_version" rejects it. So the + -source option is useful. */ + resultp->source_option = true; + } + } + } + + resultp->usable = true; + } else - { - /* Try with -target option alone. (Sun javac 1.3.1 has the -target - option but no -source option.) */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - false, source_version, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "javac -target $target_version" compiled conftest.java - successfully. */ - /* Try adding -source option if it is useful. */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - true, source_version, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - const char *failcode = get_failcode_snippet (source_version); - - if (failcode != NULL) - { - free (compiled_file_name); - free (conftest_file_name); - - conftest_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.java", - NULL); - if (write_temp_file (tmpdir, conftest_file_name, - failcode)) - { - free (conftest_file_name); - cleanup_temp_dir (tmpdir); - return true; - } - - compiled_file_name = - xconcatenated_filename (tmpdir->dir_name, - "conftestfail.class", - NULL); - register_temp_file (tmpdir, compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - false, source_version, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0) - { - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (compile_using_javac (java_sources, 1, - true, source_version, - true, target_version, - tmpdir->dir_name, - false, false, false, true)) - /* "javac -target $target_version" compiled - conftestfail.java successfully, and - "javac -target $target_version -source $source_version" - rejects it. So the -source option is useful. */ - resultp->source_option = true; - } - } - } - - resultp->target_option = true; - resultp->usable = true; - } - else - { - /* Maybe this -target option requires a -source option? Try with - -target and -source options. (Supported by Sun javac 1.4 and - higher.) */ - unlink (compiled_file_name); - - java_sources[0] = conftest_file_name; - if (!compile_using_javac (java_sources, 1, - true, source_version, - true, target_version, - tmpdir->dir_name, - false, false, false, true) - && stat (compiled_file_name, &statbuf) >= 0 - && get_classfile_version (compiled_file_name) - <= corresponding_classfile_version (target_version)) - { - /* "javac -target $target_version -source $source_version" - compiled conftest.java successfully. */ - resultp->source_option = true; - resultp->target_option = true; - resultp->usable = true; - } - } - } + { + /* Try with -target option alone. (Sun javac 1.3.1 has the -target + option but no -source option.) */ + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_javac (java_sources, 1, + false, source_version, + true, target_version, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* "javac -target $target_version" compiled conftest.java + successfully. */ + /* Try adding -source option if it is useful. */ + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_javac (java_sources, 1, + true, source_version, + true, target_version, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + const char *failcode = get_failcode_snippet (source_version); + + if (failcode != NULL) + { + free (compiled_file_name); + free (conftest_file_name); + + conftest_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.java", + NULL); + if (write_temp_file (tmpdir, conftest_file_name, + failcode)) + { + free (conftest_file_name); + cleanup_temp_dir (tmpdir); + return true; + } + + compiled_file_name = + xconcatenated_filename (tmpdir->dir_name, + "conftestfail.class", + NULL); + register_temp_file (tmpdir, compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_javac (java_sources, 1, + false, source_version, + true, target_version, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0) + { + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (compile_using_javac (java_sources, 1, + true, source_version, + true, target_version, + tmpdir->dir_name, + false, false, false, true)) + /* "javac -target $target_version" compiled + conftestfail.java successfully, and + "javac -target $target_version -source $source_version" + rejects it. So the -source option is useful. */ + resultp->source_option = true; + } + } + } + + resultp->target_option = true; + resultp->usable = true; + } + else + { + /* Maybe this -target option requires a -source option? Try with + -target and -source options. (Supported by Sun javac 1.4 and + higher.) */ + unlink (compiled_file_name); + + java_sources[0] = conftest_file_name; + if (!compile_using_javac (java_sources, 1, + true, source_version, + true, target_version, + tmpdir->dir_name, + false, false, false, true) + && stat (compiled_file_name, &statbuf) >= 0 + && get_classfile_version (compiled_file_name) + <= corresponding_classfile_version (target_version)) + { + /* "javac -target $target_version -source $source_version" + compiled conftest.java successfully. */ + resultp->source_option = true; + resultp->target_option = true; + resultp->usable = true; + } + } + } free (compiled_file_name); free (conftest_file_name); @@ -2057,7 +2057,7 @@ is_jikes_present (void) argv[0] = "jikes"; argv[1] = NULL; exitstatus = execute ("jikes", "jikes", argv, false, false, true, true, - true, false, NULL); + true, false, NULL); jikes_present = (exitstatus == 0 || exitstatus == 1); jikes_tested = true; } @@ -2069,15 +2069,15 @@ is_jikes_present (void) bool compile_java_class (const char * const *java_sources, - unsigned int java_sources_count, - const char * const *classpaths, - unsigned int classpaths_count, - const char *source_version, - const char *target_version, - const char *directory, - bool optimize, bool debug, - bool use_minimal_classpath, - bool verbose) + unsigned int java_sources_count, + const char * const *classpaths, + unsigned int classpaths_count, + const char *source_version, + const char *target_version, + const char *directory, + bool optimize, bool debug, + bool use_minimal_classpath, + bool verbose) { bool err = false; char *old_JAVA_HOME; @@ -2086,106 +2086,106 @@ compile_java_class (const char * const *java_sources, const char *javac = getenv ("JAVAC"); if (javac != NULL && javac[0] != '\0') { - bool usable = false; - bool no_assert_option = false; - bool source_option = false; - bool target_option = false; - bool fsource_option = false; - bool ftarget_option = false; - - if (target_version == NULL) - target_version = default_target_version (); - - if (is_envjavac_gcj (javac)) - { - /* It's a version of gcj. */ - if (is_envjavac_gcj43 (javac)) - { - /* It's a version of gcj >= 4.3. Assume the classfile versions - are correct. */ - if (is_envjavac_gcj43_usable (javac, - source_version, target_version, - &usable, - &fsource_option, &ftarget_option)) - { - err = true; - goto done1; - } - } - else - { - /* It's a version of gcj < 4.3. Ignore the version of the - class files that it creates. */ - if (strcmp (target_version, "1.4") == 0 - && strcmp (source_version, "1.4") == 0) - { - if (is_envjavac_oldgcj_14_14_usable (javac, &usable)) - { - err = true; - goto done1; - } - } - else if (strcmp (target_version, "1.4") == 0 - && strcmp (source_version, "1.3") == 0) - { - if (is_envjavac_oldgcj_14_13_usable (javac, - &usable, - &no_assert_option)) - { - err = true; - goto done1; - } - } - } - } - else - { - /* It's not gcj. Assume the classfile versions are correct. */ - if (is_envjavac_nongcj_usable (javac, - source_version, target_version, - &usable, - &source_option, &target_option)) - { - err = true; - goto done1; - } - } - - if (usable) - { - char *old_classpath; - char *javac_with_options; - - /* Set CLASSPATH. */ - old_classpath = - set_classpath (classpaths, classpaths_count, false, verbose); - - javac_with_options = - (no_assert_option - ? xasprintf ("%s -fno-assert", javac) - : xasprintf ("%s%s%s%s%s%s%s%s%s", - javac, - source_option ? " -source " : "", - source_option ? source_version : "", - target_option ? " -target " : "", - target_option ? target_version : "", - fsource_option ? " -fsource=" : "", - fsource_option ? source_version : "", - ftarget_option ? " -ftarget=" : "", - ftarget_option ? target_version : "")); - - err = compile_using_envjavac (javac_with_options, - java_sources, java_sources_count, - directory, optimize, debug, verbose, - false); - - free (javac_with_options); - - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); - - goto done1; - } + bool usable = false; + bool no_assert_option = false; + bool source_option = false; + bool target_option = false; + bool fsource_option = false; + bool ftarget_option = false; + + if (target_version == NULL) + target_version = default_target_version (); + + if (is_envjavac_gcj (javac)) + { + /* It's a version of gcj. */ + if (is_envjavac_gcj43 (javac)) + { + /* It's a version of gcj >= 4.3. Assume the classfile versions + are correct. */ + if (is_envjavac_gcj43_usable (javac, + source_version, target_version, + &usable, + &fsource_option, &ftarget_option)) + { + err = true; + goto done1; + } + } + else + { + /* It's a version of gcj < 4.3. Ignore the version of the + class files that it creates. */ + if (strcmp (target_version, "1.4") == 0 + && strcmp (source_version, "1.4") == 0) + { + if (is_envjavac_oldgcj_14_14_usable (javac, &usable)) + { + err = true; + goto done1; + } + } + else if (strcmp (target_version, "1.4") == 0 + && strcmp (source_version, "1.3") == 0) + { + if (is_envjavac_oldgcj_14_13_usable (javac, + &usable, + &no_assert_option)) + { + err = true; + goto done1; + } + } + } + } + else + { + /* It's not gcj. Assume the classfile versions are correct. */ + if (is_envjavac_nongcj_usable (javac, + source_version, target_version, + &usable, + &source_option, &target_option)) + { + err = true; + goto done1; + } + } + + if (usable) + { + char *old_classpath; + char *javac_with_options; + + /* Set CLASSPATH. */ + old_classpath = + set_classpath (classpaths, classpaths_count, false, verbose); + + javac_with_options = + (no_assert_option + ? xasprintf ("%s -fno-assert", javac) + : xasprintf ("%s%s%s%s%s%s%s%s%s", + javac, + source_option ? " -source " : "", + source_option ? source_version : "", + target_option ? " -target " : "", + target_option ? target_version : "", + fsource_option ? " -fsource=" : "", + fsource_option ? source_version : "", + ftarget_option ? " -ftarget=" : "", + ftarget_option ? target_version : "")); + + err = compile_using_envjavac (javac_with_options, + java_sources, java_sources_count, + directory, optimize, debug, verbose, + false); + + free (javac_with_options); + + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); + + goto done1; + } } } @@ -2206,68 +2206,68 @@ compile_java_class (const char * const *java_sources, bool ftarget_option = false; if (target_version == NULL) - target_version = default_target_version (); + target_version = default_target_version (); if (is_gcj_43 ()) - { - /* It's a version of gcj >= 4.3. Assume the classfile versions - are correct. */ - if (is_gcj43_usable (source_version, target_version, - &usable, &fsource_option, &ftarget_option)) - { - err = true; - goto done1; - } - } + { + /* It's a version of gcj >= 4.3. Assume the classfile versions + are correct. */ + if (is_gcj43_usable (source_version, target_version, + &usable, &fsource_option, &ftarget_option)) + { + err = true; + goto done1; + } + } else - { - /* It's a version of gcj < 4.3. Ignore the version of the class - files that it creates. - Test whether it supports the desired target-version and - source-version. */ - if (strcmp (target_version, "1.4") == 0 - && strcmp (source_version, "1.4") == 0) - { - if (is_oldgcj_14_14_usable (&usable)) - { - err = true; - goto done1; - } - } - else if (strcmp (target_version, "1.4") == 0 - && strcmp (source_version, "1.3") == 0) - { - if (is_oldgcj_14_13_usable (&usable, &no_assert_option)) - { - err = true; - goto done1; - } - } - } + { + /* It's a version of gcj < 4.3. Ignore the version of the class + files that it creates. + Test whether it supports the desired target-version and + source-version. */ + if (strcmp (target_version, "1.4") == 0 + && strcmp (source_version, "1.4") == 0) + { + if (is_oldgcj_14_14_usable (&usable)) + { + err = true; + goto done1; + } + } + else if (strcmp (target_version, "1.4") == 0 + && strcmp (source_version, "1.3") == 0) + { + if (is_oldgcj_14_13_usable (&usable, &no_assert_option)) + { + err = true; + goto done1; + } + } + } if (usable) - { - char *old_classpath; - - /* Set CLASSPATH. We could also use the --CLASSPATH=... option - of gcj. Note that --classpath=... option is different: its - argument should also contain gcj's libgcj.jar, but we don't - know its location. */ - old_classpath = - set_classpath (classpaths, classpaths_count, use_minimal_classpath, - verbose); - - err = compile_using_gcj (java_sources, java_sources_count, - no_assert_option, - fsource_option, source_version, - ftarget_option, target_version, - directory, optimize, debug, verbose, false); - - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); - - goto done2; - } + { + char *old_classpath; + + /* Set CLASSPATH. We could also use the --CLASSPATH=... option + of gcj. Note that --classpath=... option is different: its + argument should also contain gcj's libgcj.jar, but we don't + know its location. */ + old_classpath = + set_classpath (classpaths, classpaths_count, use_minimal_classpath, + verbose); + + err = compile_using_gcj (java_sources, java_sources_count, + no_assert_option, + fsource_option, source_version, + ftarget_option, target_version, + directory, optimize, debug, verbose, false); + + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); + + goto done2; + } } if (is_javac_present ()) @@ -2277,67 +2277,67 @@ compile_java_class (const char * const *java_sources, bool target_option = false; if (target_version == NULL) - target_version = default_target_version (); + target_version = default_target_version (); if (is_javac_usable (source_version, target_version, - &usable, &source_option, &target_option)) - { - err = true; - goto done1; - } + &usable, &source_option, &target_option)) + { + err = true; + goto done1; + } if (usable) - { - char *old_classpath; - - /* Set CLASSPATH. We don't use the "-classpath ..." option because - in JDK 1.1.x its argument should also contain the JDK's - classes.zip, but we don't know its location. (In JDK 1.3.0 it - would work.) */ - old_classpath = - set_classpath (classpaths, classpaths_count, use_minimal_classpath, - verbose); - - err = compile_using_javac (java_sources, java_sources_count, - source_option, source_version, - target_option, target_version, - directory, optimize, debug, verbose, - false); - - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); - - goto done2; - } + { + char *old_classpath; + + /* Set CLASSPATH. We don't use the "-classpath ..." option because + in JDK 1.1.x its argument should also contain the JDK's + classes.zip, but we don't know its location. (In JDK 1.3.0 it + would work.) */ + old_classpath = + set_classpath (classpaths, classpaths_count, use_minimal_classpath, + verbose); + + err = compile_using_javac (java_sources, java_sources_count, + source_option, source_version, + target_option, target_version, + directory, optimize, debug, verbose, + false); + + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); + + goto done2; + } } if (is_jikes_present ()) { /* Test whether it supports the desired target-version and - source-version. */ + source-version. */ bool usable = (strcmp (source_version, "1.3") == 0); if (usable) - { - char *old_classpath; - - /* Set CLASSPATH. We could also use the "-classpath ..." option. - Since jikes doesn't come with its own standard library, it - needs a classes.zip or rt.jar or libgcj.jar in the CLASSPATH. - To increase the chance of success, we reuse the current CLASSPATH - if the user has set it. */ - old_classpath = - set_classpath (classpaths, classpaths_count, false, verbose); - - err = compile_using_jikes (java_sources, java_sources_count, - directory, optimize, debug, verbose, - false); - - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); - - goto done2; - } + { + char *old_classpath; + + /* Set CLASSPATH. We could also use the "-classpath ..." option. + Since jikes doesn't come with its own standard library, it + needs a classes.zip or rt.jar or libgcj.jar in the CLASSPATH. + To increase the chance of success, we reuse the current CLASSPATH + if the user has set it. */ + old_classpath = + set_classpath (classpaths, classpaths_count, false, verbose); + + err = compile_using_jikes (java_sources, java_sources_count, + directory, optimize, debug, verbose, + false); + + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); + + goto done2; + } } error (0, 0, _("Java compiler not found, try installing gcj or set $JAVAC")); diff --git a/lib/javacomp.h b/lib/javacomp.h index 7ebcbaae1..5c85ca4dd 100644 --- a/lib/javacomp.h +++ b/lib/javacomp.h @@ -62,14 +62,14 @@ If verbose, the command to be executed will be printed. Return false if OK, true on error. */ extern bool compile_java_class (const char * const *java_sources, - unsigned int java_sources_count, - const char * const *classpaths, - unsigned int classpaths_count, - const char *source_version, - const char *target_version, - const char *directory, - bool optimize, bool debug, - bool use_minimal_classpath, - bool verbose); + unsigned int java_sources_count, + const char * const *classpaths, + unsigned int classpaths_count, + const char *source_version, + const char *target_version, + const char *directory, + bool optimize, bool debug, + bool use_minimal_classpath, + bool verbose); #endif /* _JAVACOMP_H */ diff --git a/lib/javaexec.c b/lib/javaexec.c index 8bcd6defc..a8ba1a562 100644 --- a/lib/javaexec.c +++ b/lib/javaexec.c @@ -59,7 +59,7 @@ We try the Java virtual machines in the following order: 1. getenv ("JAVA"), because the user must be able to override our - preferences, + preferences, 2. "gij", because it is a completely free JVM, 3. "java", because it is a standard JVM, 4. "jre", comes last because it requires a CLASSPATH environment variable, @@ -71,13 +71,13 @@ bool execute_java_class (const char *class_name, - const char * const *classpaths, - unsigned int classpaths_count, - bool use_minimal_classpath, - const char *exe_dir, - const char * const *args, - bool verbose, bool quiet, - execute_fn *executer, void *private_data) + const char * const *classpaths, + unsigned int classpaths_count, + bool use_minimal_classpath, + const char *exe_dir, + const char * const *args, + bool verbose, bool quiet, + execute_fn *executer, void *private_data) { bool err = false; unsigned int nargs; @@ -101,19 +101,19 @@ execute_java_class (const char *class_name, /* Set CLASSPATH. */ old_classpath = - set_classpath (classpaths, classpaths_count, use_minimal_classpath, - verbose); + set_classpath (classpaths, classpaths_count, use_minimal_classpath, + verbose); argv[0] = exe_pathname; for (i = 0; i <= nargs; i++) - argv[1 + i] = (char *) args[i]; + argv[1 + i] = (char *) args[i]; if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } err = executer (class_name, exe_pathname, argv, private_data); @@ -129,61 +129,61 @@ execute_java_class (const char *class_name, const char *java = getenv ("JAVA"); if (java != NULL && java[0] != '\0') { - /* Because $JAVA may consist of a command and options, we use the - shell. Because $JAVA has been set by the user, we leave all - all environment variables in place, including JAVA_HOME, and - we don't erase the user's CLASSPATH. */ - char *old_classpath; - unsigned int command_length; - char *command; - char *argv[4]; - const char * const *arg; - char *p; - - /* Set CLASSPATH. */ - old_classpath = - set_classpath (classpaths, classpaths_count, false, - verbose); - - command_length = strlen (java); - command_length += 1 + shell_quote_length (class_name); - for (arg = args; *arg != NULL; arg++) - command_length += 1 + shell_quote_length (*arg); - command_length += 1; - - command = (char *) xmalloca (command_length); - p = command; - /* Don't shell_quote $JAVA, because it may consist of a command - and options. */ - memcpy (p, java, strlen (java)); - p += strlen (java); - *p++ = ' '; - p = shell_quote_copy (p, class_name); - for (arg = args; *arg != NULL; arg++) - { - *p++ = ' '; - p = shell_quote_copy (p, *arg); - } - *p++ = '\0'; - /* Ensure command_length was correctly calculated. */ - if (p - command > command_length) - abort (); - - if (verbose) - printf ("%s\n", command); - - argv[0] = "/bin/sh"; - argv[1] = "-c"; - argv[2] = command; - argv[3] = NULL; - err = executer (java, "/bin/sh", argv, private_data); - - freea (command); - - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); - - goto done1; + /* Because $JAVA may consist of a command and options, we use the + shell. Because $JAVA has been set by the user, we leave all + all environment variables in place, including JAVA_HOME, and + we don't erase the user's CLASSPATH. */ + char *old_classpath; + unsigned int command_length; + char *command; + char *argv[4]; + const char * const *arg; + char *p; + + /* Set CLASSPATH. */ + old_classpath = + set_classpath (classpaths, classpaths_count, false, + verbose); + + command_length = strlen (java); + command_length += 1 + shell_quote_length (class_name); + for (arg = args; *arg != NULL; arg++) + command_length += 1 + shell_quote_length (*arg); + command_length += 1; + + command = (char *) xmalloca (command_length); + p = command; + /* Don't shell_quote $JAVA, because it may consist of a command + and options. */ + memcpy (p, java, strlen (java)); + p += strlen (java); + *p++ = ' '; + p = shell_quote_copy (p, class_name); + for (arg = args; *arg != NULL; arg++) + { + *p++ = ' '; + p = shell_quote_copy (p, *arg); + } + *p++ = '\0'; + /* Ensure command_length was correctly calculated. */ + if (p - command > command_length) + abort (); + + if (verbose) + printf ("%s\n", command); + + argv[0] = "/bin/sh"; + argv[1] = "-c"; + argv[2] = command; + argv[3] = NULL; + err = executer (java, "/bin/sh", argv, private_data); + + freea (command); + + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); + + goto done1; } } @@ -201,50 +201,50 @@ execute_java_class (const char *class_name, if (!gij_tested) { - /* Test for presence of gij: "gij --version > /dev/null" */ - char *argv[3]; - int exitstatus; - - argv[0] = "gij"; - argv[1] = "--version"; - argv[2] = NULL; - exitstatus = execute ("gij", "gij", argv, false, false, true, true, - true, false, NULL); - gij_present = (exitstatus == 0); - gij_tested = true; + /* Test for presence of gij: "gij --version > /dev/null" */ + char *argv[3]; + int exitstatus; + + argv[0] = "gij"; + argv[1] = "--version"; + argv[2] = NULL; + exitstatus = execute ("gij", "gij", argv, false, false, true, true, + true, false, NULL); + gij_present = (exitstatus == 0); + gij_tested = true; } if (gij_present) { - char *old_classpath; - char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); - unsigned int i; + char *old_classpath; + char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); + unsigned int i; - /* Set CLASSPATH. */ - old_classpath = - set_classpath (classpaths, classpaths_count, use_minimal_classpath, - verbose); + /* Set CLASSPATH. */ + old_classpath = + set_classpath (classpaths, classpaths_count, use_minimal_classpath, + verbose); - argv[0] = "gij"; - argv[1] = (char *) class_name; - for (i = 0; i <= nargs; i++) - argv[2 + i] = (char *) args[i]; + argv[0] = "gij"; + argv[1] = (char *) class_name; + for (i = 0; i <= nargs; i++) + argv[2 + i] = (char *) args[i]; - if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + if (verbose) + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } - err = executer ("gij", "gij", argv, private_data); + err = executer ("gij", "gij", argv, private_data); - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); - freea (argv); + freea (argv); - goto done2; + goto done2; } } @@ -254,52 +254,52 @@ execute_java_class (const char *class_name, if (!java_tested) { - /* Test for presence of java: "java -version 2> /dev/null" */ - char *argv[3]; - int exitstatus; - - argv[0] = "java"; - argv[1] = "-version"; - argv[2] = NULL; - exitstatus = execute ("java", "java", argv, false, false, true, true, - true, false, NULL); - java_present = (exitstatus == 0); - java_tested = true; + /* Test for presence of java: "java -version 2> /dev/null" */ + char *argv[3]; + int exitstatus; + + argv[0] = "java"; + argv[1] = "-version"; + argv[2] = NULL; + exitstatus = execute ("java", "java", argv, false, false, true, true, + true, false, NULL); + java_present = (exitstatus == 0); + java_tested = true; } if (java_present) { - char *old_classpath; - char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); - unsigned int i; + char *old_classpath; + char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); + unsigned int i; - /* Set CLASSPATH. We don't use the "-classpath ..." option because - in JDK 1.1.x its argument should also contain the JDK's classes.zip, - but we don't know its location. (In JDK 1.3.0 it would work.) */ - old_classpath = - set_classpath (classpaths, classpaths_count, use_minimal_classpath, - verbose); + /* Set CLASSPATH. We don't use the "-classpath ..." option because + in JDK 1.1.x its argument should also contain the JDK's classes.zip, + but we don't know its location. (In JDK 1.3.0 it would work.) */ + old_classpath = + set_classpath (classpaths, classpaths_count, use_minimal_classpath, + verbose); - argv[0] = "java"; - argv[1] = (char *) class_name; - for (i = 0; i <= nargs; i++) - argv[2 + i] = (char *) args[i]; + argv[0] = "java"; + argv[1] = (char *) class_name; + for (i = 0; i <= nargs; i++) + argv[2 + i] = (char *) args[i]; - if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + if (verbose) + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } - err = executer ("java", "java", argv, private_data); + err = executer ("java", "java", argv, private_data); - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); - freea (argv); + freea (argv); - goto done2; + goto done2; } } @@ -309,51 +309,51 @@ execute_java_class (const char *class_name, if (!jre_tested) { - /* Test for presence of jre: "jre 2> /dev/null ; test $? = 1" */ - char *argv[2]; - int exitstatus; - - argv[0] = "jre"; - argv[1] = NULL; - exitstatus = execute ("jre", "jre", argv, false, false, true, true, - true, false, NULL); - jre_present = (exitstatus == 0 || exitstatus == 1); - jre_tested = true; + /* Test for presence of jre: "jre 2> /dev/null ; test $? = 1" */ + char *argv[2]; + int exitstatus; + + argv[0] = "jre"; + argv[1] = NULL; + exitstatus = execute ("jre", "jre", argv, false, false, true, true, + true, false, NULL); + jre_present = (exitstatus == 0 || exitstatus == 1); + jre_tested = true; } if (jre_present) { - char *old_classpath; - char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); - unsigned int i; + char *old_classpath; + char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); + unsigned int i; - /* Set CLASSPATH. We don't use the "-classpath ..." option because - in JDK 1.1.x its argument should also contain the JDK's classes.zip, - but we don't know its location. */ - old_classpath = - set_classpath (classpaths, classpaths_count, use_minimal_classpath, - verbose); + /* Set CLASSPATH. We don't use the "-classpath ..." option because + in JDK 1.1.x its argument should also contain the JDK's classes.zip, + but we don't know its location. */ + old_classpath = + set_classpath (classpaths, classpaths_count, use_minimal_classpath, + verbose); - argv[0] = "jre"; - argv[1] = (char *) class_name; - for (i = 0; i <= nargs; i++) - argv[2 + i] = (char *) args[i]; + argv[0] = "jre"; + argv[1] = (char *) class_name; + for (i = 0; i <= nargs; i++) + argv[2 + i] = (char *) args[i]; - if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + if (verbose) + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } - err = executer ("jre", "jre", argv, private_data); + err = executer ("jre", "jre", argv, private_data); - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); - freea (argv); + freea (argv); - goto done2; + goto done2; } } @@ -365,50 +365,50 @@ execute_java_class (const char *class_name, if (!jview_tested) { - /* Test for presence of jview: "jview -? >nul ; test $? = 1" */ - char *argv[3]; - int exitstatus; - - argv[0] = "jview"; - argv[1] = "-?"; - argv[2] = NULL; - exitstatus = execute ("jview", "jview", argv, false, false, true, true, - true, false, NULL); - jview_present = (exitstatus == 0 || exitstatus == 1); - jview_tested = true; + /* Test for presence of jview: "jview -? >nul ; test $? = 1" */ + char *argv[3]; + int exitstatus; + + argv[0] = "jview"; + argv[1] = "-?"; + argv[2] = NULL; + exitstatus = execute ("jview", "jview", argv, false, false, true, true, + true, false, NULL); + jview_present = (exitstatus == 0 || exitstatus == 1); + jview_tested = true; } if (jview_present) { - char *old_classpath; - char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); - unsigned int i; + char *old_classpath; + char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); + unsigned int i; - /* Set CLASSPATH. */ - old_classpath = - set_classpath (classpaths, classpaths_count, use_minimal_classpath, - verbose); + /* Set CLASSPATH. */ + old_classpath = + set_classpath (classpaths, classpaths_count, use_minimal_classpath, + verbose); - argv[0] = "jview"; - argv[1] = (char *) class_name; - for (i = 0; i <= nargs; i++) - argv[2 + i] = (char *) args[i]; + argv[0] = "jview"; + argv[1] = (char *) class_name; + for (i = 0; i <= nargs; i++) + argv[2 + i] = (char *) args[i]; - if (verbose) - { - char *command = shell_quote_argv (argv); - printf ("%s\n", command); - free (command); - } + if (verbose) + { + char *command = shell_quote_argv (argv); + printf ("%s\n", command); + free (command); + } - err = executer ("jview", "jview", argv, private_data); + err = executer ("jview", "jview", argv, private_data); - /* Reset CLASSPATH. */ - reset_classpath (old_classpath); + /* Reset CLASSPATH. */ + reset_classpath (old_classpath); - freea (argv); + freea (argv); - goto done2; + goto done2; } } #endif diff --git a/lib/javaexec.h b/lib/javaexec.h index 6bf6293e5..277c7bd79 100644 --- a/lib/javaexec.h +++ b/lib/javaexec.h @@ -21,8 +21,8 @@ #include typedef bool execute_fn (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data); + const char *prog_path, char **prog_argv, + void *private_data); /* Execute a Java class. class_name is the Java class name to be executed. @@ -39,12 +39,12 @@ typedef bool execute_fn (const char *progname, Return false if OK, true on error. If quiet, error messages will not be printed. */ extern bool execute_java_class (const char *class_name, - const char * const *classpaths, - unsigned int classpaths_count, - bool use_minimal_classpath, - const char *exe_dir, - const char * const *args, - bool verbose, bool quiet, - execute_fn *executer, void *private_data); + const char * const *classpaths, + unsigned int classpaths_count, + bool use_minimal_classpath, + const char *exe_dir, + const char * const *args, + bool verbose, bool quiet, + execute_fn *executer, void *private_data); #endif /* _JAVAEXEC_H */ diff --git a/lib/javaversion.c b/lib/javaversion.c index 94a353a0f..eaa439cde 100644 --- a/lib/javaversion.c +++ b/lib/javaversion.c @@ -50,8 +50,8 @@ struct locals static bool execute_and_read_line (const char *progname, - const char *prog_path, char **prog_argv, - void *private_data) + const char *prog_path, char **prog_argv, + void *private_data) { struct locals *l = (struct locals *) private_data; pid_t child; @@ -64,7 +64,7 @@ execute_and_read_line (const char *progname, /* Open a pipe to the JVM. */ child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false, - true, false, fd); + true, false, fd); if (child == -1) return false; @@ -113,7 +113,7 @@ javaexec_version (void) args[0] = NULL; locals.line = NULL; execute_java_class (class_name, &pkgdatadir, 1, true, NULL, args, - false, false, execute_and_read_line, &locals); + false, false, execute_and_read_line, &locals); return locals.line; } diff --git a/lib/ldexpl.c b/lib/ldexpl.c index a783052de..1b670377a 100644 --- a/lib/ldexpl.c +++ b/lib/ldexpl.c @@ -39,25 +39,25 @@ ldexpl(long double x, int exp) if (!(isnanl (x) || x + x == x)) { if (exp < 0) - { - exp = -exp; - factor = 0.5L; - } + { + exp = -exp; + factor = 0.5L; + } else - factor = 2.0L; + 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; - } + 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 (); diff --git a/lib/linebuffer.c b/lib/linebuffer.c index 90e4cca86..6f1dc89f9 100644 --- a/lib/linebuffer.c +++ b/lib/linebuffer.c @@ -57,7 +57,7 @@ readlinebuffer (struct linebuffer *linebuffer, FILE *stream) Otherwise, return LINEBUFFER. */ struct linebuffer * readlinebuffer_delim (struct linebuffer *linebuffer, FILE *stream, - char delimiter) + char delimiter) { int c; char *buffer = linebuffer->buffer; @@ -71,21 +71,21 @@ readlinebuffer_delim (struct linebuffer *linebuffer, FILE *stream, { c = getc (stream); if (c == EOF) - { - if (p == buffer || ferror (stream)) - return NULL; - if (p[-1] == delimiter) - break; - c = delimiter; - } + { + if (p == buffer || ferror (stream)) + return NULL; + if (p[-1] == delimiter) + break; + c = delimiter; + } if (p == end) - { - size_t oldsize = linebuffer->size; - buffer = x2realloc (buffer, &linebuffer->size); - p = buffer + oldsize; - linebuffer->buffer = buffer; - end = buffer + linebuffer->size; - } + { + size_t oldsize = linebuffer->size; + buffer = x2realloc (buffer, &linebuffer->size); + p = buffer + oldsize; + linebuffer->buffer = buffer; + end = buffer + linebuffer->size; + } *p++ = c; } while (c != delimiter); diff --git a/lib/linebuffer.h b/lib/linebuffer.h index db4110304..365cb22a6 100644 --- a/lib/linebuffer.h +++ b/lib/linebuffer.h @@ -25,8 +25,8 @@ struct linebuffer { - size_t size; /* Allocated. */ - size_t length; /* Used. */ + size_t size; /* Allocated. */ + size_t length; /* Used. */ char *buffer; }; @@ -39,7 +39,7 @@ void initbuffer (struct linebuffer *linebuffer); the last character in the file. Do not NUL-terminate. Return LINEBUFFER, except at end of file return NULL. */ struct linebuffer *readlinebuffer_delim (struct linebuffer *linebuffer, - FILE *stream, char delimiter); + FILE *stream, char delimiter); /* Read an arbitrarily long line of text from STREAM into LINEBUFFER. Keep the newline; append a newline if it's the last line of a file diff --git a/lib/link.c b/lib/link.c index 994ae4569..e4a21da13 100644 --- a/lib/link.c +++ b/lib/link.c @@ -33,8 +33,8 @@ /* CreateHardLink was introduced only in Windows 2000. */ typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCTSTR lpFileName, - LPCTSTR lpExistingFileName, - LPSECURITY_ATTRIBUTES lpSecurityAttributes); + LPCTSTR lpExistingFileName, + LPSECURITY_ATTRIBUTES lpSecurityAttributes); static CreateHardLinkFuncType CreateHardLinkFunc = NULL; static BOOL initialized = FALSE; @@ -45,7 +45,7 @@ initialize (void) if (kernel32 != NULL) { CreateHardLinkFunc = - (CreateHardLinkFuncType) GetProcAddress (kernel32, "CreateHardLinkA"); + (CreateHardLinkFuncType) GetProcAddress (kernel32, "CreateHardLinkA"); } initialized = TRUE; } @@ -103,39 +103,39 @@ link (const char *file1, const char *file2) * system. */ DWORD err = GetLastError (); switch (err) - { - case ERROR_ACCESS_DENIED: - errno = EACCES; - break; - - case ERROR_INVALID_FUNCTION: /* fs does not support hard links */ - errno = EPERM; - break; - - case ERROR_NOT_SAME_DEVICE: - errno = EXDEV; - break; - - case ERROR_PATH_NOT_FOUND: - case ERROR_FILE_NOT_FOUND: - errno = ENOENT; - break; - - case ERROR_INVALID_PARAMETER: - errno = ENAMETOOLONG; - break; - - case ERROR_TOO_MANY_LINKS: - errno = EMLINK; - break; - - case ERROR_ALREADY_EXISTS: - errno = EEXIST; - break; - - default: - errno = EIO; - } + { + case ERROR_ACCESS_DENIED: + errno = EACCES; + break; + + case ERROR_INVALID_FUNCTION: /* fs does not support hard links */ + errno = EPERM; + break; + + case ERROR_NOT_SAME_DEVICE: + errno = EXDEV; + break; + + case ERROR_PATH_NOT_FOUND: + case ERROR_FILE_NOT_FOUND: + errno = ENOENT; + break; + + case ERROR_INVALID_PARAMETER: + errno = ENAMETOOLONG; + break; + + case ERROR_TOO_MANY_LINKS: + errno = EMLINK; + break; + + case ERROR_ALREADY_EXISTS: + errno = EEXIST; + break; + + default: + errno = EIO; + } return -1; } diff --git a/lib/localcharset.c b/lib/localcharset.c index ee43e81b3..c8873b565 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -129,214 +129,214 @@ get_charset_aliases (void) char *file_name; /* Make it possible to override the charset.alias location. This is - necessary for running the testsuite before "make install". */ + necessary for running the testsuite before "make install". */ dir = getenv ("CHARSETALIASDIR"); if (dir == NULL || dir[0] == '\0') - dir = relocate (LIBDIR); + 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); - } + 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 = ""; + /* 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; - if (old_res_ptr != NULL) - 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); - } + { + 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; + if (old_res_ptr != NULL) + 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. */ + 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"; + "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. */ + 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". */ + "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"; + "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 WIN32_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. */ + 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"; + "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 @@ -380,34 +380,34 @@ locale_charset (void) locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } + { + 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; - } - } - } + { + /* 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; + } + } + } /* Woe32 has a function returning the locale's codepage as a number. */ sprintf (buf, "CP%u", GetACP ()); @@ -431,11 +431,11 @@ locale_charset (void) { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } + { + 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, @@ -467,7 +467,7 @@ locale_charset (void) { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); + locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { @@ -475,21 +475,21 @@ locale_charset (void) 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; - } - } + { + 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; @@ -498,12 +498,12 @@ locale_charset (void) { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) - codeset = ""; + codeset = ""; else - { - sprintf (buf, "CP%u", cp[0]); - codeset = buf; - } + { + sprintf (buf, "CP%u", cp[0]); + codeset = buf; + } } #endif @@ -517,10 +517,10 @@ locale_charset (void) *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 - || (aliases[0] == '*' && aliases[1] == '\0')) + || (aliases[0] == '*' && aliases[1] == '\0')) { - codeset = aliases + strlen (aliases) + 1; - break; + codeset = aliases + strlen (aliases) + 1; + break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret diff --git a/lib/localename.c b/lib/localename.c index 9f4c18191..c4273c3b6 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -784,7 +784,7 @@ gl_locale_name_canonicalize (char *name) MacOS X 10.3.8 function CFLocaleCreateCanonicalLocaleIdentifierFromString(). */ typedef struct { const char legacy[21+1]; const char unixy[5+1]; } - legacy_entry; + legacy_entry; static const legacy_entry legacy_table[] = { { "Afrikaans", "af" }, { "Albanian", "sq" }, @@ -922,7 +922,7 @@ gl_locale_name_canonicalize (char *name) /* Convert new-style locale names with language tags (ISO 639 and ISO 15924) to Unix (ISO 639 and ISO 3166) names. */ typedef struct { const char langtag[7+1]; const char unixy[12+1]; } - langtag_entry; + langtag_entry; static const langtag_entry langtag_table[] = { /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn". The default script for az on Unix is Latin. */ @@ -952,7 +952,7 @@ gl_locale_name_canonicalize (char *name) /* Convert script names (ISO 15924) to Unix conventions. See http://www.unicode.org/iso15924/iso15924-codes.html */ typedef struct { const char script[4+1]; const char unixy[9+1]; } - script_entry; + script_entry; static const script_entry script_table[] = { { "Arab", "arabic" }, { "Cyrl", "cyrillic" }, @@ -966,21 +966,21 @@ gl_locale_name_canonicalize (char *name) i1 = 0; i2 = sizeof (legacy_table) / sizeof (legacy_entry); while (i2 - i1 > 1) - { - /* At this point we know that if name occurs in legacy_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const legacy_entry *p = &legacy_table[i]; - if (strcmp (name, p->legacy) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if name occurs in legacy_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const legacy_entry *p = &legacy_table[i]; + if (strcmp (name, p->legacy) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name, legacy_table[i1].legacy) == 0) - { - strcpy (name, legacy_table[i1].unixy); - return; - } + { + strcpy (name, legacy_table[i1].unixy); + return; + } } /* Step 2: Convert using langtag_table and script_table. */ @@ -990,41 +990,41 @@ gl_locale_name_canonicalize (char *name) i1 = 0; i2 = sizeof (langtag_table) / sizeof (langtag_entry); while (i2 - i1 > 1) - { - /* At this point we know that if name occurs in langtag_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const langtag_entry *p = &langtag_table[i]; - if (strcmp (name, p->langtag) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if name occurs in langtag_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const langtag_entry *p = &langtag_table[i]; + if (strcmp (name, p->langtag) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name, langtag_table[i1].langtag) == 0) - { - strcpy (name, langtag_table[i1].unixy); - return; - } + { + strcpy (name, langtag_table[i1].unixy); + return; + } i1 = 0; i2 = sizeof (script_table) / sizeof (script_entry); while (i2 - i1 > 1) - { - /* At this point we know that if (name + 3) occurs in script_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const script_entry *p = &script_table[i]; - if (strcmp (name + 3, p->script) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if (name + 3) occurs in script_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const script_entry *p = &script_table[i]; + if (strcmp (name + 3, p->script) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name + 3, script_table[i1].script) == 0) - { - name[2] = '@'; - strcpy (name + 3, script_table[i1].unixy); - return; - } + { + name[2] = '@'; + strcpy (name + 3, script_table[i1].unixy); + return; + } } /* Step 3: Convert new-style dash to Unix underscore. */ @@ -1032,7 +1032,7 @@ gl_locale_name_canonicalize (char *name) char *p; for (p = name; *p != '\0'; p++) if (*p == '-') - *p = '_'; + *p = '_'; } } @@ -1058,19 +1058,19 @@ gl_locale_name_canonicalize (char *name) for (p = name; *p != '\0'; p++) if (*p == '-') { - *p = '_'; - p++; - for (; *p != '\0'; p++) - { - if (*p >= 'a' && *p <= 'z') - *p += 'A' - 'a'; - if (*p == '-') - { - *p = '\0'; - return; - } - } - return; + *p = '_'; + p++; + for (; *p != '\0'; p++) + { + if (*p >= 'a' && *p <= 'z') + *p += 'A' - 'a'; + if (*p == '-') + { + *p = '\0'; + return; + } + } + return; } } @@ -1087,15 +1087,15 @@ gl_locale_name_from_win32_LANGID (LANGID langid) static char namebuf[256]; /* Query the system's notion of locale name. - On Windows95/98/ME, GetLocaleInfoA returns some incorrect results. - But we don't need to support systems that are so old. */ + On Windows95/98/ME, GetLocaleInfoA returns some incorrect results. + But we don't need to support systems that are so old. */ if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME, - namebuf, sizeof (namebuf) - 1)) - { - /* Convert it to a Unix locale name. */ - gl_locale_name_canonicalize (namebuf); - return namebuf; - } + namebuf, sizeof (namebuf) - 1)) + { + /* Convert it to a Unix locale name. */ + gl_locale_name_canonicalize (namebuf); + return namebuf; + } } /* Internet Explorer has an LCID to RFC3066 name mapping stored in HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that @@ -1119,176 +1119,176 @@ gl_locale_name_from_win32_LANGID (LANGID langid) case LANG_ALBANIAN: return "sq_AL"; case LANG_AMHARIC: return "am_ET"; case LANG_ARABIC: - switch (sub) - { - case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; - case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; - case SUBLANG_ARABIC_EGYPT: return "ar_EG"; - case SUBLANG_ARABIC_LIBYA: return "ar_LY"; - case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; - case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; - case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; - case SUBLANG_ARABIC_OMAN: return "ar_OM"; - case SUBLANG_ARABIC_YEMEN: return "ar_YE"; - case SUBLANG_ARABIC_SYRIA: return "ar_SY"; - case SUBLANG_ARABIC_JORDAN: return "ar_JO"; - case SUBLANG_ARABIC_LEBANON: return "ar_LB"; - case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; - case SUBLANG_ARABIC_UAE: return "ar_AE"; - case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; - case SUBLANG_ARABIC_QATAR: return "ar_QA"; - } - return "ar"; + switch (sub) + { + case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; + case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; + case SUBLANG_ARABIC_EGYPT: return "ar_EG"; + case SUBLANG_ARABIC_LIBYA: return "ar_LY"; + case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; + case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; + case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; + case SUBLANG_ARABIC_OMAN: return "ar_OM"; + case SUBLANG_ARABIC_YEMEN: return "ar_YE"; + case SUBLANG_ARABIC_SYRIA: return "ar_SY"; + case SUBLANG_ARABIC_JORDAN: return "ar_JO"; + case SUBLANG_ARABIC_LEBANON: return "ar_LB"; + case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; + case SUBLANG_ARABIC_UAE: return "ar_AE"; + case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; + case SUBLANG_ARABIC_QATAR: return "ar_QA"; + } + return "ar"; case LANG_ARMENIAN: return "hy_AM"; case LANG_ASSAMESE: return "as_IN"; case LANG_AZERI: - switch (sub) - { - /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ - case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; - case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; - } - return "az"; + switch (sub) + { + /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ + case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; + case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; + } + return "az"; case LANG_BASQUE: - switch (sub) - { - case SUBLANG_DEFAULT: return "eu_ES"; - } - return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ + switch (sub) + { + case SUBLANG_DEFAULT: return "eu_ES"; + } + return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ case LANG_BELARUSIAN: return "be_BY"; case LANG_BENGALI: - switch (sub) - { - case SUBLANG_BENGALI_INDIA: return "bn_IN"; - case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; - } - return "bn"; + switch (sub) + { + case SUBLANG_BENGALI_INDIA: return "bn_IN"; + case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; + } + return "bn"; case LANG_BULGARIAN: return "bg_BG"; case LANG_BURMESE: return "my_MM"; case LANG_CAMBODIAN: return "km_KH"; case LANG_CATALAN: return "ca_ES"; case LANG_CHEROKEE: return "chr_US"; case LANG_CHINESE: - switch (sub) - { - case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW"; - case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN"; - case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; - case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; - case SUBLANG_CHINESE_MACAU: return "zh_MO"; - } - return "zh"; + switch (sub) + { + case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW"; + case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN"; + case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; + case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; + case SUBLANG_CHINESE_MACAU: return "zh_MO"; + } + return "zh"; case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN - * What used to be called Serbo-Croatian - * should really now be two separate - * languages because of political reasons. - * (Says tml, who knows nothing about Serbian - * or Croatian.) - * (I can feel those flames coming already.) - */ - switch (sub) - { - case SUBLANG_CROATIAN_CROATIA: return "hr_HR"; - case SUBLANG_SERBIAN_LATIN: return "sr_CS"; - case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; - case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA"; - case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; - case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic"; - } - return "hr"; + * What used to be called Serbo-Croatian + * should really now be two separate + * languages because of political reasons. + * (Says tml, who knows nothing about Serbian + * or Croatian.) + * (I can feel those flames coming already.) + */ + switch (sub) + { + case SUBLANG_CROATIAN_CROATIA: return "hr_HR"; + case SUBLANG_SERBIAN_LATIN: return "sr_CS"; + case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; + case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA"; + case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; + case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic"; + } + return "hr"; case LANG_CZECH: return "cs_CZ"; case LANG_DANISH: return "da_DK"; case LANG_DIVEHI: return "dv_MV"; case LANG_DUTCH: - switch (sub) - { - case SUBLANG_DUTCH: return "nl_NL"; - case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; - } - return "nl"; + switch (sub) + { + case SUBLANG_DUTCH: return "nl_NL"; + case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; + } + return "nl"; case LANG_EDO: return "bin_NG"; case LANG_ENGLISH: - switch (sub) - { - /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought - * English was the language spoken in England. - * Oh well. - */ - case SUBLANG_ENGLISH_US: return "en_US"; - case SUBLANG_ENGLISH_UK: return "en_GB"; - case SUBLANG_ENGLISH_AUS: return "en_AU"; - case SUBLANG_ENGLISH_CAN: return "en_CA"; - case SUBLANG_ENGLISH_NZ: return "en_NZ"; - case SUBLANG_ENGLISH_EIRE: return "en_IE"; - case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; - case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; - case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ - case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; - case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; - case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; - case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; - case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; - case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; - case SUBLANG_ENGLISH_INDIA: return "en_IN"; - case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; - case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; - } - return "en"; + switch (sub) + { + /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought + * English was the language spoken in England. + * Oh well. + */ + case SUBLANG_ENGLISH_US: return "en_US"; + case SUBLANG_ENGLISH_UK: return "en_GB"; + case SUBLANG_ENGLISH_AUS: return "en_AU"; + case SUBLANG_ENGLISH_CAN: return "en_CA"; + case SUBLANG_ENGLISH_NZ: return "en_NZ"; + case SUBLANG_ENGLISH_EIRE: return "en_IE"; + case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; + case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; + case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ + case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; + case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; + case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; + case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; + case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; + case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; + case SUBLANG_ENGLISH_INDIA: return "en_IN"; + case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; + case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; + } + return "en"; case LANG_ESTONIAN: return "et_EE"; case LANG_FAEROESE: return "fo_FO"; case LANG_FARSI: return "fa_IR"; case LANG_FINNISH: return "fi_FI"; case LANG_FRENCH: - switch (sub) - { - case SUBLANG_FRENCH: return "fr_FR"; - case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; - case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; - case SUBLANG_FRENCH_SWISS: return "fr_CH"; - case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; - case SUBLANG_FRENCH_MONACO: return "fr_MC"; - case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ - case SUBLANG_FRENCH_REUNION: return "fr_RE"; - case SUBLANG_FRENCH_CONGO: return "fr_CG"; - case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; - case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; - case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; - case SUBLANG_FRENCH_MALI: return "fr_ML"; - case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; - case SUBLANG_FRENCH_HAITI: return "fr_HT"; - } - return "fr"; + switch (sub) + { + case SUBLANG_FRENCH: return "fr_FR"; + case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; + case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; + case SUBLANG_FRENCH_SWISS: return "fr_CH"; + case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; + case SUBLANG_FRENCH_MONACO: return "fr_MC"; + case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ + case SUBLANG_FRENCH_REUNION: return "fr_RE"; + case SUBLANG_FRENCH_CONGO: return "fr_CG"; + case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; + case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; + case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; + case SUBLANG_FRENCH_MALI: return "fr_ML"; + case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; + case SUBLANG_FRENCH_HAITI: return "fr_HT"; + } + return "fr"; case LANG_FRISIAN: return "fy_NL"; case LANG_FULFULDE: - /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ - return "ff_NG"; + /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ + return "ff_NG"; case LANG_GAELIC: - switch (sub) - { - case 0x01: /* SCOTTISH */ return "gd_GB"; - case 0x02: /* IRISH */ return "ga_IE"; - } - return "C"; + switch (sub) + { + case 0x01: /* SCOTTISH */ return "gd_GB"; + case 0x02: /* IRISH */ return "ga_IE"; + } + return "C"; case LANG_GALICIAN: return "gl_ES"; case LANG_GEORGIAN: return "ka_GE"; case LANG_GERMAN: - switch (sub) - { - case SUBLANG_GERMAN: return "de_DE"; - case SUBLANG_GERMAN_SWISS: return "de_CH"; - case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; - case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; - case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; - } - return "de"; + switch (sub) + { + case SUBLANG_GERMAN: return "de_DE"; + case SUBLANG_GERMAN_SWISS: return "de_CH"; + case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; + case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; + case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; + } + return "de"; case LANG_GREEK: return "el_GR"; case LANG_GUARANI: return "gn_PY"; case LANG_GUJARATI: return "gu_IN"; case LANG_HAUSA: return "ha_NG"; case LANG_HAWAIIAN: - /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) - or Hawaii Creole English ("cpe_US", 600000 speakers)? */ - return "cpe_US"; + /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) + or Hawaii Creole English ("cpe_US", 600000 speakers)? */ + return "cpe_US"; case LANG_HEBREW: return "he_IL"; case LANG_HINDI: return "hi_IN"; case LANG_HUNGARIAN: return "hu_HU"; @@ -1298,26 +1298,26 @@ gl_locale_name_from_win32_LANGID (LANGID langid) case LANG_INDONESIAN: return "id_ID"; case LANG_INUKTITUT: return "iu_CA"; case LANG_ITALIAN: - switch (sub) - { - case SUBLANG_ITALIAN: return "it_IT"; - case SUBLANG_ITALIAN_SWISS: return "it_CH"; - } - return "it"; + switch (sub) + { + case SUBLANG_ITALIAN: return "it_IT"; + case SUBLANG_ITALIAN_SWISS: return "it_CH"; + } + return "it"; case LANG_JAPANESE: return "ja_JP"; case LANG_KANNADA: return "kn_IN"; case LANG_KANURI: return "kr_NG"; case LANG_KASHMIRI: - switch (sub) - { - case SUBLANG_DEFAULT: return "ks_PK"; - case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; - } - return "ks"; + switch (sub) + { + case SUBLANG_DEFAULT: return "ks_PK"; + case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; + } + return "ks"; case LANG_KAZAK: return "kk_KZ"; case LANG_KONKANI: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "kok_IN"; + /* FIXME: Adjust this when such locales appear on Unix. */ + return "kok_IN"; case LANG_KOREAN: return "ko_KR"; case LANG_KYRGYZ: return "ky_KG"; case LANG_LAO: return "lo_LA"; @@ -1326,207 +1326,207 @@ gl_locale_name_from_win32_LANGID (LANGID langid) case LANG_LITHUANIAN: return "lt_LT"; case LANG_MACEDONIAN: return "mk_MK"; case LANG_MALAY: - switch (sub) - { - case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; - case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; - } - return "ms"; + switch (sub) + { + case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; + case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; + } + return "ms"; case LANG_MALAYALAM: return "ml_IN"; case LANG_MALTESE: return "mt_MT"; case LANG_MANIPURI: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "mni_IN"; + /* FIXME: Adjust this when such locales appear on Unix. */ + return "mni_IN"; case LANG_MAORI: return "mi_NZ"; case LANG_MARATHI: return "mr_IN"; case LANG_MONGOLIAN: - switch (sub) - { - case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: return "mn_MN"; - case SUBLANG_MONGOLIAN_PRC: return "mn_CN"; - } - return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ + switch (sub) + { + case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: return "mn_MN"; + case SUBLANG_MONGOLIAN_PRC: return "mn_CN"; + } + return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ case LANG_NEPALI: - switch (sub) - { - case SUBLANG_DEFAULT: return "ne_NP"; - case SUBLANG_NEPALI_INDIA: return "ne_IN"; - } - return "ne"; + switch (sub) + { + case SUBLANG_DEFAULT: return "ne_NP"; + case SUBLANG_NEPALI_INDIA: return "ne_IN"; + } + return "ne"; case LANG_NORWEGIAN: - switch (sub) - { - case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; - case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; - } - return "no"; + switch (sub) + { + case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; + case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; + } + return "no"; case LANG_ORIYA: return "or_IN"; case LANG_OROMO: return "om_ET"; case LANG_PAPIAMENTU: return "pap_AN"; case LANG_PASHTO: - return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ + return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ case LANG_POLISH: return "pl_PL"; case LANG_PORTUGUESE: - switch (sub) - { - case SUBLANG_PORTUGUESE: return "pt_PT"; - /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. - Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ - case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; - } - return "pt"; + switch (sub) + { + case SUBLANG_PORTUGUESE: return "pt_PT"; + /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. + Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ + case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; + } + return "pt"; case LANG_PUNJABI: - switch (sub) - { - case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ - case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ - } - return "pa"; + switch (sub) + { + case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ + case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ + } + return "pa"; case LANG_QUECHUA: - switch (sub) - { - case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO"; - case SUBLANG_QUECHUA_ECUADOR: return "qu_EC"; - case SUBLANG_QUECHUA_PERU: return "qu_PE"; - } - return "qu"; + switch (sub) + { + case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO"; + case SUBLANG_QUECHUA_ECUADOR: return "qu_EC"; + case SUBLANG_QUECHUA_PERU: return "qu_PE"; + } + return "qu"; case LANG_RHAETO_ROMANCE: return "rm_CH"; case LANG_ROMANIAN: - switch (sub) - { - case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; - case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; - } - return "ro"; + switch (sub) + { + case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; + case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; + } + return "ro"; case LANG_RUSSIAN: - switch (sub) - { - case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU"; - case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD"; - } - return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ + switch (sub) + { + case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU"; + case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD"; + } + return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ case LANG_SAAMI: /* actually Northern Sami */ return "se_NO"; case LANG_SANSKRIT: return "sa_IN"; case LANG_SINDHI: - switch (sub) - { - case SUBLANG_SINDHI_INDIA: return "sd_IN"; - case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; - /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/ - } - return "sd"; + switch (sub) + { + case SUBLANG_SINDHI_INDIA: return "sd_IN"; + case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; + /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/ + } + return "sd"; case LANG_SINHALESE: return "si_LK"; case LANG_SLOVAK: return "sk_SK"; case LANG_SLOVENIAN: return "sl_SI"; case LANG_SOMALI: return "so_SO"; case LANG_SORBIAN: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "wen_DE"; + /* FIXME: Adjust this when such locales appear on Unix. */ + return "wen_DE"; case LANG_SOTHO: - /* calls - it "Sepedi"; according to - - - it's the same as Northern Sotho. */ - return "nso_ZA"; + /* calls + it "Sepedi"; according to + + + it's the same as Northern Sotho. */ + return "nso_ZA"; case LANG_SPANISH: - switch (sub) - { - case SUBLANG_SPANISH: return "es_ES"; - case SUBLANG_SPANISH_MEXICAN: return "es_MX"; - case SUBLANG_SPANISH_MODERN: - return "es_ES@modern"; /* not seen on Unix */ - case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; - case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; - case SUBLANG_SPANISH_PANAMA: return "es_PA"; - case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; - case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; - case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; - case SUBLANG_SPANISH_PERU: return "es_PE"; - case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; - case SUBLANG_SPANISH_ECUADOR: return "es_EC"; - case SUBLANG_SPANISH_CHILE: return "es_CL"; - case SUBLANG_SPANISH_URUGUAY: return "es_UY"; - case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; - case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; - case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; - case SUBLANG_SPANISH_HONDURAS: return "es_HN"; - case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; - case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; - case SUBLANG_SPANISH_US: return "es_US"; - } - return "es"; + switch (sub) + { + case SUBLANG_SPANISH: return "es_ES"; + case SUBLANG_SPANISH_MEXICAN: return "es_MX"; + case SUBLANG_SPANISH_MODERN: + return "es_ES@modern"; /* not seen on Unix */ + case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; + case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; + case SUBLANG_SPANISH_PANAMA: return "es_PA"; + case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; + case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; + case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; + case SUBLANG_SPANISH_PERU: return "es_PE"; + case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; + case SUBLANG_SPANISH_ECUADOR: return "es_EC"; + case SUBLANG_SPANISH_CHILE: return "es_CL"; + case SUBLANG_SPANISH_URUGUAY: return "es_UY"; + case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; + case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; + case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; + case SUBLANG_SPANISH_HONDURAS: return "es_HN"; + case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; + case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; + case SUBLANG_SPANISH_US: return "es_US"; + } + return "es"; case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */ case LANG_SWAHILI: return "sw_KE"; case LANG_SWEDISH: - switch (sub) - { - case SUBLANG_DEFAULT: return "sv_SE"; - case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; - } - return "sv"; + switch (sub) + { + case SUBLANG_DEFAULT: return "sv_SE"; + case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; + } + return "sv"; case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */ case LANG_TAGALOG: return "tl_PH"; case LANG_TAJIK: return "tg_TJ"; case LANG_TAMAZIGHT: - switch (sub) - { - /* FIXME: Adjust this when Tamazight locales appear on Unix. */ - case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; - case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin"; - } - return "ber_MA"; + switch (sub) + { + /* FIXME: Adjust this when Tamazight locales appear on Unix. */ + case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; + case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin"; + } + return "ber_MA"; case LANG_TAMIL: - switch (sub) - { - case SUBLANG_DEFAULT: return "ta_IN"; - } - return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ + switch (sub) + { + case SUBLANG_DEFAULT: return "ta_IN"; + } + return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ case LANG_TATAR: return "tt_RU"; case LANG_TELUGU: return "te_IN"; case LANG_THAI: return "th_TH"; case LANG_TIBETAN: - switch (sub) - { - case SUBLANG_TIBETAN_PRC: - /* Most Tibetans would not like "bo_CN". But Tibet does not yet - have a country code of its own. */ - return "bo"; - case SUBLANG_TIBETAN_BHUTAN: return "bo_BT"; - } - return "bo"; + switch (sub) + { + case SUBLANG_TIBETAN_PRC: + /* Most Tibetans would not like "bo_CN". But Tibet does not yet + have a country code of its own. */ + return "bo"; + case SUBLANG_TIBETAN_BHUTAN: return "bo_BT"; + } + return "bo"; case LANG_TIGRINYA: - switch (sub) - { - case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; - case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; - } - return "ti"; + switch (sub) + { + case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; + case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; + } + return "ti"; case LANG_TSONGA: return "ts_ZA"; case LANG_TSWANA: return "tn_BW"; case LANG_TURKISH: return "tr_TR"; case LANG_TURKMEN: return "tk_TM"; case LANG_UIGHUR: - switch (sub) - { - case SUBLANG_UIGHUR_PRC: return "ug_CN"; - } - return "ug"; + switch (sub) + { + case SUBLANG_UIGHUR_PRC: return "ug_CN"; + } + return "ug"; case LANG_UKRAINIAN: return "uk_UA"; case LANG_URDU: - switch (sub) - { - case SUBLANG_URDU_PAKISTAN: return "ur_PK"; - case SUBLANG_URDU_INDIA: return "ur_IN"; - } - return "ur"; + switch (sub) + { + case SUBLANG_URDU_PAKISTAN: return "ur_PK"; + case SUBLANG_URDU_INDIA: return "ur_IN"; + } + return "ur"; case LANG_UZBEK: - switch (sub) - { - case SUBLANG_UZBEK_LATIN: return "uz_UZ"; - case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; - } - return "uz"; + switch (sub) + { + case SUBLANG_UZBEK_LATIN: return "uz_UZ"; + case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; + } + return "uz"; case LANG_VENDA: return "ve_ZA"; case LANG_VIETNAMESE: return "vi_VN"; case LANG_WELSH: return "cy_GB"; @@ -1633,33 +1633,33 @@ gl_locale_name_default (void) if (cached_localename == NULL) { - char namebuf[256]; + char namebuf[256]; # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */ - CFLocaleRef locale = CFLocaleCopyCurrent (); - CFStringRef name = CFLocaleGetIdentifier (locale); + CFLocaleRef locale = CFLocaleCopyCurrent (); + CFStringRef name = CFLocaleGetIdentifier (locale); - if (CFStringGetCString (name, namebuf, sizeof(namebuf), - kCFStringEncodingASCII)) - { - gl_locale_name_canonicalize (namebuf); - cached_localename = strdup (namebuf); - } - CFRelease (locale); + if (CFStringGetCString (name, namebuf, sizeof(namebuf), + kCFStringEncodingASCII)) + { + gl_locale_name_canonicalize (namebuf); + cached_localename = strdup (namebuf); + } + CFRelease (locale); # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ - CFTypeRef value = - CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), - kCFPreferencesCurrentApplication); - if (value != NULL - && CFGetTypeID (value) == CFStringGetTypeID () - && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), - kCFStringEncodingASCII)) - { - gl_locale_name_canonicalize (namebuf); - cached_localename = strdup (namebuf); - } + CFTypeRef value = + CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), + kCFPreferencesCurrentApplication); + if (value != NULL + && CFGetTypeID (value) == CFStringGetTypeID () + && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), + kCFStringEncodingASCII)) + { + gl_locale_name_canonicalize (namebuf); + cached_localename = strdup (namebuf); + } # endif - if (cached_localename == NULL) - cached_localename = "C"; + if (cached_localename == NULL) + cached_localename = "C"; } return cached_localename; } diff --git a/lib/logl.c b/lib/logl.c index 52adaecc1..2b5141268 100644 --- a/lib/logl.c +++ b/lib/logl.c @@ -18,7 +18,7 @@ /* Specification. */ #include -/* logll.c +/* logll.c * * Natural logarithm for 128-bit long double precision. * @@ -239,17 +239,17 @@ logl(long double x) /* Series expansion of log(1+z). */ w = z * z; y = ((((((((((((l15 * z - + l14) * z - + l13) * z - + l12) * z - + l11) * z - + l10) * z - + l9) * z - + l8) * z - + l7) * z - + l6) * z - + l5) * z - + l4) * z + + l14) * z + + l13) * z + + l12) * z + + l11) * z + + l10) * z + + l9) * z + + l8) * z + + l7) * z + + l6) * z + + l5) * z + + l4) * z + l3) * z * w; y -= 0.5 * w; y += e * ln2b; /* Base 2 exponent offset times ln(2). */ diff --git a/lib/long-options.c b/lib/long-options.c index 0286bdf98..f4217a8bc 100644 --- a/lib/long-options.c +++ b/lib/long-options.c @@ -42,12 +42,12 @@ static struct option const long_options[] = void parse_long_options (int argc, - char **argv, - const char *command_name, - const char *package, - const char *version, - void (*usage_func) (int), - /* const char *author1, ...*/ ...) + char **argv, + const char *command_name, + const char *package, + const char *version, + void (*usage_func) (int), + /* const char *author1, ...*/ ...) { int c; int saved_opterr; @@ -61,22 +61,22 @@ parse_long_options (int argc, && (c = getopt_long (argc, argv, "+", long_options, NULL)) != -1) { switch (c) - { - case 'h': - (*usage_func) (EXIT_SUCCESS); - - case 'v': - { - va_list authors; - va_start (authors, usage_func); - version_etc_va (stdout, command_name, package, version, authors); - exit (0); - } - - default: - /* Don't process any other long-named options. */ - break; - } + { + case 'h': + (*usage_func) (EXIT_SUCCESS); + + case 'v': + { + va_list authors; + va_start (authors, usage_func); + version_etc_va (stdout, command_name, package, version, authors); + exit (0); + } + + default: + /* Don't process any other long-named options. */ + break; + } } /* Restore previous value. */ diff --git a/lib/long-options.h b/lib/long-options.h index 36ecb333c..37d76bdbd 100644 --- a/lib/long-options.h +++ b/lib/long-options.h @@ -17,9 +17,9 @@ /* Written by Jim Meyering. */ void parse_long_options (int _argc, - char **_argv, - const char *_command_name, - const char *_package, - const char *_version, - void (*_usage) (int), - /* const char *author1, ...*/ ...); + char **_argv, + const char *_command_name, + const char *_package, + const char *_version, + void (*_usage) (int), + /* const char *author1, ...*/ ...); diff --git a/lib/malloca.c b/lib/malloca.c index 4145bf6df..b8635abc2 100644 --- a/lib/malloca.c +++ b/lib/malloca.c @@ -74,21 +74,21 @@ mmalloca (size_t n) char *p = (char *) malloc (nplus); if (p != NULL) - { - size_t slot; + { + size_t slot; - p += HEADER_SIZE; + p += HEADER_SIZE; - /* Put a magic number into the indicator word. */ - ((int *) p)[-1] = MAGIC_NUMBER; + /* Put a magic number into the indicator word. */ + ((int *) p)[-1] = MAGIC_NUMBER; - /* Enter p into the hash table. */ - slot = (unsigned long) p % HASH_TABLE_SIZE; - ((struct header *) (p - HEADER_SIZE))->next = mmalloca_results[slot]; - mmalloca_results[slot] = p; + /* Enter p into the hash table. */ + slot = (unsigned long) p % HASH_TABLE_SIZE; + ((struct header *) (p - HEADER_SIZE))->next = mmalloca_results[slot]; + mmalloca_results[slot] = p; - return p; - } + return p; + } } /* Out of memory. */ return NULL; @@ -109,28 +109,28 @@ freea (void *p) 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. */ + 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 = (unsigned long) p % HASH_TABLE_SIZE; - void **chain = &mmalloca_results[slot]; - for (; *chain != NULL;) - { - if (*chain == p) - { - /* Found it. Remove it from the hash table and free it. */ - char *p_begin = (char *) p - HEADER_SIZE; - *chain = ((struct header *) p_begin)->next; - free (p_begin); - return; - } - chain = &((struct header *) ((char *) *chain - HEADER_SIZE))->next; - } - } + { + /* Looks like a mmalloca() result. To see whether it really is one, + perform a lookup in the hash table. */ + size_t slot = (unsigned long) p % HASH_TABLE_SIZE; + void **chain = &mmalloca_results[slot]; + for (; *chain != NULL;) + { + if (*chain == p) + { + /* Found it. Remove it from the hash table and free it. */ + char *p_begin = (char *) p - HEADER_SIZE; + *chain = ((struct header *) p_begin)->next; + free (p_begin); + return; + } + chain = &((struct header *) ((char *) *chain - HEADER_SIZE))->next; + } + } /* At this point, we know it was not a mmalloca() result. */ } } diff --git a/lib/malloca.h b/lib/malloca.h index 5bb2d4734..a5f904b74 100644 --- a/lib/malloca.h +++ b/lib/malloca.h @@ -54,7 +54,7 @@ extern "C" { the function returns. Upon failure, it returns NULL. */ #if HAVE_ALLOCA # define malloca(N) \ - ((N) < 4032 - sa_increment \ + ((N) < 4032 - sa_increment \ ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \ : mmalloca (N)) #else @@ -122,10 +122,10 @@ enum 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) + | (sa_alignment_longlong - 1) #endif - | (sa_alignment_longdouble - 1) - ) + 1, + | (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 diff --git a/lib/math.in.h b/lib/math.in.h index 1778e6e91..05ce40859 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -524,31 +524,31 @@ extern int gl_signbitl (long double arg); # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf # define gl_signbitf_OPTIMIZED_MACRO # define gl_signbitf(arg) \ - ({ union { float _value; \ + ({ union { float _value; \ unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ - } _m; \ - _m._value = (arg); \ - (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \ + } _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; \ + ({ union { double _value; \ unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ - } _m; \ - _m._value = (arg); \ - (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \ + } _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; \ + ({ union { long double _value; \ unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ - } _m; \ - _m._value = (arg); \ - (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \ + } _m; \ + _m._value = (arg); \ + (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \ }) # endif # endif diff --git a/lib/mbchar.c b/lib/mbchar.c index 6fa14b09c..7f75a34cc 100644 --- a/lib/mbchar.c +++ b/lib/mbchar.c @@ -25,10 +25,10 @@ /* Bit table of characters in the ISO C "basic character set". */ const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] = { - 0x00001a00, /* '\t' '\v' '\f' */ - 0xffffffef, /* ' '...'#' '%'...'?' */ - 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ - 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ + 0x00001a00, /* '\t' '\v' '\f' */ + 0xffffffef, /* ' '...'#' '%'...'?' */ + 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ + 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ /* The remaining bits are 0. */ }; diff --git a/lib/mbchar.h b/lib/mbchar.h index 5d47a0a9c..1a9d321f1 100644 --- a/lib/mbchar.h +++ b/lib/mbchar.h @@ -114,31 +114,31 @@ Here are the function prototypes of the macros. - extern const char * mb_ptr (const mbchar_t mbc); - extern size_t mb_len (const mbchar_t mbc); - extern bool mb_iseq (const mbchar_t mbc, char sc); - extern bool mb_isnul (const mbchar_t mbc); - extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); - extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_isalnum (const mbchar_t mbc); - extern bool mb_isalpha (const mbchar_t mbc); - extern bool mb_isascii (const mbchar_t mbc); - extern bool mb_isblank (const mbchar_t mbc); - extern bool mb_iscntrl (const mbchar_t mbc); - extern bool mb_isdigit (const mbchar_t mbc); - extern bool mb_isgraph (const mbchar_t mbc); - extern bool mb_islower (const mbchar_t mbc); - extern bool mb_isprint (const mbchar_t mbc); - extern bool mb_ispunct (const mbchar_t mbc); - extern bool mb_isspace (const mbchar_t mbc); - extern bool mb_isupper (const mbchar_t mbc); - extern bool mb_isxdigit (const mbchar_t mbc); - extern int mb_width (const mbchar_t mbc); - extern void mb_putc (const mbchar_t mbc, FILE *stream); + extern const char * mb_ptr (const mbchar_t mbc); + extern size_t mb_len (const mbchar_t mbc); + extern bool mb_iseq (const mbchar_t mbc, char sc); + extern bool mb_isnul (const mbchar_t mbc); + extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_isalnum (const mbchar_t mbc); + extern bool mb_isalpha (const mbchar_t mbc); + extern bool mb_isascii (const mbchar_t mbc); + extern bool mb_isblank (const mbchar_t mbc); + extern bool mb_iscntrl (const mbchar_t mbc); + extern bool mb_isdigit (const mbchar_t mbc); + extern bool mb_isgraph (const mbchar_t mbc); + extern bool mb_islower (const mbchar_t mbc); + extern bool mb_isprint (const mbchar_t mbc); + extern bool mb_ispunct (const mbchar_t mbc); + extern bool mb_isspace (const mbchar_t mbc); + extern bool mb_isupper (const mbchar_t mbc); + extern bool mb_isxdigit (const mbchar_t mbc); + extern int mb_width (const mbchar_t mbc); + extern void mb_putc (const mbchar_t mbc, FILE *stream); extern void mb_setascii (mbchar_t *new, char sc); - extern void mb_copy (mbchar_t *new, const mbchar_t *old); + extern void mb_copy (mbchar_t *new, const mbchar_t *old); */ #ifndef _MBCHAR_H @@ -160,10 +160,10 @@ struct mbchar { - const char *ptr; /* pointer to current character */ - size_t bytes; /* number of bytes of current character, > 0 */ - bool wc_valid; /* true if wc is a valid wide character */ - wchar_t wc; /* if wc_valid: the current character */ + const char *ptr; /* pointer to current character */ + size_t bytes; /* number of bytes of current character, > 0 */ + bool wc_valid; /* true if wc is a valid wide character */ + wchar_t wc; /* if wc_valid: the current character */ char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ }; @@ -180,38 +180,38 @@ typedef struct mbchar mbchar_t; #define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) #define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) #define mb_cmp(mbc1, mbc2) \ - ((mbc1).wc_valid \ - ? ((mbc2).wc_valid \ - ? (int) (mbc1).wc - (int) (mbc2).wc \ - : -1) \ - : ((mbc2).wc_valid \ - ? 1 \ - : (mbc1).bytes == (mbc2).bytes \ - ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ - : (mbc1).bytes < (mbc2).bytes \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) (mbc1).wc - (int) (mbc2).wc \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) #define mb_casecmp(mbc1, mbc2) \ - ((mbc1).wc_valid \ - ? ((mbc2).wc_valid \ - ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ - : -1) \ - : ((mbc2).wc_valid \ - ? 1 \ - : (mbc1).bytes == (mbc2).bytes \ - ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ - : (mbc1).bytes < (mbc2).bytes \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) #define mb_equal(mbc1, mbc2) \ - ((mbc1).wc_valid && (mbc2).wc_valid \ - ? (mbc1).wc == (mbc2).wc \ - : (mbc1).bytes == (mbc2).bytes \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? (mbc1).wc == (mbc2).wc \ + : (mbc1).bytes == (mbc2).bytes \ && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) #define mb_caseequal(mbc1, mbc2) \ - ((mbc1).wc_valid && (mbc2).wc_valid \ - ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ - : (mbc1).bytes == (mbc2).bytes \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ + : (mbc1).bytes == (mbc2).bytes \ && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) /* , classification. */ @@ -308,7 +308,7 @@ static inline bool is_basic (char c) { return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) - & 1; + & 1; } #else diff --git a/lib/mbfile.h b/lib/mbfile.h index 92c3fb783..c535107ef 100644 --- a/lib/mbfile.h +++ b/lib/mbfile.h @@ -39,9 +39,9 @@ Here are the function prototypes of the macros. - extern void mbf_init (mb_file_t mbf, FILE *stream); - extern void mbf_getc (mbf_char_t mbc, mb_file_t mbf); - extern bool mb_iseof (const mbf_char_t mbc); + extern void mbf_init (mb_file_t mbf, FILE *stream); + extern void mbf_getc (mbf_char_t mbc, mb_file_t mbf); + extern bool mb_iseof (const mbf_char_t mbc); */ #ifndef _MBFILE_H @@ -95,10 +95,10 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) { int c = getc (mbf->fp); if (c == EOF) - { - mbf->eof_seen = true; - goto eof; - } + { + mbf->eof_seen = true; + goto eof; + } mbf->buf[0] = (unsigned char) c; mbf->bufcount++; } @@ -107,8 +107,8 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) if (mbf->bufcount == 1 && mbsinit (&mbf->state) && is_basic (mbf->buf[0])) { /* These characters are part of the basic character set. ISO C 99 - guarantees that their wide character code is identical to their - char code. */ + guarantees that their wide character code is identical to their + char code. */ mbc->wc = mbc->buf[0] = mbf->buf[0]; mbc->wc_valid = true; mbc->ptr = &mbc->buf[0]; @@ -123,67 +123,67 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) for (;;) { /* We don't know whether the 'mbrtowc' function updates the state when - it returns -2, - this is the ISO C 99 and glibc-2.2 behaviour - or - not - amended ANSI C, glibc-2.1 and Solaris 2.7 behaviour. We - don't have an autoconf test for this, yet. - The new behaviour would allow us to feed the bytes one by one into - mbrtowc. But the old behaviour forces us to feed all bytes since - the end of the last character into mbrtowc. Since we want to retry - with more bytes when mbrtowc returns -2, we must backup the state - before calling mbrtowc, because implementations with the new - behaviour will clobber it. */ + it returns -2, - this is the ISO C 99 and glibc-2.2 behaviour - or + not - amended ANSI C, glibc-2.1 and Solaris 2.7 behaviour. We + don't have an autoconf test for this, yet. + The new behaviour would allow us to feed the bytes one by one into + mbrtowc. But the old behaviour forces us to feed all bytes since + the end of the last character into mbrtowc. Since we want to retry + with more bytes when mbrtowc returns -2, we must backup the state + before calling mbrtowc, because implementations with the new + behaviour will clobber it. */ mbstate_t backup_state = mbf->state; bytes = mbrtowc (&mbc->wc, &mbf->buf[0], mbf->bufcount, &mbf->state); if (bytes == (size_t) -1) - { - /* An invalid multibyte sequence was encountered. */ - /* Return a single byte. */ - bytes = 1; - mbc->wc_valid = false; - break; - } + { + /* An invalid multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } else if (bytes == (size_t) -2) - { - /* An incomplete multibyte character. */ - mbf->state = backup_state; - if (mbf->bufcount == MBCHAR_BUF_SIZE) - { - /* An overlong incomplete multibyte sequence was encountered. */ - /* Return a single byte. */ - bytes = 1; - mbc->wc_valid = false; - break; - } - else - { - /* Read one more byte and retry mbrtowc. */ - int c = getc (mbf->fp); - if (c == EOF) - { - /* An incomplete multibyte character at the end. */ - mbf->eof_seen = true; - bytes = mbf->bufcount; - mbc->wc_valid = false; - break; - } - mbf->buf[mbf->bufcount] = (unsigned char) c; - mbf->bufcount++; - } + { + /* An incomplete multibyte character. */ + mbf->state = backup_state; + if (mbf->bufcount == MBCHAR_BUF_SIZE) + { + /* An overlong incomplete multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } + else + { + /* Read one more byte and retry mbrtowc. */ + int c = getc (mbf->fp); + if (c == EOF) + { + /* An incomplete multibyte character at the end. */ + mbf->eof_seen = true; + bytes = mbf->bufcount; + mbc->wc_valid = false; + break; + } + mbf->buf[mbf->bufcount] = (unsigned char) c; + mbf->bufcount++; + } } else - { - if (bytes == 0) - { - /* A null wide character was encountered. */ - bytes = 1; - assert (mbf->buf[0] == '\0'); - assert (mbc->wc == 0); - } - mbc->wc_valid = true; - break; - } + { + if (bytes == 0) + { + /* A null wide character was encountered. */ + bytes = 1; + assert (mbf->buf[0] == '\0'); + assert (mbc->wc == 0); + } + mbc->wc_valid = true; + break; + } } /* Return the multibyte sequence mbf->buf[0..bytes-1]. */ @@ -199,10 +199,10 @@ mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) char *p = &mbf->buf[0]; do - { - *p = *(p + bytes); - p++; - } + { + *p = *(p + bytes); + p++; + } while (--count > 0); } return; @@ -226,11 +226,11 @@ typedef struct mbfile_multi mb_file_t; typedef mbchar_t mbf_char_t; -#define mbf_init(mbf, stream) \ - ((mbf).fp = (stream), \ - (mbf).eof_seen = false, \ - (mbf).have_pushback = false, \ - memset (&(mbf).state, '\0', sizeof (mbstate_t)), \ +#define mbf_init(mbf, stream) \ + ((mbf).fp = (stream), \ + (mbf).eof_seen = false, \ + (mbf).have_pushback = false, \ + memset (&(mbf).state, '\0', sizeof (mbstate_t)), \ (mbf).bufcount = 0) #define mbf_getc(mbc, mbf) mbfile_multi_getc (&(mbc), &(mbf)) diff --git a/lib/mbiter.h b/lib/mbiter.h index b274da747..97594f4fc 100644 --- a/lib/mbiter.h +++ b/lib/mbiter.h @@ -69,14 +69,14 @@ Here are the function prototypes of the macros. - extern void mbi_init (mbi_iterator_t iter, - const char *startptr, size_t length); - extern bool mbi_avail (mbi_iterator_t iter); - extern void mbi_advance (mbi_iterator_t iter); - extern mbchar_t mbi_cur (mbi_iterator_t iter); - extern const char * mbi_cur_ptr (mbi_iterator_t iter); - extern void mbi_reloc (mbi_iterator_t iter, ptrdiff_t ptrdiff); - extern void mbi_copy (mbi_iterator_t *new, const mbi_iterator_t *old); + extern void mbi_init (mbi_iterator_t iter, + const char *startptr, size_t length); + extern bool mbi_avail (mbi_iterator_t iter); + extern void mbi_advance (mbi_iterator_t iter); + extern mbchar_t mbi_cur (mbi_iterator_t iter); + extern const char * mbi_cur_ptr (mbi_iterator_t iter); + extern void mbi_reloc (mbi_iterator_t iter, ptrdiff_t ptrdiff); + extern void mbi_copy (mbi_iterator_t *new, const mbi_iterator_t *old); */ #ifndef _MBITER_H @@ -99,17 +99,17 @@ struct mbiter_multi { - const char *limit; /* pointer to end of string */ - bool in_shift; /* true if next byte may not be interpreted as ASCII */ - mbstate_t state; /* if in_shift: current shift state */ - bool next_done; /* true if mbi_avail has already filled the following */ - struct mbchar cur; /* the current character: - const char *cur.ptr pointer to current character - The following are only valid after mbi_avail. - size_t cur.bytes number of bytes of current character - bool cur.wc_valid true if wc is a valid wide character - wchar_t cur.wc if wc_valid: the current character - */ + const char *limit; /* pointer to end of string */ + bool in_shift; /* true if next byte may not be interpreted as ASCII */ + mbstate_t state; /* if in_shift: current shift state */ + bool next_done; /* true if mbi_avail has already filled the following */ + struct mbchar cur; /* the current character: + const char *cur.ptr pointer to current character + The following are only valid after mbi_avail. + size_t cur.bytes number of bytes of current character + bool cur.wc_valid true if wc is a valid wide character + wchar_t cur.wc if wc_valid: the current character + */ }; static inline void @@ -123,8 +123,8 @@ mbiter_multi_next (struct mbiter_multi *iter) if (is_basic (*iter->cur.ptr)) { /* These characters are part of the basic character set. ISO C 99 - guarantees that their wide character code is identical to their - char code. */ + guarantees that their wide character code is identical to their + char code. */ iter->cur.bytes = 1; iter->cur.wc = *iter->cur.ptr; iter->cur.wc_valid = true; @@ -135,39 +135,39 @@ mbiter_multi_next (struct mbiter_multi *iter) iter->in_shift = true; with_shift: iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr, - iter->limit - iter->cur.ptr, &iter->state); + iter->limit - iter->cur.ptr, &iter->state); if (iter->cur.bytes == (size_t) -1) - { - /* An invalid multibyte sequence was encountered. */ - iter->cur.bytes = 1; - iter->cur.wc_valid = false; - /* Whether to set iter->in_shift = false and reset iter->state - or not is not very important; the string is bogus anyway. */ - } + { + /* An invalid multibyte sequence was encountered. */ + iter->cur.bytes = 1; + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not very important; the string is bogus anyway. */ + } else if (iter->cur.bytes == (size_t) -2) - { - /* An incomplete multibyte character at the end. */ - iter->cur.bytes = iter->limit - iter->cur.ptr; - iter->cur.wc_valid = false; - /* Whether to set iter->in_shift = false and reset iter->state - or not is not important; the string end is reached anyway. */ - } + { + /* An incomplete multibyte character at the end. */ + iter->cur.bytes = iter->limit - iter->cur.ptr; + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not important; the string end is reached anyway. */ + } else - { - if (iter->cur.bytes == 0) - { - /* A null wide character was encountered. */ - iter->cur.bytes = 1; - assert (*iter->cur.ptr == '\0'); - assert (iter->cur.wc == 0); - } - iter->cur.wc_valid = true; - - /* When in the initial state, we can go back treating ASCII - characters more quickly. */ - if (mbsinit (&iter->state)) - iter->in_shift = false; - } + { + if (iter->cur.bytes == 0) + { + /* A null wide character was encountered. */ + iter->cur.bytes = 1; + assert (*iter->cur.ptr == '\0'); + assert (iter->cur.wc == 0); + } + iter->cur.wc_valid = true; + + /* When in the initial state, we can go back treating ASCII + characters more quickly. */ + if (mbsinit (&iter->state)) + iter->in_shift = false; + } } iter->next_done = true; } diff --git a/lib/mbmemcasecmp.c b/lib/mbmemcasecmp.c index c2d115d43..5e9f44b78 100644 --- a/lib/mbmemcasecmp.c +++ b/lib/mbmemcasecmp.c @@ -44,21 +44,21 @@ mbmemcasecmp (const char *s1, size_t n1, const char *s2, size_t n2) mbi_init (iter2, s2, n2); while (mbi_avail (iter1) && mbi_avail (iter2)) - { - int cmp = mb_casecmp (mbi_cur (iter1), mbi_cur (iter2)); + { + int cmp = mb_casecmp (mbi_cur (iter1), mbi_cur (iter2)); - if (cmp != 0) - return cmp; + if (cmp != 0) + return cmp; - mbi_advance (iter1); - mbi_advance (iter2); - } + mbi_advance (iter1); + mbi_advance (iter2); + } if (mbi_avail (iter1)) - /* s2 terminated before s1. */ - return 1; + /* s2 terminated before s1. */ + return 1; if (mbi_avail (iter2)) - /* s1 terminated before s2. */ - return -1; + /* s1 terminated before s2. */ + return -1; return 0; } else @@ -69,28 +69,28 @@ mbmemcasecmp (const char *s1, size_t n1, const char *s2, size_t n2) const unsigned char *p2 = (const unsigned char *) s2; while (p1 < s1_end && p2 < s2_end) - { - unsigned char c1 = TOLOWER (*p1); - unsigned char c2 = TOLOWER (*p2); - if (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); - } - ++p1; - ++p2; - } + { + unsigned char c1 = TOLOWER (*p1); + unsigned char c2 = TOLOWER (*p2); + if (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); + } + ++p1; + ++p2; + } if (p1 < s1_end) - /* s2 terminated before s1. */ - return 1; + /* s2 terminated before s1. */ + return 1; if (p2 < s2_end) - /* s1 terminated before s2. */ - return -1; + /* s1 terminated before s2. */ + return -1; return 0; } } diff --git a/lib/mbmemcasecoll.c b/lib/mbmemcasecoll.c index ed0a84f3f..366045383 100644 --- a/lib/mbmemcasecoll.c +++ b/lib/mbmemcasecoll.c @@ -43,7 +43,7 @@ result as a multibyte character sequence in OUTBUF. */ static size_t apply_towlower (const char *inbuf, size_t inbufsize, - char *outbuf, size_t outbufsize) + char *outbuf, size_t outbufsize) { char *outbuf_orig = outbuf; size_t remaining; @@ -58,37 +58,37 @@ apply_towlower (const char *inbuf, size_t inbufsize, memset (&state, '\0', sizeof (mbstate_t)); n1 = mbrtowc (&wc1, inbuf, remaining, &state); if (n1 == (size_t)(-2)) - break; + break; if (n1 != (size_t)(-1)) - { - wint_t wc2 = towlower (wc1); - - if (wc2 != wc1) - { - size_t n2; - - memset (&state, '\0', sizeof (mbstate_t)); - n2 = wcrtomb (outbuf, wc2, &state); - if (n2 != (size_t)(-1)) - { - /* Store the translated multibyte character. */ - inbuf += n1; - remaining -= n1; - outbuf += n2; - continue; - } - } - - /* Nothing to translate. */ - memcpy (outbuf, inbuf, n1); - inbuf += n1; - remaining -= n1; - outbuf += n1; - continue; - } + { + wint_t wc2 = towlower (wc1); + + if (wc2 != wc1) + { + size_t n2; + + memset (&state, '\0', sizeof (mbstate_t)); + n2 = wcrtomb (outbuf, wc2, &state); + if (n2 != (size_t)(-1)) + { + /* Store the translated multibyte character. */ + inbuf += n1; + remaining -= n1; + outbuf += n2; + continue; + } + } + + /* Nothing to translate. */ + memcpy (outbuf, inbuf, n1); + inbuf += n1; + remaining -= n1; + outbuf += n1; + continue; + } /* Invalid multibyte character on input. - Copy one byte without modification. */ + Copy one byte without modification. */ *outbuf++ = *inbuf++; remaining -= 1; } @@ -123,7 +123,7 @@ apply_tolower (const char *inbuf, char *outbuf, size_t bufsize) int mbmemcasecoll (const char *s1, size_t s1len, const char *s2, size_t s2len, - bool hard_LC_COLLATE) + bool hard_LC_COLLATE) { char *t1; size_t t1len; @@ -135,7 +135,7 @@ mbmemcasecoll (const char *s1, size_t s1len, const char *s2, size_t s2len, if (MB_CUR_MAX > 1) { /* Application of towlower grows each character by a factor 2 - at most. */ + at most. */ t1len = 2 * s1len; t2len = 2 * s2len; } diff --git a/lib/mbmemcasecoll.h b/lib/mbmemcasecoll.h index ed774fb3b..301dabb08 100644 --- a/lib/mbmemcasecoll.h +++ b/lib/mbmemcasecoll.h @@ -47,8 +47,8 @@ extern "C" { different lengths! */ extern int mbmemcasecoll (const char *s1, size_t s1len, - const char *s2, size_t s2len, - bool hard_LC_COLLATE); + const char *s2, size_t s2len, + bool hard_LC_COLLATE); #ifdef __cplusplus diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c index 0fec5f1c9..7cf624a75 100644 --- a/lib/mbrtowc.c +++ b/lib/mbrtowc.c @@ -63,30 +63,30 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) switch (nstate) { case 0: - p = s; - m = n; - break; + p = s; + m = n; + break; case 3: - buf[2] = pstate[3]; - /*FALLTHROUGH*/ + buf[2] = pstate[3]; + /*FALLTHROUGH*/ case 2: - buf[1] = pstate[2]; - /*FALLTHROUGH*/ + 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; + 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); + errno = EINVAL; + return (size_t)(-1); } /* Here m > 0. */ @@ -99,208 +99,208 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) 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; - } + { + 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. */ + 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; + goto invalid; /* Here MB_CUR_MAX > 1 and 0 < m < 4. */ { - const char *encoding = locale_charset (); - - if (STREQ (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 (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 (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) - || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) - || STREQ (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 (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 (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 (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; + const char *encoding = locale_charset (); + + if (STREQ (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 (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 (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) + || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) + || STREQ (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 (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 (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 (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 (); + 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); @@ -341,25 +341,25 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) 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); + /* 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 @@ -371,10 +371,10 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) if (ret != (size_t)(-1) && ret != (size_t)(-2)) { - if (pwc != NULL) - *pwc = wc; - if (wc == 0) - ret = 0; + if (pwc != NULL) + *pwc = wc; + if (wc == 0) + ret = 0; } return ret; } diff --git a/lib/mbscasecmp.c b/lib/mbscasecmp.c index 7fdfdeb3d..4dda10447 100644 --- a/lib/mbscasecmp.c +++ b/lib/mbscasecmp.c @@ -51,21 +51,21 @@ mbscasecmp (const char *s1, const char *s2) mbui_init (iter2, s2); while (mbui_avail (iter1) && mbui_avail (iter2)) - { - int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); + { + int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); - if (cmp != 0) - return cmp; + if (cmp != 0) + return cmp; - mbui_advance (iter1); - mbui_advance (iter2); - } + mbui_advance (iter1); + mbui_advance (iter2); + } if (mbui_avail (iter1)) - /* s2 terminated before s1. */ - return 1; + /* s2 terminated before s1. */ + return 1; if (mbui_avail (iter2)) - /* s1 terminated before s2. */ - return -1; + /* s1 terminated before s2. */ + return -1; return 0; } else @@ -75,24 +75,24 @@ mbscasecmp (const char *s1, const char *s2) unsigned char c1, c2; do - { - c1 = TOLOWER (*p1); - c2 = TOLOWER (*p2); + { + c1 = TOLOWER (*p1); + c2 = TOLOWER (*p2); - if (c1 == '\0') - break; + if (c1 == '\0') + break; - ++p1; - ++p2; - } + ++p1; + ++p2; + } while (c1 == c2); if (UCHAR_MAX <= INT_MAX) - return c1 - c2; + 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); + /* 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/lib/mbscasestr.c b/lib/mbscasestr.c index 7a3466356..31512ff22 100644 --- a/lib/mbscasestr.c +++ b/lib/mbscasestr.c @@ -40,7 +40,7 @@ Return false if it was aborted because not enough memory was available. */ static bool knuth_morris_pratt_multibyte (const char *haystack, const char *needle, - const char **resultp) + const char **resultp) { size_t m = mbslen (needle); mbchar_t *needle_mbchars; @@ -61,9 +61,9 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle, j = 0; for (mbui_init (iter, needle); mbui_avail (iter); mbui_advance (iter), j++) { - mb_copy (&needle_mbchars[j], &mbui_cur (iter)); - if (needle_mbchars[j].wc_valid) - needle_mbchars[j].wc = towlower (needle_mbchars[j].wc); + mb_copy (&needle_mbchars[j], &mbui_cur (iter)); + if (needle_mbchars[j].wc_valid) + needle_mbchars[j].wc = towlower (needle_mbchars[j].wc); } } @@ -91,46 +91,46 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle, for (i = 2; i < m; i++) { - /* Here: j = i-1 - table[i-1]. - The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold - for x < table[i-1], by induction. - Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ - mbchar_t *b = &needle_mbchars[i - 1]; - - for (;;) - { - /* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x] - is known to hold for x < i-1-j. - Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ - if (mb_equal (*b, needle_mbchars[j])) - { - /* Set table[i] := i-1-j. */ - table[i] = i - ++j; - break; - } - /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds - for x = i-1-j, because - needle[i-1] != needle[j] = needle[i-1-x]. */ - if (j == 0) - { - /* The inequality holds for all possible x. */ - table[i] = i; - break; - } - /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds - for i-1-j < x < i-1-j+table[j], because for these x: - needle[x..i-2] - = needle[x-(i-1-j)..j-1] - != needle[0..j-1-(x-(i-1-j))] (by definition of table[j]) - = needle[0..i-2-x], - hence needle[x..i-1] != needle[0..i-1-x]. - Furthermore - needle[i-1-j+table[j]..i-2] - = needle[table[j]..j-1] - = needle[0..j-1-table[j]] (by definition of table[j]). */ - j = j - table[j]; - } - /* Here: j = i - table[i]. */ + /* Here: j = i-1 - table[i-1]. + The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold + for x < table[i-1], by induction. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + mbchar_t *b = &needle_mbchars[i - 1]; + + for (;;) + { + /* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x] + is known to hold for x < i-1-j. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + if (mb_equal (*b, needle_mbchars[j])) + { + /* Set table[i] := i-1-j. */ + table[i] = i - ++j; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for x = i-1-j, because + needle[i-1] != needle[j] = needle[i-1-x]. */ + if (j == 0) + { + /* The inequality holds for all possible x. */ + table[i] = i; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for i-1-j < x < i-1-j+table[j], because for these x: + needle[x..i-2] + = needle[x-(i-1-j)..j-1] + != needle[0..j-1-(x-(i-1-j))] (by definition of table[j]) + = needle[0..i-2-x], + hence needle[x..i-1] != needle[0..i-1-x]. + Furthermore + needle[i-1-j+table[j]..i-2] + = needle[table[j]..j-1] + = needle[0..j-1-table[j]] (by definition of table[j]). */ + j = j - table[j]; + } + /* Here: j = i - table[i]. */ } } @@ -147,42 +147,42 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle, /* Invariant: phaystack = rhaystack + j. */ while (mbui_avail (phaystack)) { - mbchar_t c; - - mb_copy (&c, &mbui_cur (phaystack)); - if (c.wc_valid) - c.wc = towlower (c.wc); - if (mb_equal (needle_mbchars[j], c)) - { - j++; - mbui_advance (phaystack); - if (j == m) - { - /* The entire needle has been found. */ - *resultp = mbui_cur_ptr (rhaystack); - break; - } - } - else if (j > 0) - { - /* Found a match of needle[0..j-1], mismatch at needle[j]. */ - size_t count = table[j]; - j -= count; - for (; count > 0; count--) - { - if (!mbui_avail (rhaystack)) - abort (); - mbui_advance (rhaystack); - } - } - else - { - /* Found a mismatch at needle[0] already. */ - if (!mbui_avail (rhaystack)) - abort (); - mbui_advance (rhaystack); - mbui_advance (phaystack); - } + mbchar_t c; + + mb_copy (&c, &mbui_cur (phaystack)); + if (c.wc_valid) + c.wc = towlower (c.wc); + if (mb_equal (needle_mbchars[j], c)) + { + j++; + mbui_advance (phaystack); + if (j == m) + { + /* The entire needle has been found. */ + *resultp = mbui_cur_ptr (rhaystack); + break; + } + } + else if (j > 0) + { + /* Found a match of needle[0..j-1], mismatch at needle[j]. */ + size_t count = table[j]; + j -= count; + for (; count > 0; count--) + { + if (!mbui_avail (rhaystack)) + abort (); + mbui_advance (rhaystack); + } + } + else + { + /* Found a mismatch at needle[0] already. */ + if (!mbui_avail (rhaystack)) + abort (); + mbui_advance (rhaystack); + mbui_advance (phaystack); + } } } @@ -208,202 +208,202 @@ mbscasestr (const char *haystack, const char *needle) mbui_init (iter_needle, needle); if (mbui_avail (iter_needle)) - { - /* Minimizing the worst-case complexity: - Let n = mbslen(haystack), m = mbslen(needle). - The naïve algorithm is O(n*m) worst-case. - The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a - memory allocation. - To achieve linear complexity and yet amortize the cost of the - memory allocation, we activate the Knuth-Morris-Pratt algorithm - only once the naïve algorithm has already run for some time; more - precisely, when - - the outer loop count is >= 10, - - the average number of comparisons per outer loop is >= 5, - - the total number of comparisons is >= m. - But we try it only once. If the memory allocation attempt failed, - we don't retry it. */ - bool try_kmp = true; - size_t outer_loop_count = 0; - size_t comparison_count = 0; - size_t last_ccount = 0; /* last comparison count */ - mbui_iterator_t iter_needle_last_ccount; /* = needle + last_ccount */ - - mbchar_t b; - mbui_iterator_t iter_haystack; - - mbui_init (iter_needle_last_ccount, needle); - - mb_copy (&b, &mbui_cur (iter_needle)); - if (b.wc_valid) - b.wc = towlower (b.wc); - - mbui_init (iter_haystack, haystack); - for (;; mbui_advance (iter_haystack)) - { - mbchar_t c; - - if (!mbui_avail (iter_haystack)) - /* No match. */ - return NULL; - - /* See whether it's advisable to use an asymptotically faster - algorithm. */ - if (try_kmp - && outer_loop_count >= 10 - && comparison_count >= 5 * outer_loop_count) - { - /* See if needle + comparison_count now reaches the end of - needle. */ - size_t count = comparison_count - last_ccount; - for (; - count > 0 && mbui_avail (iter_needle_last_ccount); - count--) - mbui_advance (iter_needle_last_ccount); - last_ccount = comparison_count; - if (!mbui_avail (iter_needle_last_ccount)) - { - /* Try the Knuth-Morris-Pratt algorithm. */ - const char *result; - bool success = - knuth_morris_pratt_multibyte (haystack, needle, - &result); - if (success) - return (char *) result; - try_kmp = false; - } - } - - outer_loop_count++; - comparison_count++; - mb_copy (&c, &mbui_cur (iter_haystack)); - if (c.wc_valid) - c.wc = towlower (c.wc); - if (mb_equal (c, b)) - /* The first character matches. */ - { - mbui_iterator_t rhaystack; - mbui_iterator_t rneedle; - - memcpy (&rhaystack, &iter_haystack, sizeof (mbui_iterator_t)); - mbui_advance (rhaystack); - - mbui_init (rneedle, needle); - if (!mbui_avail (rneedle)) - abort (); - mbui_advance (rneedle); - - for (;; mbui_advance (rhaystack), mbui_advance (rneedle)) - { - if (!mbui_avail (rneedle)) - /* Found a match. */ - return (char *) mbui_cur_ptr (iter_haystack); - if (!mbui_avail (rhaystack)) - /* No match. */ - return NULL; - comparison_count++; - if (!mb_caseequal (mbui_cur (rhaystack), - mbui_cur (rneedle))) - /* Nothing in this round. */ - break; - } - } - } - } + { + /* Minimizing the worst-case complexity: + Let n = mbslen(haystack), m = mbslen(needle). + The naïve algorithm is O(n*m) worst-case. + The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a + memory allocation. + To achieve linear complexity and yet amortize the cost of the + memory allocation, we activate the Knuth-Morris-Pratt algorithm + only once the naïve algorithm has already run for some time; more + precisely, when + - the outer loop count is >= 10, + - the average number of comparisons per outer loop is >= 5, + - the total number of comparisons is >= m. + But we try it only once. If the memory allocation attempt failed, + we don't retry it. */ + bool try_kmp = true; + size_t outer_loop_count = 0; + size_t comparison_count = 0; + size_t last_ccount = 0; /* last comparison count */ + mbui_iterator_t iter_needle_last_ccount; /* = needle + last_ccount */ + + mbchar_t b; + mbui_iterator_t iter_haystack; + + mbui_init (iter_needle_last_ccount, needle); + + mb_copy (&b, &mbui_cur (iter_needle)); + if (b.wc_valid) + b.wc = towlower (b.wc); + + mbui_init (iter_haystack, haystack); + for (;; mbui_advance (iter_haystack)) + { + mbchar_t c; + + if (!mbui_avail (iter_haystack)) + /* No match. */ + return NULL; + + /* See whether it's advisable to use an asymptotically faster + algorithm. */ + if (try_kmp + && outer_loop_count >= 10 + && comparison_count >= 5 * outer_loop_count) + { + /* See if needle + comparison_count now reaches the end of + needle. */ + size_t count = comparison_count - last_ccount; + for (; + count > 0 && mbui_avail (iter_needle_last_ccount); + count--) + mbui_advance (iter_needle_last_ccount); + last_ccount = comparison_count; + if (!mbui_avail (iter_needle_last_ccount)) + { + /* Try the Knuth-Morris-Pratt algorithm. */ + const char *result; + bool success = + knuth_morris_pratt_multibyte (haystack, needle, + &result); + if (success) + return (char *) result; + try_kmp = false; + } + } + + outer_loop_count++; + comparison_count++; + mb_copy (&c, &mbui_cur (iter_haystack)); + if (c.wc_valid) + c.wc = towlower (c.wc); + if (mb_equal (c, b)) + /* The first character matches. */ + { + mbui_iterator_t rhaystack; + mbui_iterator_t rneedle; + + memcpy (&rhaystack, &iter_haystack, sizeof (mbui_iterator_t)); + mbui_advance (rhaystack); + + mbui_init (rneedle, needle); + if (!mbui_avail (rneedle)) + abort (); + mbui_advance (rneedle); + + for (;; mbui_advance (rhaystack), mbui_advance (rneedle)) + { + if (!mbui_avail (rneedle)) + /* Found a match. */ + return (char *) mbui_cur_ptr (iter_haystack); + if (!mbui_avail (rhaystack)) + /* No match. */ + return NULL; + comparison_count++; + if (!mb_caseequal (mbui_cur (rhaystack), + mbui_cur (rneedle))) + /* Nothing in this round. */ + break; + } + } + } + } else - return (char *) haystack; + return (char *) haystack; } else { if (*needle != '\0') - { - /* Minimizing the worst-case complexity: - Let n = strlen(haystack), m = strlen(needle). - The naïve algorithm is O(n*m) worst-case. - The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a - memory allocation. - To achieve linear complexity and yet amortize the cost of the - memory allocation, we activate the Knuth-Morris-Pratt algorithm - only once the naïve algorithm has already run for some time; more - precisely, when - - the outer loop count is >= 10, - - the average number of comparisons per outer loop is >= 5, - - the total number of comparisons is >= m. - But we try it only once. If the memory allocation attempt failed, - we don't retry it. */ - bool try_kmp = true; - size_t outer_loop_count = 0; - size_t comparison_count = 0; - size_t last_ccount = 0; /* last comparison count */ - const char *needle_last_ccount = needle; /* = needle + last_ccount */ - - /* Speed up the following searches of needle by caching its first - character. */ - unsigned char b = TOLOWER ((unsigned char) *needle); - - needle++; - for (;; haystack++) - { - if (*haystack == '\0') - /* No match. */ - return NULL; - - /* See whether it's advisable to use an asymptotically faster - algorithm. */ - if (try_kmp - && outer_loop_count >= 10 - && comparison_count >= 5 * outer_loop_count) - { - /* See if needle + comparison_count now reaches the end of - needle. */ - if (needle_last_ccount != NULL) - { - needle_last_ccount += - strnlen (needle_last_ccount, - comparison_count - last_ccount); - if (*needle_last_ccount == '\0') - needle_last_ccount = NULL; - last_ccount = comparison_count; - } - if (needle_last_ccount == NULL) - { - /* Try the Knuth-Morris-Pratt algorithm. */ - const char *result; - bool success = - knuth_morris_pratt_unibyte (haystack, needle - 1, - &result); - if (success) - return (char *) result; - try_kmp = false; - } - } - - outer_loop_count++; - comparison_count++; - if (TOLOWER ((unsigned char) *haystack) == b) - /* The first character matches. */ - { - const char *rhaystack = haystack + 1; - const char *rneedle = needle; - - for (;; rhaystack++, rneedle++) - { - if (*rneedle == '\0') - /* Found a match. */ - return (char *) haystack; - if (*rhaystack == '\0') - /* No match. */ - return NULL; - comparison_count++; - if (TOLOWER ((unsigned char) *rhaystack) - != TOLOWER ((unsigned char) *rneedle)) - /* Nothing in this round. */ - break; - } - } - } - } + { + /* Minimizing the worst-case complexity: + Let n = strlen(haystack), m = strlen(needle). + The naïve algorithm is O(n*m) worst-case. + The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a + memory allocation. + To achieve linear complexity and yet amortize the cost of the + memory allocation, we activate the Knuth-Morris-Pratt algorithm + only once the naïve algorithm has already run for some time; more + precisely, when + - the outer loop count is >= 10, + - the average number of comparisons per outer loop is >= 5, + - the total number of comparisons is >= m. + But we try it only once. If the memory allocation attempt failed, + we don't retry it. */ + bool try_kmp = true; + size_t outer_loop_count = 0; + size_t comparison_count = 0; + size_t last_ccount = 0; /* last comparison count */ + const char *needle_last_ccount = needle; /* = needle + last_ccount */ + + /* Speed up the following searches of needle by caching its first + character. */ + unsigned char b = TOLOWER ((unsigned char) *needle); + + needle++; + for (;; haystack++) + { + if (*haystack == '\0') + /* No match. */ + return NULL; + + /* See whether it's advisable to use an asymptotically faster + algorithm. */ + if (try_kmp + && outer_loop_count >= 10 + && comparison_count >= 5 * outer_loop_count) + { + /* See if needle + comparison_count now reaches the end of + needle. */ + if (needle_last_ccount != NULL) + { + needle_last_ccount += + strnlen (needle_last_ccount, + comparison_count - last_ccount); + if (*needle_last_ccount == '\0') + needle_last_ccount = NULL; + last_ccount = comparison_count; + } + if (needle_last_ccount == NULL) + { + /* Try the Knuth-Morris-Pratt algorithm. */ + const char *result; + bool success = + knuth_morris_pratt_unibyte (haystack, needle - 1, + &result); + if (success) + return (char *) result; + try_kmp = false; + } + } + + outer_loop_count++; + comparison_count++; + if (TOLOWER ((unsigned char) *haystack) == b) + /* The first character matches. */ + { + const char *rhaystack = haystack + 1; + const char *rneedle = needle; + + for (;; rhaystack++, rneedle++) + { + if (*rneedle == '\0') + /* Found a match. */ + return (char *) haystack; + if (*rhaystack == '\0') + /* No match. */ + return NULL; + comparison_count++; + if (TOLOWER ((unsigned char) *rhaystack) + != TOLOWER ((unsigned char) *rneedle)) + /* Nothing in this round. */ + break; + } + } + } + } else - return (char *) haystack; + return (char *) haystack; } } diff --git a/lib/mbschr.c b/lib/mbschr.c index ec1ebac05..eb047cf35 100644 --- a/lib/mbschr.c +++ b/lib/mbschr.c @@ -29,20 +29,20 @@ mbschr (const char *string, int c) { if (MB_CUR_MAX > 1 /* Optimization: We know that ASCII characters < 0x30 don't occur as - part of multibyte characters longer than 1 byte. Hence, if c < 0x30, - the faster unibyte loop can be used. */ + part of multibyte characters longer than 1 byte. Hence, if c < 0x30, + the faster unibyte loop can be used. */ && (unsigned char) c >= 0x30) { mbui_iterator_t iter; for (mbui_init (iter, string);; mbui_advance (iter)) - { - if (!mbui_avail (iter)) - goto notfound; - if (mb_len (mbui_cur (iter)) == 1 - && (unsigned char) * mbui_cur_ptr (iter) == (unsigned char) c) - break; - } + { + if (!mbui_avail (iter)) + goto notfound; + if (mb_len (mbui_cur (iter)) == 1 + && (unsigned char) * mbui_cur_ptr (iter) == (unsigned char) c) + break; + } return (char *) mbui_cur_ptr (iter); notfound: return NULL; diff --git a/lib/mbscspn.c b/lib/mbscspn.c index 6d3fe674b..47064480d 100644 --- a/lib/mbscspn.c +++ b/lib/mbscspn.c @@ -43,23 +43,23 @@ mbscspn (const char *string, const char *accept) mbui_iterator_t iter; for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter)) - { - if (mb_len (mbui_cur (iter)) == 1) - { - if (mbschr (accept, * mbui_cur_ptr (iter))) - goto found; - } - else - { - mbui_iterator_t aiter; + { + if (mb_len (mbui_cur (iter)) == 1) + { + if (mbschr (accept, * mbui_cur_ptr (iter))) + goto found; + } + else + { + mbui_iterator_t aiter; - for (mbui_init (aiter, accept); - mbui_avail (aiter); - mbui_advance (aiter)) - if (mb_equal (mbui_cur (aiter), mbui_cur (iter))) - goto found; - } - } + for (mbui_init (aiter, accept); + mbui_avail (aiter); + mbui_advance (aiter)) + if (mb_equal (mbui_cur (aiter), mbui_cur (iter))) + goto found; + } + } found: return mbui_cur_ptr (iter) - string; } diff --git a/lib/mbslen.c b/lib/mbslen.c index 2dd6ea8bb..21e8d736a 100644 --- a/lib/mbslen.c +++ b/lib/mbslen.c @@ -35,7 +35,7 @@ mbslen (const char *string) count = 0; for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter)) - count++; + count++; return count; } diff --git a/lib/mbsncasecmp.c b/lib/mbsncasecmp.c index 4c8c5a55c..e9b3ecd16 100644 --- a/lib/mbsncasecmp.c +++ b/lib/mbsncasecmp.c @@ -53,24 +53,24 @@ mbsncasecmp (const char *s1, const char *s2, size_t n) mbui_init (iter2, s2); while (mbui_avail (iter1) && mbui_avail (iter2)) - { - int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); + { + int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); - if (cmp != 0) - return cmp; + if (cmp != 0) + return cmp; - if (--n == 0) - return 0; + if (--n == 0) + return 0; - mbui_advance (iter1); - mbui_advance (iter2); - } + mbui_advance (iter1); + mbui_advance (iter2); + } if (mbui_avail (iter1)) - /* s2 terminated before s1 and n. */ - return 1; + /* s2 terminated before s1 and n. */ + return 1; if (mbui_avail (iter2)) - /* s1 terminated before s2 and n. */ - return -1; + /* s1 terminated before s2 and n. */ + return -1; return 0; } else @@ -80,20 +80,20 @@ mbsncasecmp (const char *s1, const char *s2, size_t n) unsigned char c1, c2; for (; ; p1++, p2++) - { - c1 = TOLOWER (*p1); - c2 = TOLOWER (*p2); + { + c1 = TOLOWER (*p1); + c2 = TOLOWER (*p2); - if (--n == 0 || c1 == '\0' || c1 != c2) - break; - } + if (--n == 0 || c1 == '\0' || c1 != c2) + break; + } if (UCHAR_MAX <= INT_MAX) - return c1 - c2; + 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); + /* 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/lib/mbsnlen.c b/lib/mbsnlen.c index 78c751f35..b0a00bf19 100644 --- a/lib/mbsnlen.c +++ b/lib/mbsnlen.c @@ -36,7 +36,7 @@ mbsnlen (const char *string, size_t len) count = 0; for (mbi_init (iter, string, len); mbi_avail (iter); mbi_advance (iter)) - count++; + count++; return count; } diff --git a/lib/mbsnrtowcs.c b/lib/mbsnrtowcs.c index 57db98d29..99a365083 100644 --- a/lib/mbsnrtowcs.c +++ b/lib/mbsnrtowcs.c @@ -40,94 +40,94 @@ mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate if (dest != NULL) { - wchar_t *destptr = dest; - - for (; srclen > 0 && len > 0; destptr++, len--) - { - size_t src_avail; - size_t ret; - - /* An optimized variant of - src_avail = strnlen1 (src, MIN (srclen, MB_LEN_MAX)); */ - if (srclen == 1 || src[0] == '\0') - src_avail = 1; - else if (srclen == 2 || src[1] == '\0') - src_avail = 2; - else if (srclen == 3 || src[2] == '\0') - src_avail = 3; - else if (MB_LEN_MAX <= 4 || srclen == 4 || src[3] == '\0') - src_avail = 4; - else - src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4); - - /* Parse the next multibyte character. */ - ret = mbrtowc (destptr, src, src_avail, ps); - - if (ret == (size_t)(-2)) - /* Encountered a multibyte character that extends past a '\0' byte - or that is longer than MB_LEN_MAX bytes. Cannot happen. */ - abort (); - - if (ret == (size_t)(-1)) - goto bad_input; - if (ret == 0) - { - src = NULL; - /* Here mbsinit (ps). */ - break; - } - src += ret; - srclen -= ret; - } - - *srcp = src; - return destptr - dest; + wchar_t *destptr = dest; + + for (; srclen > 0 && len > 0; destptr++, len--) + { + size_t src_avail; + size_t ret; + + /* An optimized variant of + src_avail = strnlen1 (src, MIN (srclen, MB_LEN_MAX)); */ + if (srclen == 1 || src[0] == '\0') + src_avail = 1; + else if (srclen == 2 || src[1] == '\0') + src_avail = 2; + else if (srclen == 3 || src[2] == '\0') + src_avail = 3; + else if (MB_LEN_MAX <= 4 || srclen == 4 || src[3] == '\0') + src_avail = 4; + else + src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4); + + /* Parse the next multibyte character. */ + ret = mbrtowc (destptr, src, src_avail, ps); + + if (ret == (size_t)(-2)) + /* Encountered a multibyte character that extends past a '\0' byte + or that is longer than MB_LEN_MAX bytes. Cannot happen. */ + abort (); + + if (ret == (size_t)(-1)) + goto bad_input; + if (ret == 0) + { + src = NULL; + /* Here mbsinit (ps). */ + break; + } + src += ret; + srclen -= ret; + } + + *srcp = src; + return destptr - dest; } else { - /* Ignore dest and len, don't store *srcp at the end, and - don't clobber *ps. */ - mbstate_t state = *ps; - size_t totalcount = 0; - - for (; srclen > 0; totalcount++) - { - size_t src_avail; - size_t ret; - - /* An optimized variant of - src_avail = strnlen1 (src, MIN (srclen, MB_LEN_MAX)); */ - if (srclen == 1 || src[0] == '\0') - src_avail = 1; - else if (srclen == 2 || src[1] == '\0') - src_avail = 2; - else if (srclen == 3 || src[2] == '\0') - src_avail = 3; - else if (MB_LEN_MAX <= 4 || srclen == 4 || src[3] == '\0') - src_avail = 4; - else - src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4); - - /* Parse the next multibyte character. */ - ret = mbrtowc (NULL, src, src_avail, &state); - - if (ret == (size_t)(-2)) - /* Encountered a multibyte character that extends past a '\0' byte - or that is longer than MB_LEN_MAX bytes. Cannot happen. */ - abort (); - - if (ret == (size_t)(-1)) - goto bad_input2; - if (ret == 0) - { - /* Here mbsinit (&state). */ - break; - } - src += ret; - srclen -= ret; - } - - return totalcount; + /* Ignore dest and len, don't store *srcp at the end, and + don't clobber *ps. */ + mbstate_t state = *ps; + size_t totalcount = 0; + + for (; srclen > 0; totalcount++) + { + size_t src_avail; + size_t ret; + + /* An optimized variant of + src_avail = strnlen1 (src, MIN (srclen, MB_LEN_MAX)); */ + if (srclen == 1 || src[0] == '\0') + src_avail = 1; + else if (srclen == 2 || src[1] == '\0') + src_avail = 2; + else if (srclen == 3 || src[2] == '\0') + src_avail = 3; + else if (MB_LEN_MAX <= 4 || srclen == 4 || src[3] == '\0') + src_avail = 4; + else + src_avail = 4 + strnlen1 (src + 4, MIN (srclen, MB_LEN_MAX) - 4); + + /* Parse the next multibyte character. */ + ret = mbrtowc (NULL, src, src_avail, &state); + + if (ret == (size_t)(-2)) + /* Encountered a multibyte character that extends past a '\0' byte + or that is longer than MB_LEN_MAX bytes. Cannot happen. */ + abort (); + + if (ret == (size_t)(-1)) + goto bad_input2; + if (ret == 0) + { + /* Here mbsinit (&state). */ + break; + } + src += ret; + srclen -= ret; + } + + return totalcount; } bad_input: diff --git a/lib/mbspbrk.c b/lib/mbspbrk.c index bf56d5a1e..b9aeeecd9 100644 --- a/lib/mbspbrk.c +++ b/lib/mbspbrk.c @@ -39,23 +39,23 @@ mbspbrk (const char *string, const char *accept) mbui_iterator_t iter; for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter)) - { - if (mb_len (mbui_cur (iter)) == 1) - { - if (mbschr (accept, * mbui_cur_ptr (iter))) - return (char *) mbui_cur_ptr (iter); - } - else - { - mbui_iterator_t aiter; - - for (mbui_init (aiter, accept); - mbui_avail (aiter); - mbui_advance (aiter)) - if (mb_equal (mbui_cur (aiter), mbui_cur (iter))) - return (char *) mbui_cur_ptr (iter); - } - } + { + if (mb_len (mbui_cur (iter)) == 1) + { + if (mbschr (accept, * mbui_cur_ptr (iter))) + return (char *) mbui_cur_ptr (iter); + } + else + { + mbui_iterator_t aiter; + + for (mbui_init (aiter, accept); + mbui_avail (aiter); + mbui_advance (aiter)) + if (mb_equal (mbui_cur (aiter), mbui_cur (iter))) + return (char *) mbui_cur_ptr (iter); + } + } return NULL; } else diff --git a/lib/mbspcasecmp.c b/lib/mbspcasecmp.c index 7cde9b76e..b503c89e4 100644 --- a/lib/mbspcasecmp.c +++ b/lib/mbspcasecmp.c @@ -54,21 +54,21 @@ mbspcasecmp (const char *string, const char *prefix) mbui_init (iter2, prefix); while (mbui_avail (iter1) && mbui_avail (iter2)) - { - int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); + { + int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2)); - if (cmp != 0) - return NULL; + if (cmp != 0) + return NULL; - mbui_advance (iter1); - mbui_advance (iter2); - } + mbui_advance (iter1); + mbui_advance (iter2); + } if (!mbui_avail (iter2)) - /* PREFIX equals STRING or is terminated before STRING. */ - return (char *) mbui_cur_ptr (iter1); + /* PREFIX equals STRING or is terminated before STRING. */ + return (char *) mbui_cur_ptr (iter1); else - /* STRING terminated before PREFIX. */ - return NULL; + /* STRING terminated before PREFIX. */ + return NULL; } else { @@ -77,19 +77,19 @@ mbspcasecmp (const char *string, const char *prefix) unsigned char c1, c2; for (; ; p1++, p2++) - { - c1 = TOLOWER (*p1); - c2 = TOLOWER (*p2); + { + c1 = TOLOWER (*p1); + c2 = TOLOWER (*p2); - if (c2 == '\0' || c1 != c2) - break; - } + if (c2 == '\0' || c1 != c2) + break; + } if (c2 == '\0') - /* PREFIX equals STRING or is terminated before STRING. */ - return (char *) p1; + /* PREFIX equals STRING or is terminated before STRING. */ + return (char *) p1; else - /* STRING terminated before PREFIX. */ - return NULL; + /* STRING terminated before PREFIX. */ + return NULL; } } diff --git a/lib/mbsrchr.c b/lib/mbsrchr.c index 087904dec..367656f5c 100644 --- a/lib/mbsrchr.c +++ b/lib/mbsrchr.c @@ -29,19 +29,19 @@ mbsrchr (const char *string, int c) { if (MB_CUR_MAX > 1 /* Optimization: We know that ASCII characters < 0x30 don't occur as - part of multibyte characters longer than 1 byte. Hence, if c < 0x30, - the faster unibyte loop can be used. */ + part of multibyte characters longer than 1 byte. Hence, if c < 0x30, + the faster unibyte loop can be used. */ && (unsigned char) c >= 0x30) { const char *result = NULL; mbui_iterator_t iter; for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter)) - { - if (mb_len (mbui_cur (iter)) == 1 - && (unsigned char) * mbui_cur_ptr (iter) == (unsigned char) c) - result = mbui_cur_ptr (iter); - } + { + if (mb_len (mbui_cur (iter)) == 1 + && (unsigned char) * mbui_cur_ptr (iter) == (unsigned char) c) + result = mbui_cur_ptr (iter); + } return (char *) result; } else diff --git a/lib/mbsrtowcs.c b/lib/mbsrtowcs.c index ea6a01872..b31356ced 100644 --- a/lib/mbsrtowcs.c +++ b/lib/mbsrtowcs.c @@ -39,92 +39,92 @@ mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) if (dest != NULL) { - wchar_t *destptr = dest; - - for (; len > 0; destptr++, len--) - { - size_t src_avail; - size_t ret; - - /* An optimized variant of - src_avail = strnlen1 (src, MB_LEN_MAX); */ - if (src[0] == '\0') - src_avail = 1; - else if (src[1] == '\0') - src_avail = 2; - else if (src[2] == '\0') - src_avail = 3; - else if (MB_LEN_MAX <= 4 || src[3] == '\0') - src_avail = 4; - else - src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4); - - /* Parse the next multibyte character. */ - ret = mbrtowc (destptr, src, src_avail, ps); - - if (ret == (size_t)(-2)) - /* Encountered a multibyte character that extends past a '\0' byte - or that is longer than MB_LEN_MAX bytes. Cannot happen. */ - abort (); - - if (ret == (size_t)(-1)) - goto bad_input; - if (ret == 0) - { - src = NULL; - /* Here mbsinit (ps). */ - break; - } - src += ret; - } - - *srcp = src; - return destptr - dest; + wchar_t *destptr = dest; + + for (; len > 0; destptr++, len--) + { + size_t src_avail; + size_t ret; + + /* An optimized variant of + src_avail = strnlen1 (src, MB_LEN_MAX); */ + if (src[0] == '\0') + src_avail = 1; + else if (src[1] == '\0') + src_avail = 2; + else if (src[2] == '\0') + src_avail = 3; + else if (MB_LEN_MAX <= 4 || src[3] == '\0') + src_avail = 4; + else + src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4); + + /* Parse the next multibyte character. */ + ret = mbrtowc (destptr, src, src_avail, ps); + + if (ret == (size_t)(-2)) + /* Encountered a multibyte character that extends past a '\0' byte + or that is longer than MB_LEN_MAX bytes. Cannot happen. */ + abort (); + + if (ret == (size_t)(-1)) + goto bad_input; + if (ret == 0) + { + src = NULL; + /* Here mbsinit (ps). */ + break; + } + src += ret; + } + + *srcp = src; + return destptr - dest; } else { - /* Ignore dest and len, don't store *srcp at the end, and - don't clobber *ps. */ - mbstate_t state = *ps; - size_t totalcount = 0; - - for (;; totalcount++) - { - size_t src_avail; - size_t ret; - - /* An optimized variant of - src_avail = strnlen1 (src, MB_LEN_MAX); */ - if (src[0] == '\0') - src_avail = 1; - else if (src[1] == '\0') - src_avail = 2; - else if (src[2] == '\0') - src_avail = 3; - else if (MB_LEN_MAX <= 4 || src[3] == '\0') - src_avail = 4; - else - src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4); - - /* Parse the next multibyte character. */ - ret = mbrtowc (NULL, src, src_avail, &state); - - if (ret == (size_t)(-2)) - /* Encountered a multibyte character that extends past a '\0' byte - or that is longer than MB_LEN_MAX bytes. Cannot happen. */ - abort (); - - if (ret == (size_t)(-1)) - goto bad_input2; - if (ret == 0) - { - /* Here mbsinit (&state). */ - break; - } - src += ret; - } - - return totalcount; + /* Ignore dest and len, don't store *srcp at the end, and + don't clobber *ps. */ + mbstate_t state = *ps; + size_t totalcount = 0; + + for (;; totalcount++) + { + size_t src_avail; + size_t ret; + + /* An optimized variant of + src_avail = strnlen1 (src, MB_LEN_MAX); */ + if (src[0] == '\0') + src_avail = 1; + else if (src[1] == '\0') + src_avail = 2; + else if (src[2] == '\0') + src_avail = 3; + else if (MB_LEN_MAX <= 4 || src[3] == '\0') + src_avail = 4; + else + src_avail = 4 + strnlen1 (src + 4, MB_LEN_MAX - 4); + + /* Parse the next multibyte character. */ + ret = mbrtowc (NULL, src, src_avail, &state); + + if (ret == (size_t)(-2)) + /* Encountered a multibyte character that extends past a '\0' byte + or that is longer than MB_LEN_MAX bytes. Cannot happen. */ + abort (); + + if (ret == (size_t)(-1)) + goto bad_input2; + if (ret == 0) + { + /* Here mbsinit (&state). */ + break; + } + src += ret; + } + + return totalcount; } bad_input: diff --git a/lib/mbssep.c b/lib/mbssep.c index 3a9b530ee..6081cc8b2 100644 --- a/lib/mbssep.c +++ b/lib/mbssep.c @@ -31,30 +31,30 @@ mbssep (char **stringp, const char *delim) char *ptr; if (start == NULL) - return NULL; + return NULL; /* No need to optimize the cases of 0 or 1 delimiters specially, - since mbspbrk already optimizes them. */ + since mbspbrk already optimizes them. */ ptr = mbspbrk (start, delim); if (ptr == NULL) - { - *stringp = NULL; - return start; - } + { + *stringp = NULL; + return start; + } else - { - mbui_iterator_t iter; - - mbui_init (iter, ptr); - if (!mbui_avail (iter)) - abort (); - mbui_advance (iter); - *ptr = '\0'; - *stringp = (char *) mbui_cur_ptr (iter); - return start; - } + { + mbui_iterator_t iter; + + mbui_init (iter, ptr); + if (!mbui_avail (iter)) + abort (); + mbui_advance (iter); + *ptr = '\0'; + *stringp = (char *) mbui_cur_ptr (iter); + return start; + } } else return strsep (stringp, delim); diff --git a/lib/mbsspn.c b/lib/mbsspn.c index 3ef41ca1b..40f33d3fe 100644 --- a/lib/mbsspn.c +++ b/lib/mbsspn.c @@ -37,24 +37,24 @@ mbsspn (const char *string, const char *reject) unsigned char uc = (unsigned char) reject[0]; if (MB_CUR_MAX > 1) - { - mbui_iterator_t iter; + { + mbui_iterator_t iter; - for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter)) - if (!(mb_len (mbui_cur (iter)) == 1 - && (unsigned char) * mbui_cur_ptr (iter) == uc)) - break; - return mbui_cur_ptr (iter) - string; - } + for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter)) + if (!(mb_len (mbui_cur (iter)) == 1 + && (unsigned char) * mbui_cur_ptr (iter) == uc)) + break; + return mbui_cur_ptr (iter) - string; + } else - { - const char *ptr; + { + const char *ptr; - for (ptr = string; *ptr != '\0'; ptr++) - if ((unsigned char) *ptr != uc) - break; - return ptr - string; - } + for (ptr = string; *ptr != '\0'; ptr++) + if ((unsigned char) *ptr != uc) + break; + return ptr - string; + } } /* General case. */ if (MB_CUR_MAX > 1) @@ -62,25 +62,25 @@ mbsspn (const char *string, const char *reject) mbui_iterator_t iter; for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter)) - { - if (mb_len (mbui_cur (iter)) == 1) - { - if (mbschr (reject, * mbui_cur_ptr (iter)) == NULL) - goto found; - } - else - { - mbui_iterator_t aiter; + { + if (mb_len (mbui_cur (iter)) == 1) + { + if (mbschr (reject, * mbui_cur_ptr (iter)) == NULL) + goto found; + } + else + { + mbui_iterator_t aiter; - for (mbui_init (aiter, reject);; mbui_advance (aiter)) - { - if (!mbui_avail (aiter)) - goto found; - if (mb_equal (mbui_cur (aiter), mbui_cur (iter))) - break; - } - } - } + for (mbui_init (aiter, reject);; mbui_advance (aiter)) + { + if (!mbui_avail (aiter)) + goto found; + if (mb_equal (mbui_cur (aiter), mbui_cur (iter))) + break; + } + } + } found: return mbui_cur_ptr (iter) - string; } diff --git a/lib/mbsstr.c b/lib/mbsstr.c index c84946b63..e9aeea41d 100644 --- a/lib/mbsstr.c +++ b/lib/mbsstr.c @@ -37,7 +37,7 @@ Return false if it was aborted because not enough memory was available. */ static bool knuth_morris_pratt_multibyte (const char *haystack, const char *needle, - const char **resultp) + const char **resultp) { size_t m = mbslen (needle); mbchar_t *needle_mbchars; @@ -84,46 +84,46 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle, for (i = 2; i < m; i++) { - /* Here: j = i-1 - table[i-1]. - The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold - for x < table[i-1], by induction. - Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ - mbchar_t *b = &needle_mbchars[i - 1]; - - for (;;) - { - /* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x] - is known to hold for x < i-1-j. - Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ - if (mb_equal (*b, needle_mbchars[j])) - { - /* Set table[i] := i-1-j. */ - table[i] = i - ++j; - break; - } - /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds - for x = i-1-j, because - needle[i-1] != needle[j] = needle[i-1-x]. */ - if (j == 0) - { - /* The inequality holds for all possible x. */ - table[i] = i; - break; - } - /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds - for i-1-j < x < i-1-j+table[j], because for these x: - needle[x..i-2] - = needle[x-(i-1-j)..j-1] - != needle[0..j-1-(x-(i-1-j))] (by definition of table[j]) - = needle[0..i-2-x], - hence needle[x..i-1] != needle[0..i-1-x]. - Furthermore - needle[i-1-j+table[j]..i-2] - = needle[table[j]..j-1] - = needle[0..j-1-table[j]] (by definition of table[j]). */ - j = j - table[j]; - } - /* Here: j = i - table[i]. */ + /* Here: j = i-1 - table[i-1]. + The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold + for x < table[i-1], by induction. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + mbchar_t *b = &needle_mbchars[i - 1]; + + for (;;) + { + /* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x] + is known to hold for x < i-1-j. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + if (mb_equal (*b, needle_mbchars[j])) + { + /* Set table[i] := i-1-j. */ + table[i] = i - ++j; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for x = i-1-j, because + needle[i-1] != needle[j] = needle[i-1-x]. */ + if (j == 0) + { + /* The inequality holds for all possible x. */ + table[i] = i; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for i-1-j < x < i-1-j+table[j], because for these x: + needle[x..i-2] + = needle[x-(i-1-j)..j-1] + != needle[0..j-1-(x-(i-1-j))] (by definition of table[j]) + = needle[0..i-2-x], + hence needle[x..i-1] != needle[0..i-1-x]. + Furthermore + needle[i-1-j+table[j]..i-2] + = needle[table[j]..j-1] + = needle[0..j-1-table[j]] (by definition of table[j]). */ + j = j - table[j]; + } + /* Here: j = i - table[i]. */ } } @@ -140,36 +140,36 @@ knuth_morris_pratt_multibyte (const char *haystack, const char *needle, /* Invariant: phaystack = rhaystack + j. */ while (mbui_avail (phaystack)) if (mb_equal (needle_mbchars[j], mbui_cur (phaystack))) - { - j++; - mbui_advance (phaystack); - if (j == m) - { - /* The entire needle has been found. */ - *resultp = mbui_cur_ptr (rhaystack); - break; - } - } + { + j++; + mbui_advance (phaystack); + if (j == m) + { + /* The entire needle has been found. */ + *resultp = mbui_cur_ptr (rhaystack); + break; + } + } else if (j > 0) - { - /* Found a match of needle[0..j-1], mismatch at needle[j]. */ - size_t count = table[j]; - j -= count; - for (; count > 0; count--) - { - if (!mbui_avail (rhaystack)) - abort (); - mbui_advance (rhaystack); - } - } + { + /* Found a match of needle[0..j-1], mismatch at needle[j]. */ + size_t count = table[j]; + j -= count; + for (; count > 0; count--) + { + if (!mbui_avail (rhaystack)) + abort (); + mbui_advance (rhaystack); + } + } else - { - /* Found a mismatch at needle[0] already. */ - if (!mbui_avail (rhaystack)) - abort (); - mbui_advance (rhaystack); - mbui_advance (phaystack); - } + { + /* Found a mismatch at needle[0] already. */ + if (!mbui_avail (rhaystack)) + abort (); + mbui_advance (rhaystack); + mbui_advance (phaystack); + } } freea (memory); @@ -192,188 +192,188 @@ mbsstr (const char *haystack, const char *needle) mbui_init (iter_needle, needle); if (mbui_avail (iter_needle)) - { - /* Minimizing the worst-case complexity: - Let n = mbslen(haystack), m = mbslen(needle). - The naïve algorithm is O(n*m) worst-case. - The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a - memory allocation. - To achieve linear complexity and yet amortize the cost of the - memory allocation, we activate the Knuth-Morris-Pratt algorithm - only once the naïve algorithm has already run for some time; more - precisely, when - - the outer loop count is >= 10, - - the average number of comparisons per outer loop is >= 5, - - the total number of comparisons is >= m. - But we try it only once. If the memory allocation attempt failed, - we don't retry it. */ - bool try_kmp = true; - size_t outer_loop_count = 0; - size_t comparison_count = 0; - size_t last_ccount = 0; /* last comparison count */ - mbui_iterator_t iter_needle_last_ccount; /* = needle + last_ccount */ - - mbui_iterator_t iter_haystack; - - mbui_init (iter_needle_last_ccount, needle); - mbui_init (iter_haystack, haystack); - for (;; mbui_advance (iter_haystack)) - { - if (!mbui_avail (iter_haystack)) - /* No match. */ - return NULL; - - /* See whether it's advisable to use an asymptotically faster - algorithm. */ - if (try_kmp - && outer_loop_count >= 10 - && comparison_count >= 5 * outer_loop_count) - { - /* See if needle + comparison_count now reaches the end of - needle. */ - size_t count = comparison_count - last_ccount; - for (; - count > 0 && mbui_avail (iter_needle_last_ccount); - count--) - mbui_advance (iter_needle_last_ccount); - last_ccount = comparison_count; - if (!mbui_avail (iter_needle_last_ccount)) - { - /* Try the Knuth-Morris-Pratt algorithm. */ - const char *result; - bool success = - knuth_morris_pratt_multibyte (haystack, needle, - &result); - if (success) - return (char *) result; - try_kmp = false; - } - } - - outer_loop_count++; - comparison_count++; - if (mb_equal (mbui_cur (iter_haystack), mbui_cur (iter_needle))) - /* The first character matches. */ - { - mbui_iterator_t rhaystack; - mbui_iterator_t rneedle; - - memcpy (&rhaystack, &iter_haystack, sizeof (mbui_iterator_t)); - mbui_advance (rhaystack); - - mbui_init (rneedle, needle); - if (!mbui_avail (rneedle)) - abort (); - mbui_advance (rneedle); - - for (;; mbui_advance (rhaystack), mbui_advance (rneedle)) - { - if (!mbui_avail (rneedle)) - /* Found a match. */ - return (char *) mbui_cur_ptr (iter_haystack); - if (!mbui_avail (rhaystack)) - /* No match. */ - return NULL; - comparison_count++; - if (!mb_equal (mbui_cur (rhaystack), mbui_cur (rneedle))) - /* Nothing in this round. */ - break; - } - } - } - } + { + /* Minimizing the worst-case complexity: + Let n = mbslen(haystack), m = mbslen(needle). + The naïve algorithm is O(n*m) worst-case. + The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a + memory allocation. + To achieve linear complexity and yet amortize the cost of the + memory allocation, we activate the Knuth-Morris-Pratt algorithm + only once the naïve algorithm has already run for some time; more + precisely, when + - the outer loop count is >= 10, + - the average number of comparisons per outer loop is >= 5, + - the total number of comparisons is >= m. + But we try it only once. If the memory allocation attempt failed, + we don't retry it. */ + bool try_kmp = true; + size_t outer_loop_count = 0; + size_t comparison_count = 0; + size_t last_ccount = 0; /* last comparison count */ + mbui_iterator_t iter_needle_last_ccount; /* = needle + last_ccount */ + + mbui_iterator_t iter_haystack; + + mbui_init (iter_needle_last_ccount, needle); + mbui_init (iter_haystack, haystack); + for (;; mbui_advance (iter_haystack)) + { + if (!mbui_avail (iter_haystack)) + /* No match. */ + return NULL; + + /* See whether it's advisable to use an asymptotically faster + algorithm. */ + if (try_kmp + && outer_loop_count >= 10 + && comparison_count >= 5 * outer_loop_count) + { + /* See if needle + comparison_count now reaches the end of + needle. */ + size_t count = comparison_count - last_ccount; + for (; + count > 0 && mbui_avail (iter_needle_last_ccount); + count--) + mbui_advance (iter_needle_last_ccount); + last_ccount = comparison_count; + if (!mbui_avail (iter_needle_last_ccount)) + { + /* Try the Knuth-Morris-Pratt algorithm. */ + const char *result; + bool success = + knuth_morris_pratt_multibyte (haystack, needle, + &result); + if (success) + return (char *) result; + try_kmp = false; + } + } + + outer_loop_count++; + comparison_count++; + if (mb_equal (mbui_cur (iter_haystack), mbui_cur (iter_needle))) + /* The first character matches. */ + { + mbui_iterator_t rhaystack; + mbui_iterator_t rneedle; + + memcpy (&rhaystack, &iter_haystack, sizeof (mbui_iterator_t)); + mbui_advance (rhaystack); + + mbui_init (rneedle, needle); + if (!mbui_avail (rneedle)) + abort (); + mbui_advance (rneedle); + + for (;; mbui_advance (rhaystack), mbui_advance (rneedle)) + { + if (!mbui_avail (rneedle)) + /* Found a match. */ + return (char *) mbui_cur_ptr (iter_haystack); + if (!mbui_avail (rhaystack)) + /* No match. */ + return NULL; + comparison_count++; + if (!mb_equal (mbui_cur (rhaystack), mbui_cur (rneedle))) + /* Nothing in this round. */ + break; + } + } + } + } else - return (char *) haystack; + return (char *) haystack; } else { if (*needle != '\0') - { - /* Minimizing the worst-case complexity: - Let n = strlen(haystack), m = strlen(needle). - The naïve algorithm is O(n*m) worst-case. - The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a - memory allocation. - To achieve linear complexity and yet amortize the cost of the - memory allocation, we activate the Knuth-Morris-Pratt algorithm - only once the naïve algorithm has already run for some time; more - precisely, when - - the outer loop count is >= 10, - - the average number of comparisons per outer loop is >= 5, - - the total number of comparisons is >= m. - But we try it only once. If the memory allocation attempt failed, - we don't retry it. */ - bool try_kmp = true; - size_t outer_loop_count = 0; - size_t comparison_count = 0; - size_t last_ccount = 0; /* last comparison count */ - const char *needle_last_ccount = needle; /* = needle + last_ccount */ - - /* Speed up the following searches of needle by caching its first - character. */ - char b = *needle++; - - for (;; haystack++) - { - if (*haystack == '\0') - /* No match. */ - return NULL; - - /* See whether it's advisable to use an asymptotically faster - algorithm. */ - if (try_kmp - && outer_loop_count >= 10 - && comparison_count >= 5 * outer_loop_count) - { - /* See if needle + comparison_count now reaches the end of - needle. */ - if (needle_last_ccount != NULL) - { - needle_last_ccount += - strnlen (needle_last_ccount, - comparison_count - last_ccount); - if (*needle_last_ccount == '\0') - needle_last_ccount = NULL; - last_ccount = comparison_count; - } - if (needle_last_ccount == NULL) - { - /* Try the Knuth-Morris-Pratt algorithm. */ - const char *result; - bool success = - knuth_morris_pratt_unibyte (haystack, needle - 1, - &result); - if (success) - return (char *) result; - try_kmp = false; - } - } - - outer_loop_count++; - comparison_count++; - if (*haystack == b) - /* The first character matches. */ - { - const char *rhaystack = haystack + 1; - const char *rneedle = needle; - - for (;; rhaystack++, rneedle++) - { - if (*rneedle == '\0') - /* Found a match. */ - return (char *) haystack; - if (*rhaystack == '\0') - /* No match. */ - return NULL; - comparison_count++; - if (*rhaystack != *rneedle) - /* Nothing in this round. */ - break; - } - } - } - } + { + /* Minimizing the worst-case complexity: + Let n = strlen(haystack), m = strlen(needle). + The naïve algorithm is O(n*m) worst-case. + The Knuth-Morris-Pratt algorithm is O(n) worst-case but it needs a + memory allocation. + To achieve linear complexity and yet amortize the cost of the + memory allocation, we activate the Knuth-Morris-Pratt algorithm + only once the naïve algorithm has already run for some time; more + precisely, when + - the outer loop count is >= 10, + - the average number of comparisons per outer loop is >= 5, + - the total number of comparisons is >= m. + But we try it only once. If the memory allocation attempt failed, + we don't retry it. */ + bool try_kmp = true; + size_t outer_loop_count = 0; + size_t comparison_count = 0; + size_t last_ccount = 0; /* last comparison count */ + const char *needle_last_ccount = needle; /* = needle + last_ccount */ + + /* Speed up the following searches of needle by caching its first + character. */ + char b = *needle++; + + for (;; haystack++) + { + if (*haystack == '\0') + /* No match. */ + return NULL; + + /* See whether it's advisable to use an asymptotically faster + algorithm. */ + if (try_kmp + && outer_loop_count >= 10 + && comparison_count >= 5 * outer_loop_count) + { + /* See if needle + comparison_count now reaches the end of + needle. */ + if (needle_last_ccount != NULL) + { + needle_last_ccount += + strnlen (needle_last_ccount, + comparison_count - last_ccount); + if (*needle_last_ccount == '\0') + needle_last_ccount = NULL; + last_ccount = comparison_count; + } + if (needle_last_ccount == NULL) + { + /* Try the Knuth-Morris-Pratt algorithm. */ + const char *result; + bool success = + knuth_morris_pratt_unibyte (haystack, needle - 1, + &result); + if (success) + return (char *) result; + try_kmp = false; + } + } + + outer_loop_count++; + comparison_count++; + if (*haystack == b) + /* The first character matches. */ + { + const char *rhaystack = haystack + 1; + const char *rneedle = needle; + + for (;; rhaystack++, rneedle++) + { + if (*rneedle == '\0') + /* Found a match. */ + return (char *) haystack; + if (*rhaystack == '\0') + /* No match. */ + return NULL; + comparison_count++; + if (*rhaystack != *rneedle) + /* Nothing in this round. */ + break; + } + } + } + } else - return (char *) haystack; + return (char *) haystack; } } diff --git a/lib/mbstok_r.c b/lib/mbstok_r.c index b698d3fad..e0d99db78 100644 --- a/lib/mbstok_r.c +++ b/lib/mbstok_r.c @@ -28,35 +28,35 @@ mbstok_r (char *string, const char *delim, char **save_ptr) if (MB_CUR_MAX > 1) { if (string == NULL) - { - string = *save_ptr; - if (string == NULL) - return NULL; /* reminder that end of token sequence has been - reached */ - } + { + string = *save_ptr; + if (string == NULL) + return NULL; /* reminder that end of token sequence has been + reached */ + } /* Skip leading delimiters. */ string += mbsspn (string, delim); /* Found a token? */ if (*string == '\0') - { - *save_ptr = NULL; - return NULL; - } + { + *save_ptr = NULL; + return NULL; + } /* Move past the token. */ { - char *token_end = mbspbrk (string, delim); + char *token_end = mbspbrk (string, delim); - if (token_end != NULL) - { - /* NUL-terminate the token. */ - *token_end = '\0'; - *save_ptr = token_end + 1; - } - else - *save_ptr = NULL; + if (token_end != NULL) + { + /* NUL-terminate the token. */ + *token_end = '\0'; + *save_ptr = token_end + 1; + } + else + *save_ptr = NULL; } return string; diff --git a/lib/mbswidth.c b/lib/mbswidth.c index 0f380a9dc..ac34a9cad 100644 --- a/lib/mbswidth.c +++ b/lib/mbswidth.c @@ -63,92 +63,92 @@ mbsnwidth (const char *string, size_t nbytes, int flags) 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. */ - width += w; - else - /* An unprintable multibyte character. */ - if (!(flags & MBSW_REJECT_UNPRINTABLE)) - width += (iswcntrl (wc) ? 0 : 1); - else - return -1; - - p += bytes; - } - while (! mbsinit (&mbstate)); - } - break; - } + 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. */ + width += w; + else + /* An unprintable multibyte character. */ + if (!(flags & MBSW_REJECT_UNPRINTABLE)) + width += (iswcntrl (wc) ? 0 : 1); + else + return -1; + + p += bytes; + } + while (! mbsinit (&mbstate)); + } + break; + } return width; } @@ -157,11 +157,11 @@ mbsnwidth (const char *string, size_t nbytes, int flags) unsigned char c = (unsigned char) *p++; if (isprint (c)) - width++; + width++; else if (!(flags & MBSW_REJECT_UNPRINTABLE)) - width += (iscntrl (c) ? 0 : 1); + width += (iscntrl (c) ? 0 : 1); else - return -1; + return -1; } return width; } diff --git a/lib/mbswidth.h b/lib/mbswidth.h index 15da406dc..ff7ccbc3f 100644 --- a/lib/mbswidth.h +++ b/lib/mbswidth.h @@ -43,7 +43,7 @@ extern "C" { /* 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 +#define MBSW_REJECT_UNPRINTABLE 2 /* Returns the number of screen columns needed for STRING. */ diff --git a/lib/mbuiter.h b/lib/mbuiter.h index 213e71030..a0189f23d 100644 --- a/lib/mbuiter.h +++ b/lib/mbuiter.h @@ -77,13 +77,13 @@ Here are the function prototypes of the macros. - extern void mbui_init (mbui_iterator_t iter, const char *startptr); - extern bool mbui_avail (mbui_iterator_t iter); - extern void mbui_advance (mbui_iterator_t iter); - extern mbchar_t mbui_cur (mbui_iterator_t iter); - extern const char * mbui_cur_ptr (mbui_iterator_t iter); - extern void mbui_reloc (mbui_iterator_t iter, ptrdiff_t ptrdiff); - extern void mbui_copy (mbui_iterator_t *new, const mbui_iterator_t *old); + extern void mbui_init (mbui_iterator_t iter, const char *startptr); + extern bool mbui_avail (mbui_iterator_t iter); + extern void mbui_advance (mbui_iterator_t iter); + extern mbchar_t mbui_cur (mbui_iterator_t iter); + extern const char * mbui_cur_ptr (mbui_iterator_t iter); + extern void mbui_reloc (mbui_iterator_t iter, ptrdiff_t ptrdiff); + extern void mbui_copy (mbui_iterator_t *new, const mbui_iterator_t *old); */ #ifndef _MBUITER_H @@ -108,16 +108,16 @@ struct mbuiter_multi { - bool in_shift; /* true if next byte may not be interpreted as ASCII */ - mbstate_t state; /* if in_shift: current shift state */ - bool next_done; /* true if mbui_avail has already filled the following */ - struct mbchar cur; /* the current character: - const char *cur.ptr pointer to current character - The following are only valid after mbui_avail. - size_t cur.bytes number of bytes of current character - bool cur.wc_valid true if wc is a valid wide character - wchar_t cur.wc if wc_valid: the current character - */ + bool in_shift; /* true if next byte may not be interpreted as ASCII */ + mbstate_t state; /* if in_shift: current shift state */ + bool next_done; /* true if mbui_avail has already filled the following */ + struct mbchar cur; /* the current character: + const char *cur.ptr pointer to current character + The following are only valid after mbui_avail. + size_t cur.bytes number of bytes of current character + bool cur.wc_valid true if wc is a valid wide character + wchar_t cur.wc if wc_valid: the current character + */ }; static inline void @@ -131,8 +131,8 @@ mbuiter_multi_next (struct mbuiter_multi *iter) if (is_basic (*iter->cur.ptr)) { /* These characters are part of the basic character set. ISO C 99 - guarantees that their wide character code is identical to their - char code. */ + guarantees that their wide character code is identical to their + char code. */ iter->cur.bytes = 1; iter->cur.wc = *iter->cur.ptr; iter->cur.wc_valid = true; @@ -143,40 +143,40 @@ mbuiter_multi_next (struct mbuiter_multi *iter) iter->in_shift = true; with_shift: iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr, - strnlen1 (iter->cur.ptr, MB_CUR_MAX), - &iter->state); + strnlen1 (iter->cur.ptr, MB_CUR_MAX), + &iter->state); if (iter->cur.bytes == (size_t) -1) - { - /* An invalid multibyte sequence was encountered. */ - iter->cur.bytes = 1; - iter->cur.wc_valid = false; - /* Whether to set iter->in_shift = false and reset iter->state - or not is not very important; the string is bogus anyway. */ - } + { + /* An invalid multibyte sequence was encountered. */ + iter->cur.bytes = 1; + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not very important; the string is bogus anyway. */ + } else if (iter->cur.bytes == (size_t) -2) - { - /* An incomplete multibyte character at the end. */ - iter->cur.bytes = strlen (iter->cur.ptr); - iter->cur.wc_valid = false; - /* Whether to set iter->in_shift = false and reset iter->state - or not is not important; the string end is reached anyway. */ - } + { + /* An incomplete multibyte character at the end. */ + iter->cur.bytes = strlen (iter->cur.ptr); + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not important; the string end is reached anyway. */ + } else - { - if (iter->cur.bytes == 0) - { - /* A null wide character was encountered. */ - iter->cur.bytes = 1; - assert (*iter->cur.ptr == '\0'); - assert (iter->cur.wc == 0); - } - iter->cur.wc_valid = true; - - /* When in the initial state, we can go back treating ASCII - characters more quickly. */ - if (mbsinit (&iter->state)) - iter->in_shift = false; - } + { + if (iter->cur.bytes == 0) + { + /* A null wide character was encountered. */ + iter->cur.bytes = 1; + assert (*iter->cur.ptr == '\0'); + assert (iter->cur.wc == 0); + } + iter->cur.wc_valid = true; + + /* When in the initial state, we can go back treating ASCII + characters more quickly. */ + if (mbsinit (&iter->state)) + iter->in_shift = false; + } } iter->next_done = true; } diff --git a/lib/md2.c b/lib/md2.c index e585eb808..1b7dc4618 100644 --- a/lib/md2.c +++ b/lib/md2.c @@ -115,33 +115,33 @@ md2_stream (FILE *stream, void *resblock) /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that BLOCKSIZE % 64 == 0 @@ -196,11 +196,11 @@ md2_process_bytes (const void *buffer, size_t len, struct md2_ctx *ctx) /* is 16 bytes full? */ if (ctx->curlen == 16) - { - md2_compress (ctx); - md2_update_chksum (ctx); - ctx->curlen = 0; - } + { + md2_compress (ctx); + md2_update_chksum (ctx); + ctx->curlen = 0; + } } } @@ -260,9 +260,9 @@ md2_compress (struct md2_ctx *ctx) for (j = 0; j < 18; j++) { for (k = 0; k < 48; k++) - { - t = (ctx->X[k] ^= PI_SUBST[(int) (t & 255)]); - } + { + t = (ctx->X[k] ^= PI_SUBST[(int) (t & 255)]); + } t = (t + (unsigned char) j) & 255; } } diff --git a/lib/md2.h b/lib/md2.h index c7db64dd7..383ed2968 100644 --- a/lib/md2.h +++ b/lib/md2.h @@ -45,14 +45,14 @@ extern void md2_init_ctx (struct md2_ctx *ctx); starting at BUFFER. It is NOT required that LEN is a multiple of 64. */ extern void md2_process_block (const void *buffer, size_t len, - struct md2_ctx *ctx); + struct md2_ctx *ctx); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes starting at BUFFER. It is NOT required that LEN is a multiple of 64. */ extern void md2_process_bytes (const void *buffer, size_t len, - struct md2_ctx *ctx); + struct md2_ctx *ctx); /* Process the remaining bytes in the buffer and put result from CTX in first 16 bytes following RESBUF. The result is always in little diff --git a/lib/md4.c b/lib/md4.c index 2adb82d1b..b5a8a7053 100644 --- a/lib/md4.c +++ b/lib/md4.c @@ -35,7 +35,7 @@ #endif #ifdef WORDS_BIGENDIAN -# define SWAP(n) \ +# define SWAP(n) \ (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) #else # define SWAP(n) (n) @@ -108,7 +108,7 @@ md4_finish_ctx (struct md4_ctx *ctx, void *resbuf) /* Put the 64-bit file length in *bits* at the end of the buffer. */ ctx->buffer[(bytes + pad) / 4] = SWAP (ctx->total[0] << 3); ctx->buffer[(bytes + pad) / 4 + 1] = SWAP ((ctx->total[1] << 3) | - (ctx->total[0] >> 29)); + (ctx->total[0] >> 29)); /* Process last bytes. */ md4_process_block (ctx->buffer, bytes + pad + 8, ctx); @@ -143,33 +143,33 @@ md4_stream (FILE * stream, void *resblock) /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that BLOCKSIZE % 64 == 0 @@ -222,14 +222,14 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx) ctx->buflen += add; if (ctx->buflen > 64) - { - md4_process_block (ctx->buffer, ctx->buflen & ~63, ctx); + { + md4_process_block (ctx->buffer, ctx->buflen & ~63, ctx); - ctx->buflen &= 63; - /* The regions in the following copy operation cannot overlap. */ - memcpy (ctx->buffer, &((char*)ctx->buffer)[(left_over + add) & ~63], - ctx->buflen); - } + ctx->buflen &= 63; + /* The regions in the following copy operation cannot overlap. */ + memcpy (ctx->buffer, &((char*)ctx->buffer)[(left_over + add) & ~63], + ctx->buflen); + } buffer = (const char *) buffer + add; len -= add; @@ -248,19 +248,19 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx) # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) # endif if (UNALIGNED_P (buffer)) - while (len > 64) - { - md4_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *) buffer + 64; - len -= 64; - } + while (len > 64) + { + md4_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); + buffer = (const char *) buffer + 64; + len -= 64; + } else #endif - { - md4_process_block (buffer, len & ~63, ctx); - buffer = (const char *) buffer + (len & ~63); - len &= 63; - } + { + md4_process_block (buffer, len & ~63, ctx); + buffer = (const char *) buffer + (len & ~63); + len &= 63; + } } /* Move remaining bytes in internal buffer. */ @@ -271,11 +271,11 @@ md4_process_bytes (const void *buffer, size_t len, struct md4_ctx *ctx) memcpy (&((char*)ctx->buffer)[left_over], buffer, len); left_over += len; if (left_over >= 64) - { - md4_process_block (ctx->buffer, 64, ctx); - left_over -= 64; - memcpy (ctx->buffer, &ctx->buffer[16], left_over); - } + { + md4_process_block (ctx->buffer, 64, ctx); + left_over -= 64; + memcpy (ctx->buffer, &ctx->buffer[16], left_over); + } ctx->buflen = left_over; } } @@ -323,10 +323,10 @@ md4_process_block (const void *buffer, size_t len, struct md4_ctx *ctx) { int t; for (t = 0; t < 16; t++) - { - x[t] = SWAP (*words); - words++; - } + { + x[t] = SWAP (*words); + words++; + } /* Round 1. */ R1 (A, B, C, D, 0, 3); diff --git a/lib/md4.h b/lib/md4.h index 9930b1aba..ee07d81bd 100644 --- a/lib/md4.h +++ b/lib/md4.h @@ -51,14 +51,14 @@ extern void md4_init_ctx (struct md4_ctx *ctx); starting at BUFFER. It is necessary that LEN is a multiple of 64!!! */ extern void md4_process_block (const void *buffer, size_t len, - struct md4_ctx *ctx); + struct md4_ctx *ctx); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes starting at BUFFER. It is NOT required that LEN is a multiple of 64. */ extern void md4_process_bytes (const void *buffer, size_t len, - struct md4_ctx *ctx); + struct md4_ctx *ctx); /* Process the remaining bytes in the buffer and put result from CTX in first 16 bytes following RESBUF. The result is always in little diff --git a/lib/md5.c b/lib/md5.c index 85c35535a..a7a47ad5d 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -1,7 +1,7 @@ /* Functions to compute MD5 message digest of files or memory blocks. according to the definition of MD5 in RFC 1321 from April 1992. Copyright (C) 1995,1996,1997,1999,2000,2001,2005,2006,2008 - Free Software Foundation, Inc. + 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 @@ -50,7 +50,7 @@ #endif #ifdef WORDS_BIGENDIAN -# define SWAP(n) \ +# define SWAP(n) \ (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) #else # define SWAP(n) (n) @@ -156,33 +156,33 @@ md5_stream (FILE *stream, void *resblock) /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that BLOCKSIZE % 64 == 0 @@ -236,15 +236,15 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) ctx->buflen += add; if (ctx->buflen > 64) - { - md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx); + { + md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx); - ctx->buflen &= 63; - /* The regions in the following copy operation cannot overlap. */ - memcpy (ctx->buffer, - &((char *) ctx->buffer)[(left_over + add) & ~63], - ctx->buflen); - } + ctx->buflen &= 63; + /* The regions in the following copy operation cannot overlap. */ + memcpy (ctx->buffer, + &((char *) ctx->buffer)[(left_over + add) & ~63], + ctx->buflen); + } buffer = (const char *) buffer + add; len -= add; @@ -257,19 +257,19 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) # define alignof(type) offsetof (struct { char c; type x; }, x) # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) - while (len > 64) - { - md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *) buffer + 64; - len -= 64; - } + while (len > 64) + { + md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); + buffer = (const char *) buffer + 64; + len -= 64; + } else #endif - { - md5_process_block (buffer, len & ~63, ctx); - buffer = (const char *) buffer + (len & ~63); - len &= 63; - } + { + md5_process_block (buffer, len & ~63, ctx); + buffer = (const char *) buffer + (len & ~63); + len &= 63; + } } /* Move remaining bytes in internal buffer. */ @@ -280,11 +280,11 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) memcpy (&((char *) ctx->buffer)[left_over], buffer, len); left_over += len; if (left_over >= 64) - { - md5_process_block (ctx->buffer, 64, ctx); - left_over -= 64; - memcpy (ctx->buffer, &ctx->buffer[16], left_over); - } + { + md5_process_block (ctx->buffer, 64, ctx); + left_over -= 64; + memcpy (ctx->buffer, &ctx->buffer[16], left_over); + } ctx->buflen = left_over; } } @@ -338,14 +338,14 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) before the computation. To reduce the work for the next steps we store the swapped words in the array CORRECT_WORDS. */ -#define OP(a, b, c, d, s, T) \ - do \ - { \ - a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ - ++words; \ - CYCLIC (a, s); \ - a += b; \ - } \ +#define OP(a, b, c, d, s, T) \ + do \ + { \ + a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ + ++words; \ + CYCLIC (a, s); \ + a += b; \ + } \ while (0) /* It is unfortunate that C does not provide an operator for @@ -384,13 +384,13 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) in CORRECT_WORDS. Redefine the macro to take an additional first argument specifying the function to use. */ #undef OP -#define OP(f, a, b, c, d, k, s, T) \ - do \ - { \ - a += f (b, c, d) + correct_words[k] + T; \ - CYCLIC (a, s); \ - a += b; \ - } \ +#define OP(f, a, b, c, d, k, s, T) \ + do \ + { \ + a += f (b, c, d) + correct_words[k] + T; \ + CYCLIC (a, s); \ + a += b; \ + } \ while (0) /* Round 2. */ diff --git a/lib/md5.h b/lib/md5.h index ab8deb75b..3443f0e91 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -29,7 +29,7 @@ #ifndef __GNUC_PREREQ # if defined __GNUC__ && defined __GNUC_MINOR__ -# define __GNUC_PREREQ(maj, min) \ +# define __GNUC_PREREQ(maj, min) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) # else # define __GNUC_PREREQ(maj, min) 0 @@ -38,7 +38,7 @@ #ifndef __THROW # if defined __cplusplus && __GNUC_PREREQ (2,8) -# define __THROW throw () +# define __THROW throw () # else # define __THROW # endif @@ -85,14 +85,14 @@ extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW; starting at BUFFER. It is necessary that LEN is a multiple of 64!!! */ extern void __md5_process_block (const void *buffer, size_t len, - struct md5_ctx *ctx) __THROW; + struct md5_ctx *ctx) __THROW; /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes starting at BUFFER. It is NOT required that LEN is a multiple of 64. */ extern void __md5_process_bytes (const void *buffer, size_t len, - struct md5_ctx *ctx) __THROW; + struct md5_ctx *ctx) __THROW; /* Process the remaining bytes in the buffer and put result from CTX in first 16 bytes following RESBUF. The result is always in little @@ -117,7 +117,7 @@ extern int __md5_stream (FILE *stream, void *resblock) __THROW; output yields to the wanted ASCII representation of the message digest. */ extern void *__md5_buffer (const char *buffer, size_t len, - void *resblock) __THROW; + void *resblock) __THROW; # ifdef __cplusplus } diff --git a/lib/memcasecmp.c b/lib/memcasecmp.c index 4873651b3..08887fb4e 100644 --- a/lib/memcasecmp.c +++ b/lib/memcasecmp.c @@ -40,9 +40,9 @@ memcasecmp (const void *vs1, const void *vs2, size_t n) int U1 = toupper (u1); int U2 = toupper (u2); int diff = (UCHAR_MAX <= INT_MAX ? U1 - U2 - : U1 < U2 ? -1 : U2 < U1); + : U1 < U2 ? -1 : U2 < U1); if (diff) - return diff; + return diff; } return 0; } diff --git a/lib/memchr.c b/lib/memchr.c index 2253d2d65..a23ff788d 100644 --- a/lib/memchr.c +++ b/lib/memchr.c @@ -97,15 +97,15 @@ __memchr (void const *s, int c_in, size_t n) 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; - } - } + { + 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 @@ -144,8 +144,8 @@ __memchr (void const *s, int c_in, size_t n) longword longword1 = *longword_ptr ^ repeated_c; if ((((longword1 - repeated_one) & ~longword1) - & (repeated_one << 7)) != 0) - break; + & (repeated_one << 7)) != 0) + break; longword_ptr++; n -= sizeof (longword); } @@ -162,7 +162,7 @@ __memchr (void const *s, int c_in, size_t n) for (; n > 0; --n, ++char_ptr) { if (*char_ptr == c) - return (void *) char_ptr; + return (void *) char_ptr; } return NULL; diff --git a/lib/memchr2.c b/lib/memchr2.c index ad78195ee..a19f9eb41 100644 --- a/lib/memchr2.c +++ b/lib/memchr2.c @@ -84,16 +84,16 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n) 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; - } - } + { + 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 @@ -138,9 +138,9 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n) longword longword2 = *longword_ptr ^ repeated_c2; if (((((longword1 - repeated_one) & ~longword1) - | ((longword2 - repeated_one) & ~longword2)) - & (repeated_one << 7)) != 0) - break; + | ((longword2 - repeated_one) & ~longword2)) + & (repeated_one << 7)) != 0) + break; longword_ptr++; n -= sizeof (longword); } @@ -157,7 +157,7 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n) for (; n > 0; --n, ++char_ptr) { if (*char_ptr == c1 || *char_ptr == c2) - return (void *) char_ptr; + return (void *) char_ptr; } return NULL; diff --git a/lib/memcmp.c b/lib/memcmp.c index 01810715b..98069b30c 100644 --- a/lib/memcmp.c +++ b/lib/memcmp.c @@ -38,18 +38,18 @@ # define WORDS_BIGENDIAN # endif -#else /* Not in the GNU C library. */ +#else /* Not in the GNU C library. */ # include /* Type to use for aligned memory operations. This should normally be the biggest type supported by a single load and store. Must be an unsigned type. */ -# define op_t unsigned long int -# define OPSIZ (sizeof(op_t)) +# define op_t unsigned long int +# define OPSIZ (sizeof(op_t)) /* Threshold value for when to enter the unrolled loops. */ -# define OP_T_THRES 16 +# define OP_T_THRES 16 /* Type to use for unaligned operations. */ typedef unsigned char byte; @@ -60,7 +60,7 @@ typedef unsigned char byte; # define MERGE(w0, sh_1, w1, sh_2) (((w0) << (sh_1)) | ((w1) >> (sh_2))) # endif -#endif /* In the GNU C library. */ +#endif /* In the GNU C library. */ #ifdef WORDS_BIGENDIAN # define CMP_LT_OR_GT(a, b) ((a) > (b) ? 1 : -1) @@ -111,7 +111,7 @@ memcmp_bytes (op_t a, op_t b) /* memcmp_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN `op_t' objects (not LEN bytes!). Both SRCP1 and SRCP2 should be aligned for memory operations on `op_t's. */ -#ifdef __GNUC__ +#ifdef __GNUC__ __inline #endif static int @@ -139,7 +139,7 @@ memcmp_common_alignment (uintptr_t srcp1, uintptr_t srcp2, size_t len) goto do2; case 0: if (OP_T_THRES <= 3 * OPSIZ && len == 0) - return 0; + return 0; a0 = ((op_t *) srcp1)[0]; b0 = ((op_t *) srcp2)[0]; goto do3; @@ -150,7 +150,7 @@ memcmp_common_alignment (uintptr_t srcp1, uintptr_t srcp2, size_t len) srcp2 += OPSIZ; len -= 1; if (OP_T_THRES <= 3 * OPSIZ && len == 0) - goto do0; + goto do0; /* Fall through. */ } @@ -159,25 +159,25 @@ memcmp_common_alignment (uintptr_t srcp1, uintptr_t srcp2, size_t len) a0 = ((op_t *) srcp1)[0]; b0 = ((op_t *) srcp2)[0]; if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); + return CMP_LT_OR_GT (a1, b1); do3: a1 = ((op_t *) srcp1)[1]; b1 = ((op_t *) srcp2)[1]; if (a0 != b0) - return CMP_LT_OR_GT (a0, b0); + return CMP_LT_OR_GT (a0, b0); do2: a0 = ((op_t *) srcp1)[2]; b0 = ((op_t *) srcp2)[2]; if (a1 != b1) - return CMP_LT_OR_GT (a1, b1); + return CMP_LT_OR_GT (a1, b1); do1: a1 = ((op_t *) srcp1)[3]; b1 = ((op_t *) srcp2)[3]; if (a0 != b0) - return CMP_LT_OR_GT (a0, b0); + return CMP_LT_OR_GT (a0, b0); srcp1 += 4 * OPSIZ; srcp2 += 4 * OPSIZ; @@ -196,7 +196,7 @@ memcmp_common_alignment (uintptr_t srcp1, uintptr_t srcp2, size_t len) /* memcmp_not_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN `op_t' objects (not LEN bytes!). SRCP2 should be aligned for memory operations on `op_t', but SRCP1 *should be unaligned*. */ -#ifdef __GNUC__ +#ifdef __GNUC__ __inline #endif static int @@ -237,7 +237,7 @@ memcmp_not_common_alignment (uintptr_t srcp1, uintptr_t srcp2, size_t len) goto do2; case 0: if (OP_T_THRES <= 3 * OPSIZ && len == 0) - return 0; + return 0; a3 = ((op_t *) srcp1)[0]; a0 = ((op_t *) srcp1)[1]; b0 = ((op_t *) srcp2)[0]; @@ -251,7 +251,7 @@ memcmp_not_common_alignment (uintptr_t srcp1, uintptr_t srcp2, size_t len) srcp2 += 1 * OPSIZ; len -= 1; if (OP_T_THRES <= 3 * OPSIZ && len == 0) - goto do0; + goto do0; /* Fall through. */ } @@ -261,28 +261,28 @@ memcmp_not_common_alignment (uintptr_t srcp1, uintptr_t srcp2, size_t len) b0 = ((op_t *) srcp2)[0]; x = MERGE(a2, shl, a3, shr); if (x != b3) - return CMP_LT_OR_GT (x, b3); + return CMP_LT_OR_GT (x, b3); do3: a1 = ((op_t *) srcp1)[1]; b1 = ((op_t *) srcp2)[1]; x = MERGE(a3, shl, a0, shr); if (x != b0) - return CMP_LT_OR_GT (x, b0); + return CMP_LT_OR_GT (x, b0); do2: a2 = ((op_t *) srcp1)[2]; b2 = ((op_t *) srcp2)[2]; x = MERGE(a0, shl, a1, shr); if (x != b1) - return CMP_LT_OR_GT (x, b1); + return CMP_LT_OR_GT (x, b1); do1: a3 = ((op_t *) srcp1)[3]; b3 = ((op_t *) srcp2)[3]; x = MERGE(a1, shl, a2, shr); if (x != b2) - return CMP_LT_OR_GT (x, b2); + return CMP_LT_OR_GT (x, b2); srcp1 += 4 * OPSIZ; srcp2 += 4 * OPSIZ; @@ -311,29 +311,29 @@ rpl_memcmp (const void *s1, const void *s2, size_t len) if (len >= OP_T_THRES) { /* There are at least some bytes to compare. No need to test - for LEN == 0 in this alignment loop. */ + for LEN == 0 in this alignment loop. */ while (srcp2 % OPSIZ != 0) - { - a0 = ((byte *) srcp1)[0]; - b0 = ((byte *) srcp2)[0]; - srcp1 += 1; - srcp2 += 1; - res = a0 - b0; - if (res != 0) - return res; - len -= 1; - } + { + a0 = ((byte *) srcp1)[0]; + b0 = ((byte *) srcp2)[0]; + srcp1 += 1; + srcp2 += 1; + res = a0 - b0; + if (res != 0) + return res; + len -= 1; + } /* SRCP2 is now aligned for memory operations on `op_t'. - SRCP1 alignment determines if we can do a simple, - aligned compare or need to shuffle bits. */ + SRCP1 alignment determines if we can do a simple, + aligned compare or need to shuffle bits. */ if (srcp1 % OPSIZ == 0) - res = memcmp_common_alignment (srcp1, srcp2, len / OPSIZ); + res = memcmp_common_alignment (srcp1, srcp2, len / OPSIZ); else - res = memcmp_not_common_alignment (srcp1, srcp2, len / OPSIZ); + res = memcmp_not_common_alignment (srcp1, srcp2, len / OPSIZ); if (res != 0) - return res; + return res; /* Number of bytes remaining in the interval [0..OPSIZ-1]. */ srcp1 += len & -OPSIZ; @@ -350,7 +350,7 @@ rpl_memcmp (const void *s1, const void *s2, size_t len) srcp2 += 1; res = a0 - b0; if (res != 0) - return res; + return res; len -= 1; } diff --git a/lib/memcmp2.c b/lib/memcmp2.c index 7f8f6049f..ce19efcd2 100644 --- a/lib/memcmp2.c +++ b/lib/memcmp2.c @@ -28,9 +28,9 @@ memcmp2 (const char *s1, size_t n1, const char *s2, size_t n2) if (cmp == 0) { if (n1 < n2) - cmp = -1; + cmp = -1; else if (n1 > n2) - cmp = 1; + cmp = 1; } return cmp; } diff --git a/lib/memcoll.c b/lib/memcoll.c index 9d0c434c2..3c798dfc7 100644 --- a/lib/memcoll.c +++ b/lib/memcoll.c @@ -54,29 +54,29 @@ memcoll (char *s1, size_t s1len, char *s2, size_t s2len) s2[s2len++] = '\0'; while (! (errno = 0, (diff = strcoll (s1, s2)) || errno)) - { - /* strcoll found no difference, but perhaps it was fooled by NUL - characters in the data. Work around this problem by advancing - past the NUL chars. */ - size_t size1 = strlen (s1) + 1; - size_t size2 = strlen (s2) + 1; - s1 += size1; - s2 += size2; - s1len -= size1; - s2len -= size2; - - if (s1len == 0) - { - if (s2len != 0) - diff = -1; - break; - } - else if (s2len == 0) - { - diff = 1; - break; - } - } + { + /* strcoll found no difference, but perhaps it was fooled by NUL + characters in the data. Work around this problem by advancing + past the NUL chars. */ + size_t size1 = strlen (s1) + 1; + size_t size2 = strlen (s2) + 1; + s1 += size1; + s2 += size2; + s1len -= size1; + s2len -= size2; + + if (s1len == 0) + { + if (s2len != 0) + diff = -1; + break; + } + else if (s2len == 0) + { + diff = 1; + break; + } + } s1[s1len - 1] = n1; s2[s2len - 1] = n2; diff --git a/lib/memmem.c b/lib/memmem.c index 186d84009..df7df4513 100644 --- a/lib/memmem.c +++ b/lib/memmem.c @@ -38,7 +38,7 @@ HAYSTACK. */ void * memmem (const void *haystack_start, size_t haystack_len, - const void *needle_start, size_t needle_len) + const void *needle_start, size_t needle_len) { /* 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. */ @@ -63,10 +63,10 @@ memmem (const void *haystack_start, size_t haystack_len, { haystack = memchr (haystack, *needle, haystack_len); if (!haystack || __builtin_expect (needle_len == 1, 0)) - return (void *) haystack; + return (void *) haystack; haystack_len -= haystack - (const unsigned char *) haystack_start; if (haystack_len < needle_len) - return NULL; + return NULL; return two_way_short_needle (haystack, haystack_len, needle, needle_len); } else diff --git a/lib/memmove.c b/lib/memmove.c index c5ff8b520..0f040540c 100644 --- a/lib/memmove.c +++ b/lib/memmove.c @@ -20,7 +20,7 @@ memmove (void *dest0, void const *source0, size_t length) { /* Moving from hi mem to low mem; start at beginning. */ for (; length; --length) - *dest++ = *source++; + *dest++ = *source++; } return dest0; } diff --git a/lib/memrchr.c b/lib/memrchr.c index da93ca0ba..f9c7683e8 100644 --- a/lib/memrchr.c +++ b/lib/memrchr.c @@ -84,15 +84,15 @@ __memrchr (void const *s, int c_in, size_t n) 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; - } - } + { + 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 @@ -131,11 +131,11 @@ __memrchr (void const *s, int c_in, size_t n) longword longword1 = *--longword_ptr ^ repeated_c; if ((((longword1 - repeated_one) & ~longword1) - & (repeated_one << 7)) != 0) - { - longword_ptr++; - break; - } + & (repeated_one << 7)) != 0) + { + longword_ptr++; + break; + } n -= sizeof (longword); } @@ -151,7 +151,7 @@ __memrchr (void const *s, int c_in, size_t n) while (n-- > 0) { if (*--char_ptr == c) - return (void *) char_ptr; + return (void *) char_ptr; } return NULL; diff --git a/lib/memxfrm.c b/lib/memxfrm.c index dc6eda1fa..9b89f9469 100644 --- a/lib/memxfrm.c +++ b/lib/memxfrm.c @@ -45,7 +45,7 @@ memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp) allocated = (n > 0 ? n : 1); result = (char *) malloc (allocated); if (result == NULL) - goto out_of_memory_2; + goto out_of_memory_2; } length = 0; @@ -63,44 +63,44 @@ memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp) p = s; for (;;) { - /* Search next NUL byte. */ - const char *q = p + strlen (p); - - for (;;) - { - size_t k; - - errno = 0; - k = strxfrm (result + length, p, allocated - length); - if (errno != 0) - goto fail; - if (k >= allocated - length) - { - /* Grow the result buffer. */ - char *new_result; - - allocated = 2 * allocated; - if (allocated < 64) - allocated = 64; - if (result == resultbuf) - new_result = (char *) malloc (allocated); - else - new_result = (char *) realloc (result, allocated); - if (new_result == NULL) - goto out_of_memory_1; - result = new_result; - } - else - { - length += k; - break; - } - } - - p = q + 1; - if (p == p_end) - break; - result[length] = '\0'; + /* Search next NUL byte. */ + const char *q = p + strlen (p); + + for (;;) + { + size_t k; + + errno = 0; + k = strxfrm (result + length, p, allocated - length); + if (errno != 0) + goto fail; + if (k >= allocated - length) + { + /* Grow the result buffer. */ + char *new_result; + + allocated = 2 * allocated; + if (allocated < 64) + allocated = 64; + if (result == resultbuf) + new_result = (char *) malloc (allocated); + else + new_result = (char *) realloc (result, allocated); + if (new_result == NULL) + goto out_of_memory_1; + result = new_result; + } + else + { + length += k; + break; + } + } + + p = q + 1; + if (p == p_end) + break; + result[length] = '\0'; length++; } } @@ -110,7 +110,7 @@ memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp) { char *memory = (char *) realloc (result, length > 0 ? length : 1); if (memory != NULL) - result = memory; + result = memory; } s[n] = orig_sentinel; diff --git a/lib/mkancesdirs.c b/lib/mkancesdirs.c index e44cf3e05..b96dd8b76 100644 --- a/lib/mkancesdirs.c +++ b/lib/mkancesdirs.c @@ -65,8 +65,8 @@ ptrdiff_t mkancesdirs (char *file, struct savewd *wd, - int (*make_dir) (char const *, char const *, void *), - void *make_dir_arg) + int (*make_dir) (char const *, char const *, void *), + void *make_dir_arg) { /* Address of the previous directory separator that follows an ordinary byte in a file name in the left-to-right scan, or NULL @@ -90,63 +90,63 @@ mkancesdirs (char *file, struct savewd *wd, while ((c = *p++)) if (ISSLASH (*p)) { - if (! ISSLASH (c)) - sep = p; + if (! ISSLASH (c)) + sep = p; } else if (ISSLASH (c) && *p && sep) { - /* Don't bother to make or test for "." since it does not - affect the algorithm. */ - if (! (sep - component == 1 && component[0] == '.')) - { - int make_dir_errno = 0; - int savewd_chdir_options = 0; - int chdir_result; - - /* Temporarily modify FILE to isolate this file name - component. */ - *sep = '\0'; - - /* Invoke MAKE_DIR on this component, except don't bother - with ".." since it must exist if its "parent" does. */ - if (sep - component == 2 - && component[0] == '.' && component[1] == '.') - made_dir = false; - else - switch (make_dir (file, component, make_dir_arg)) - { - case -1: - make_dir_errno = errno; - break; - - case 0: - savewd_chdir_options |= SAVEWD_CHDIR_READABLE; - /* Fall through. */ - case 1: - made_dir = true; - break; - } - - if (made_dir) - savewd_chdir_options |= SAVEWD_CHDIR_NOFOLLOW; - - chdir_result = - savewd_chdir (wd, component, savewd_chdir_options, NULL); - - /* Undo the temporary modification to FILE, unless there - was a failure. */ - if (chdir_result != -1) - *sep = '/'; - - if (chdir_result != 0) - { - if (make_dir_errno != 0 && errno == ENOENT) - errno = make_dir_errno; - return chdir_result; - } - } - - component = p; + /* Don't bother to make or test for "." since it does not + affect the algorithm. */ + if (! (sep - component == 1 && component[0] == '.')) + { + int make_dir_errno = 0; + int savewd_chdir_options = 0; + int chdir_result; + + /* Temporarily modify FILE to isolate this file name + component. */ + *sep = '\0'; + + /* Invoke MAKE_DIR on this component, except don't bother + with ".." since it must exist if its "parent" does. */ + if (sep - component == 2 + && component[0] == '.' && component[1] == '.') + made_dir = false; + else + switch (make_dir (file, component, make_dir_arg)) + { + case -1: + make_dir_errno = errno; + break; + + case 0: + savewd_chdir_options |= SAVEWD_CHDIR_READABLE; + /* Fall through. */ + case 1: + made_dir = true; + break; + } + + if (made_dir) + savewd_chdir_options |= SAVEWD_CHDIR_NOFOLLOW; + + chdir_result = + savewd_chdir (wd, component, savewd_chdir_options, NULL); + + /* Undo the temporary modification to FILE, unless there + was a failure. */ + if (chdir_result != -1) + *sep = '/'; + + if (chdir_result != 0) + { + if (make_dir_errno != 0 && errno == ENOENT) + errno = make_dir_errno; + return chdir_result; + } + } + + component = p; } return component - file; diff --git a/lib/mkancesdirs.h b/lib/mkancesdirs.h index 08fb50cbd..5f7b2d642 100644 --- a/lib/mkancesdirs.h +++ b/lib/mkancesdirs.h @@ -1,4 +1,4 @@ #include struct savewd; ptrdiff_t mkancesdirs (char *, struct savewd *, - int (*) (char const *, char const *, void *), void *); + int (*) (char const *, char const *, void *), void *); diff --git a/lib/mkdir-p.c b/lib/mkdir-p.c index f38dbc71f..39979a8b3 100644 --- a/lib/mkdir-p.c +++ b/lib/mkdir-p.c @@ -84,15 +84,15 @@ bool make_dir_parents (char *dir, - struct savewd *wd, - int (*make_ancestor) (char const *, char const *, void *), - void *options, - mode_t mode, - void (*announce) (char const *, void *), - mode_t mode_bits, - uid_t owner, - gid_t group, - bool preserve_existing) + struct savewd *wd, + int (*make_ancestor) (char const *, char const *, void *), + void *options, + mode_t mode, + void (*announce) (char const *, void *), + mode_t mode_bits, + uid_t owner, + gid_t group, + bool preserve_existing) { int mkdir_errno = (IS_ABSOLUTE_FILE_NAME (dir) ? 0 : savewd_errno (wd)); @@ -102,105 +102,105 @@ make_dir_parents (char *dir, int savewd_chdir_options = (HAVE_FCHMOD ? SAVEWD_CHDIR_SKIP_READABLE : 0); if (make_ancestor) - { - prefix_len = mkancesdirs (dir, wd, make_ancestor, options); - if (prefix_len < 0) - { - if (prefix_len < -1) - return true; - mkdir_errno = errno; - } - } + { + prefix_len = mkancesdirs (dir, wd, make_ancestor, options); + if (prefix_len < 0) + { + if (prefix_len < -1) + return true; + mkdir_errno = errno; + } + } if (0 <= prefix_len) - { - /* If the ownership might change, or if the directory will be - writeable to other users and its special mode bits may - change after the directory is created, create it with - more restrictive permissions at first, so unauthorized - users cannot nip in before the directory is ready. */ - bool keep_owner = owner == (uid_t) -1 && group == (gid_t) -1; - bool keep_special_mode_bits = - ((mode_bits & (S_ISUID | S_ISGID)) | (mode & S_ISVTX)) == 0; - mode_t mkdir_mode = mode; - if (! keep_owner) - mkdir_mode &= ~ (S_IRWXG | S_IRWXO); - else if (! keep_special_mode_bits) - mkdir_mode &= ~ (S_IWGRP | S_IWOTH); - - if (mkdir (dir + prefix_len, mkdir_mode) == 0) - { - announce (dir, options); - preserve_existing = keep_owner & keep_special_mode_bits; - savewd_chdir_options |= - (SAVEWD_CHDIR_NOFOLLOW - | (mode & S_IRUSR ? SAVEWD_CHDIR_READABLE : 0)); - } - else - { - mkdir_errno = errno; - mkdir_mode = -1; - } - - if (preserve_existing) - { - struct stat st; - if (mkdir_errno == 0 - || (mkdir_errno != ENOENT && make_ancestor - && stat (dir + prefix_len, &st) == 0 - && S_ISDIR (st.st_mode))) - return true; - } - else - { - int open_result[2]; - int chdir_result = - savewd_chdir (wd, dir + prefix_len, - savewd_chdir_options, open_result); - if (chdir_result < -1) - return true; - else - { - bool chdir_ok = (chdir_result == 0); - int chdir_errno = errno; - int fd = open_result[0]; - bool chdir_failed_unexpectedly = - (mkdir_errno == 0 - && ((! chdir_ok && (mode & S_IXUSR)) - || (fd < 0 && (mode & S_IRUSR)))); - - if (chdir_failed_unexpectedly) - { - /* No need to save errno here; it's irrelevant. */ - if (0 <= fd) - close (fd); - } - else - { - char const *subdir = (chdir_ok ? "." : dir + prefix_len); - if (dirchownmod (fd, subdir, mkdir_mode, owner, group, - mode, mode_bits) - == 0) - return true; - } - - if (mkdir_errno == 0 - || (mkdir_errno != ENOENT && make_ancestor - && errno != ENOTDIR)) - { - error (0, - (! chdir_failed_unexpectedly ? errno - : ! chdir_ok && (mode & S_IXUSR) ? chdir_errno - : open_result[1]), - _(keep_owner - ? "cannot change permissions of %s" - : "cannot change owner and permissions of %s"), - quote (dir)); - return false; - } - } - } - } + { + /* If the ownership might change, or if the directory will be + writeable to other users and its special mode bits may + change after the directory is created, create it with + more restrictive permissions at first, so unauthorized + users cannot nip in before the directory is ready. */ + bool keep_owner = owner == (uid_t) -1 && group == (gid_t) -1; + bool keep_special_mode_bits = + ((mode_bits & (S_ISUID | S_ISGID)) | (mode & S_ISVTX)) == 0; + mode_t mkdir_mode = mode; + if (! keep_owner) + mkdir_mode &= ~ (S_IRWXG | S_IRWXO); + else if (! keep_special_mode_bits) + mkdir_mode &= ~ (S_IWGRP | S_IWOTH); + + if (mkdir (dir + prefix_len, mkdir_mode) == 0) + { + announce (dir, options); + preserve_existing = keep_owner & keep_special_mode_bits; + savewd_chdir_options |= + (SAVEWD_CHDIR_NOFOLLOW + | (mode & S_IRUSR ? SAVEWD_CHDIR_READABLE : 0)); + } + else + { + mkdir_errno = errno; + mkdir_mode = -1; + } + + if (preserve_existing) + { + struct stat st; + if (mkdir_errno == 0 + || (mkdir_errno != ENOENT && make_ancestor + && stat (dir + prefix_len, &st) == 0 + && S_ISDIR (st.st_mode))) + return true; + } + else + { + int open_result[2]; + int chdir_result = + savewd_chdir (wd, dir + prefix_len, + savewd_chdir_options, open_result); + if (chdir_result < -1) + return true; + else + { + bool chdir_ok = (chdir_result == 0); + int chdir_errno = errno; + int fd = open_result[0]; + bool chdir_failed_unexpectedly = + (mkdir_errno == 0 + && ((! chdir_ok && (mode & S_IXUSR)) + || (fd < 0 && (mode & S_IRUSR)))); + + if (chdir_failed_unexpectedly) + { + /* No need to save errno here; it's irrelevant. */ + if (0 <= fd) + close (fd); + } + else + { + char const *subdir = (chdir_ok ? "." : dir + prefix_len); + if (dirchownmod (fd, subdir, mkdir_mode, owner, group, + mode, mode_bits) + == 0) + return true; + } + + if (mkdir_errno == 0 + || (mkdir_errno != ENOENT && make_ancestor + && errno != ENOTDIR)) + { + error (0, + (! chdir_failed_unexpectedly ? errno + : ! chdir_ok && (mode & S_IXUSR) ? chdir_errno + : open_result[1]), + _(keep_owner + ? "cannot change permissions of %s" + : "cannot change owner and permissions of %s"), + quote (dir)); + return false; + } + } + } + } } error (0, mkdir_errno, _("cannot create directory %s"), quote (dir)); diff --git a/lib/mkdir-p.h b/lib/mkdir-p.h index 487e6ebeb..8cb9fc248 100644 --- a/lib/mkdir-p.h +++ b/lib/mkdir-p.h @@ -23,13 +23,13 @@ struct savewd; bool make_dir_parents (char *dir, - struct savewd *wd, - int (*make_ancestor) (char const *, char const *, - void *), - void *options, - mode_t mode, - void (*announce) (char const *, void *), - mode_t mode_bits, - uid_t owner, - gid_t group, - bool preserve_existing); + struct savewd *wd, + int (*make_ancestor) (char const *, char const *, + void *), + void *options, + mode_t mode, + void (*announce) (char const *, void *), + mode_t mode_bits, + uid_t owner, + gid_t group, + bool preserve_existing); diff --git a/lib/mktime.c b/lib/mktime.c index b9b961ffd..5ae519312 100644 --- a/lib/mktime.c +++ b/lib/mktime.c @@ -36,7 +36,7 @@ #include -#include /* For the real memcpy prototype. */ +#include /* For the real memcpy prototype. */ #if DEBUG # include @@ -55,9 +55,9 @@ implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift right in the usual way when A < 0, so SHR falls back on division if ordinary A >> B doesn't seem to be the usual signed shift. */ -#define SHR(a, b) \ - (-1 >> 1 == -1 \ - ? (a) >> (b) \ +#define SHR(a, b) \ + (-1 >> 1 == -1 \ + ? (a) >> (b) \ : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) /* The extra casts in the following macros work around compiler bugs, @@ -84,14 +84,14 @@ your host. */ #define TYPE_MINIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ - ? (t) 0 \ - : TYPE_SIGNED_MAGNITUDE (t) \ - ? ~ (t) 0 \ - : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) + ? (t) 0 \ + : TYPE_SIGNED_MAGNITUDE (t) \ + ? ~ (t) 0 \ + : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) #define TYPE_MAXIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ - ? (t) -1 \ - : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) + ? (t) -1 \ + : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) #ifndef TIME_T_MIN # define TIME_T_MIN TYPE_MINIMUM (time_t) @@ -123,7 +123,7 @@ leapyear (long int year) return ((year & 3) == 0 && (year % 100 != 0 - || ((year / 100) & 3) == (- (TM_YEAR_BASE / 100) & 3))); + || ((year / 100) & 3) == (- (TM_YEAR_BASE / 100) & 3))); } /* How many days come before each month (0-12). */ @@ -163,13 +163,13 @@ const unsigned short int __mon_yday[2][13] = static inline time_t ydhms_diff (long int year1, long int yday1, int hour1, int min1, int sec1, - int year0, int yday0, int hour0, int min0, int sec0) + int year0, int yday0, int hour0, int min0, int sec0) { verify (C99_integer_division, -1 / 2 == 0); #if 0 /* This assertion fails on 32-bit systems with 64-bit time_t, such as NetBSD 5 on i386. */ verify (long_int_year_and_yday_are_wide_enough, - INT_MAX <= LONG_MAX / 2 || TIME_T_MAX <= UINT_MAX); + INT_MAX <= LONG_MAX / 2 || TIME_T_MAX <= UINT_MAX); #endif /* Compute intervening leap days correctly even if year is negative. @@ -202,16 +202,16 @@ ydhms_diff (long int year1, long int yday1, int hour1, int min1, int sec1, yield a value equal to *T. */ static time_t guess_time_tm (long int year, long int yday, int hour, int min, int sec, - const time_t *t, const struct tm *tp) + const time_t *t, const struct tm *tp) { if (tp) { time_t d = ydhms_diff (year, yday, hour, min, sec, - tp->tm_year, tp->tm_yday, - tp->tm_hour, tp->tm_min, tp->tm_sec); + tp->tm_year, tp->tm_yday, + tp->tm_hour, tp->tm_min, tp->tm_sec); time_t t1 = *t + d; if ((t1 < *t) == (TYPE_SIGNED (time_t) ? d < 0 : TIME_T_MAX / 2 < d)) - return t1; + return t1; } /* Overflow occurred one way or another. Return the nearest result @@ -220,8 +220,8 @@ guess_time_tm (long int year, long int yday, int hour, int min, int sec, match; and don't oscillate between two values, as that would confuse the spring-forward gap detector. */ return (*t < TIME_T_MIDPOINT - ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN) - : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX)); + ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN) + : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX)); } /* Use CONVERT to convert *T to a broken down time in *TP. @@ -229,7 +229,7 @@ guess_time_tm (long int year, long int yday, int hour, int min, int sec, it is the nearest in-range value and then convert that. */ static struct tm * ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), - time_t *t, struct tm *tp) + time_t *t, struct tm *tp) { struct tm *r = convert (t, tp); @@ -239,27 +239,27 @@ ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), time_t ok = 0; /* BAD is a known unconvertible time_t, and OK is a known good one. - Use binary search to narrow the range between BAD and OK until - they differ by 1. */ + Use binary search to narrow the range between BAD and OK until + they differ by 1. */ while (bad != ok + (bad < 0 ? -1 : 1)) - { - time_t mid = *t = (bad < 0 - ? bad + ((ok - bad) >> 1) - : ok + ((bad - ok) >> 1)); - r = convert (t, tp); - if (r) - ok = mid; - else - bad = mid; - } + { + time_t mid = *t = (bad < 0 + ? bad + ((ok - bad) >> 1) + : ok + ((bad - ok) >> 1)); + r = convert (t, tp); + if (r) + ok = mid; + else + bad = mid; + } if (!r && ok) - { - /* The last conversion attempt failed; - revert to the most recent successful attempt. */ - *t = ok; - r = convert (t, tp); - } + { + /* The last conversion attempt failed; + revert to the most recent successful attempt. */ + *t = ok; + r = convert (t, tp); + } } return r; @@ -274,8 +274,8 @@ ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), This function is external because it is used also by timegm.c. */ time_t __mktime_internal (struct tm *tp, - struct tm *(*convert) (const time_t *, struct tm *), - time_t *offset) + struct tm *(*convert) (const time_t *, struct tm *), + time_t *offset) { time_t t, gt, t0, t1, t2; struct tm tm; @@ -296,7 +296,7 @@ __mktime_internal (struct tm *tp, int year_requested = tp->tm_year; /* Normalize the value. */ int isdst = ((tp->tm_isdst >> (8 * sizeof (tp->tm_isdst) - 1)) - | (tp->tm_isdst != 0)); + | (tp->tm_isdst != 0)); /* 1 if the previous probe was DST. */ int dst2; @@ -316,8 +316,8 @@ __mktime_internal (struct tm *tp, /* Calculate day of year from year, month, and day of month. The result need not be in range. */ int mon_yday = ((__mon_yday[leapyear (year)] - [mon_remainder + 12 * negative_mon_remainder]) - - 1); + [mon_remainder + 12 * negative_mon_remainder]) + - 1); long int lmday = mday; long int yday = mon_yday + lmday; @@ -328,33 +328,33 @@ __mktime_internal (struct tm *tp, if (LEAP_SECONDS_POSSIBLE) { /* Handle out-of-range seconds specially, - since ydhms_tm_diff assumes every minute has 60 seconds. */ + since ydhms_tm_diff assumes every minute has 60 seconds. */ if (sec < 0) - sec = 0; + sec = 0; if (59 < sec) - sec = 59; + sec = 59; } /* Invert CONVERT by probing. First assume the same offset as last time. */ t0 = ydhms_diff (year, yday, hour, min, sec, - EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset); + EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset); if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3) { /* time_t isn't large enough to rule out overflows, so check - for major overflows. A gross check suffices, since if t0 - has overflowed, it is off by a multiple of TIME_T_MAX - - TIME_T_MIN + 1. So ignore any component of the difference - that is bounded by a small value. */ + for major overflows. A gross check suffices, since if t0 + has overflowed, it is off by a multiple of TIME_T_MAX - + TIME_T_MIN + 1. So ignore any component of the difference + that is bounded by a small value. */ /* Approximate log base 2 of the number of time units per - biennium. A biennium is 2 years; use this unit instead of - years to avoid integer overflow. For example, 2 average - Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds, - which is 63113904 seconds, and rint (log2 (63113904)) is - 26. */ + biennium. A biennium is 2 years; use this unit instead of + years to avoid integer overflow. For example, 2 average + Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds, + which is 63113904 seconds, and rint (log2 (63113904)) is + 26. */ int ALOG2_SECONDS_PER_BIENNIUM = 26; int ALOG2_MINUTES_PER_BIENNIUM = 20; int ALOG2_HOURS_PER_BIENNIUM = 14; @@ -362,64 +362,64 @@ __mktime_internal (struct tm *tp, int LOG2_YEARS_PER_BIENNIUM = 1; int approx_requested_biennia = - (SHR (year_requested, LOG2_YEARS_PER_BIENNIUM) - - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM) - + SHR (mday, ALOG2_DAYS_PER_BIENNIUM) - + SHR (hour, ALOG2_HOURS_PER_BIENNIUM) - + SHR (min, ALOG2_MINUTES_PER_BIENNIUM) - + (LEAP_SECONDS_POSSIBLE - ? 0 - : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM))); + (SHR (year_requested, LOG2_YEARS_PER_BIENNIUM) + - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM) + + SHR (mday, ALOG2_DAYS_PER_BIENNIUM) + + SHR (hour, ALOG2_HOURS_PER_BIENNIUM) + + SHR (min, ALOG2_MINUTES_PER_BIENNIUM) + + (LEAP_SECONDS_POSSIBLE + ? 0 + : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM))); int approx_biennia = SHR (t0, ALOG2_SECONDS_PER_BIENNIUM); int diff = approx_biennia - approx_requested_biennia; int abs_diff = diff < 0 ? - diff : diff; /* IRIX 4.0.5 cc miscaculates TIME_T_MIN / 3: it erroneously - gives a positive value of 715827882. Setting a variable - first then doing math on it seems to work. - (ghazi@caip.rutgers.edu) */ + gives a positive value of 715827882. Setting a variable + first then doing math on it seems to work. + (ghazi@caip.rutgers.edu) */ time_t time_t_max = TIME_T_MAX; time_t time_t_min = TIME_T_MIN; time_t overflow_threshold = - (time_t_max / 3 - time_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM; + (time_t_max / 3 - time_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM; if (overflow_threshold < abs_diff) - { - /* Overflow occurred. Try repairing it; this might work if - the time zone offset is enough to undo the overflow. */ - time_t repaired_t0 = -1 - t0; - approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM); - diff = approx_biennia - approx_requested_biennia; - abs_diff = diff < 0 ? - diff : diff; - if (overflow_threshold < abs_diff) - return -1; - guessed_offset += repaired_t0 - t0; - t0 = repaired_t0; - } + { + /* Overflow occurred. Try repairing it; this might work if + the time zone offset is enough to undo the overflow. */ + time_t repaired_t0 = -1 - t0; + approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM); + diff = approx_biennia - approx_requested_biennia; + abs_diff = diff < 0 ? - diff : diff; + if (overflow_threshold < abs_diff) + return -1; + guessed_offset += repaired_t0 - t0; + t0 = repaired_t0; + } } /* Repeatedly use the error to improve the guess. */ for (t = t1 = t2 = t0, dst2 = 0; (gt = guess_time_tm (year, yday, hour, min, sec, &t, - ranged_convert (convert, &t, &tm)), - t != gt); + ranged_convert (convert, &t, &tm)), + t != gt); t1 = t2, t2 = t, t = gt, dst2 = tm.tm_isdst != 0) if (t == t1 && t != t2 - && (tm.tm_isdst < 0 - || (isdst < 0 - ? dst2 <= (tm.tm_isdst != 0) - : (isdst != 0) != (tm.tm_isdst != 0)))) + && (tm.tm_isdst < 0 + || (isdst < 0 + ? dst2 <= (tm.tm_isdst != 0) + : (isdst != 0) != (tm.tm_isdst != 0)))) /* We can't possibly find a match, as we are oscillating - between two values. The requested time probably falls - within a spring-forward gap of size GT - T. Follow the common - practice in this case, which is to return a time that is GT - T - away from the requested time, preferring a time whose - tm_isdst differs from the requested value. (If no tm_isdst - was requested and only one of the two values has a nonzero - tm_isdst, prefer that value.) In practice, this is more - useful than returning -1. */ + between two values. The requested time probably falls + within a spring-forward gap of size GT - T. Follow the common + practice in this case, which is to return a time that is GT - T + away from the requested time, preferring a time whose + tm_isdst differs from the requested value. (If no tm_isdst + was requested and only one of the two values has a nonzero + tm_isdst, prefer that value.) In practice, this is more + useful than returning -1. */ goto offset_found; else if (--remaining_probes == 0) return -1; @@ -429,52 +429,52 @@ __mktime_internal (struct tm *tp, if (isdst != tm.tm_isdst && 0 <= isdst && 0 <= tm.tm_isdst) { /* tm.tm_isdst has the wrong value. Look for a neighboring - time with the right value, and use its UTC offset. + time with the right value, and use its UTC offset. - Heuristic: probe the adjacent timestamps in both directions, - looking for the desired isdst. This should work for all real - time zone histories in the tz database. */ + Heuristic: probe the adjacent timestamps in both directions, + looking for the desired isdst. This should work for all real + time zone histories in the tz database. */ /* Distance between probes when looking for a DST boundary. In - tzdata2003a, the shortest period of DST is 601200 seconds - (e.g., America/Recife starting 2000-10-08 01:00), and the - shortest period of non-DST surrounded by DST is 694800 - seconds (Africa/Tunis starting 1943-04-17 01:00). Use the - minimum of these two values, so we don't miss these short - periods when probing. */ + tzdata2003a, the shortest period of DST is 601200 seconds + (e.g., America/Recife starting 2000-10-08 01:00), and the + shortest period of non-DST surrounded by DST is 694800 + seconds (Africa/Tunis starting 1943-04-17 01:00). Use the + minimum of these two values, so we don't miss these short + periods when probing. */ int stride = 601200; /* The longest period of DST in tzdata2003a is 536454000 seconds - (e.g., America/Jujuy starting 1946-10-01 01:00). The longest - period of non-DST is much longer, but it makes no real sense - to search for more than a year of non-DST, so use the DST - max. */ + (e.g., America/Jujuy starting 1946-10-01 01:00). The longest + period of non-DST is much longer, but it makes no real sense + to search for more than a year of non-DST, so use the DST + max. */ int duration_max = 536454000; /* Search in both directions, so the maximum distance is half - the duration; add the stride to avoid off-by-1 problems. */ + the duration; add the stride to avoid off-by-1 problems. */ int delta_bound = duration_max / 2 + stride; int delta, direction; for (delta = stride; delta < delta_bound; delta += stride) - for (direction = -1; direction <= 1; direction += 2) - { - time_t ot = t + delta * direction; - if ((ot < t) == (direction < 0)) - { - struct tm otm; - ranged_convert (convert, &ot, &otm); - if (otm.tm_isdst == isdst) - { - /* We found the desired tm_isdst. - Extrapolate back to the desired time. */ - t = guess_time_tm (year, yday, hour, min, sec, &ot, &otm); - ranged_convert (convert, &t, &tm); - goto offset_found; - } - } - } + for (direction = -1; direction <= 1; direction += 2) + { + time_t ot = t + delta * direction; + if ((ot < t) == (direction < 0)) + { + struct tm otm; + ranged_convert (convert, &ot, &otm); + if (otm.tm_isdst == isdst) + { + /* We found the desired tm_isdst. + Extrapolate back to the desired time. */ + t = guess_time_tm (year, yday, hour, min, sec, &ot, &otm); + ranged_convert (convert, &t, &tm); + goto offset_found; + } + } + } } offset_found: @@ -483,14 +483,14 @@ __mktime_internal (struct tm *tp, if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) { /* Adjust time to reflect the tm_sec requested, not the normalized value. - Also, repair any damage from a false match due to a leap second. */ + Also, repair any damage from a false match due to a leap second. */ int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec; t1 = t + sec_requested; t2 = t1 + sec_adjustment; if (((t1 < t) != (sec_requested < 0)) - | ((t2 < t1) != (sec_adjustment < 0)) - | ! convert (&t2, &tm)) - return -1; + | ((t2 < t1) != (sec_adjustment < 0)) + | ! convert (&t2, &tm)) + return -1; t = t2; } @@ -534,13 +534,13 @@ static int not_equal_tm (const struct tm *a, const struct tm *b) { return ((a->tm_sec ^ b->tm_sec) - | (a->tm_min ^ b->tm_min) - | (a->tm_hour ^ b->tm_hour) - | (a->tm_mday ^ b->tm_mday) - | (a->tm_mon ^ b->tm_mon) - | (a->tm_year ^ b->tm_year) - | (a->tm_yday ^ b->tm_yday) - | (a->tm_isdst ^ b->tm_isdst)); + | (a->tm_min ^ b->tm_min) + | (a->tm_hour ^ b->tm_hour) + | (a->tm_mday ^ b->tm_mday) + | (a->tm_mon ^ b->tm_mon) + | (a->tm_year ^ b->tm_year) + | (a->tm_yday ^ b->tm_yday) + | (a->tm_isdst ^ b->tm_isdst)); } static void @@ -548,9 +548,9 @@ print_tm (const struct tm *tp) { if (tp) printf ("%04d-%02d-%02d %02d:%02d:%02d yday %03d wday %d isdst %d", - tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday, - tp->tm_hour, tp->tm_min, tp->tm_sec, - tp->tm_yday, tp->tm_wday, tp->tm_isdst); + tp->tm_year + TM_YEAR_BASE, tp->tm_mon + 1, tp->tm_mday, + tp->tm_hour, tp->tm_min, tp->tm_sec, + tp->tm_yday, tp->tm_wday, tp->tm_isdst); else printf ("0"); } @@ -582,11 +582,11 @@ main (int argc, char **argv) if ((argc == 3 || argc == 4) && (sscanf (argv[1], "%d-%d-%d%c", - &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer) - == 3) + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer) + == 3) && (sscanf (argv[2], "%d:%d:%d%c", - &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer) - == 3)) + &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &trailer) + == 3)) { tm.tm_year -= TM_YEAR_BASE; tm.tm_mon--; @@ -595,10 +595,10 @@ main (int argc, char **argv) tl = mktime (&tmk); lt = localtime (&tl); if (lt) - { - tml = *lt; - lt = &tml; - } + { + tml = *lt; + lt = &tml; + } printf ("mktime returns %ld == ", (long int) tl); print_tm (&tmk); printf ("\n"); @@ -611,51 +611,51 @@ main (int argc, char **argv) time_t to = atol (argv[3]); if (argc == 4) - for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) - { - lt = localtime (&tl); - if (lt) - { - tmk = tml = *lt; - tk = mktime (&tmk); - status |= check_result (tk, tmk, tl, &tml); - } - else - { - printf ("localtime (%ld) yields 0\n", (long int) tl); - status = 1; - } - tl1 = tl + by; - if ((tl1 < tl) != (by < 0)) - break; - } + for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) + { + lt = localtime (&tl); + if (lt) + { + tmk = tml = *lt; + tk = mktime (&tmk); + status |= check_result (tk, tmk, tl, &tml); + } + else + { + printf ("localtime (%ld) yields 0\n", (long int) tl); + status = 1; + } + tl1 = tl + by; + if ((tl1 < tl) != (by < 0)) + break; + } else - for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) - { - /* Null benchmark. */ - lt = localtime (&tl); - if (lt) - { - tmk = tml = *lt; - tk = tl; - status |= check_result (tk, tmk, tl, &tml); - } - else - { - printf ("localtime (%ld) yields 0\n", (long int) tl); - status = 1; - } - tl1 = tl + by; - if ((tl1 < tl) != (by < 0)) - break; - } + for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1) + { + /* Null benchmark. */ + lt = localtime (&tl); + if (lt) + { + tmk = tml = *lt; + tk = tl; + status |= check_result (tk, tmk, tl, &tml); + } + else + { + printf ("localtime (%ld) yields 0\n", (long int) tl); + status = 1; + } + tl1 = tl + by; + if ((tl1 < tl) != (by < 0)) + break; + } } else printf ("Usage:\ \t%s YYYY-MM-DD HH:MM:SS [ISDST] # Test given time.\n\ \t%s FROM BY TO # Test values FROM, FROM+BY, ..., TO.\n\ \t%s FROM BY TO - # Do not test those values (for benchmark).\n", - argv[0], argv[0], argv[0]); + argv[0], argv[0], argv[0]); return status; } diff --git a/lib/modechange.c b/lib/modechange.c index 1296717c5..80cb24b9f 100644 --- a/lib/modechange.c +++ b/lib/modechange.c @@ -56,22 +56,22 @@ octal_to_mode (unsigned int octal) /* Help the compiler optimize the usual case where mode_t uses the traditional octal representation. */ return ((S_ISUID == SUID && S_ISGID == SGID && S_ISVTX == SVTX - && S_IRUSR == RUSR && S_IWUSR == WUSR && S_IXUSR == XUSR - && S_IRGRP == RGRP && S_IWGRP == WGRP && S_IXGRP == XGRP - && S_IROTH == ROTH && S_IWOTH == WOTH && S_IXOTH == XOTH) - ? octal - : (mode_t) ((octal & SUID ? S_ISUID : 0) - | (octal & SGID ? S_ISGID : 0) - | (octal & SVTX ? S_ISVTX : 0) - | (octal & RUSR ? S_IRUSR : 0) - | (octal & WUSR ? S_IWUSR : 0) - | (octal & XUSR ? S_IXUSR : 0) - | (octal & RGRP ? S_IRGRP : 0) - | (octal & WGRP ? S_IWGRP : 0) - | (octal & XGRP ? S_IXGRP : 0) - | (octal & ROTH ? S_IROTH : 0) - | (octal & WOTH ? S_IWOTH : 0) - | (octal & XOTH ? S_IXOTH : 0))); + && S_IRUSR == RUSR && S_IWUSR == WUSR && S_IXUSR == XUSR + && S_IRGRP == RGRP && S_IWGRP == WGRP && S_IXGRP == XGRP + && S_IROTH == ROTH && S_IWOTH == WOTH && S_IXOTH == XOTH) + ? octal + : (mode_t) ((octal & SUID ? S_ISUID : 0) + | (octal & SGID ? S_ISGID : 0) + | (octal & SVTX ? S_ISVTX : 0) + | (octal & RUSR ? S_IRUSR : 0) + | (octal & WUSR ? S_IWUSR : 0) + | (octal & XUSR ? S_IXUSR : 0) + | (octal & RGRP ? S_IRGRP : 0) + | (octal & WGRP ? S_IWGRP : 0) + | (octal & XGRP ? S_IXGRP : 0) + | (octal & ROTH ? S_IROTH : 0) + | (octal & WOTH ? S_IWOTH : 0) + | (octal & XOTH ? S_IXOTH : 0))); } /* Special operations flags. */ @@ -97,11 +97,11 @@ enum /* Description of a mode change. */ struct mode_change { - char op; /* One of "=+-". */ - char flag; /* Special operations flag. */ - mode_t affected; /* Set for u, g, o, or a. */ - mode_t value; /* Bits to add/remove. */ - mode_t mentioned; /* Bits explicitly mentioned. */ + char op; /* One of "=+-". */ + char flag; /* Special operations flag. */ + mode_t affected; /* Set for u, g, o, or a. */ + mode_t value; /* Bits to add/remove. */ + mode_t mentioned; /* Bits explicitly mentioned. */ }; /* Return a mode_change array with the specified `=ddd'-style @@ -144,15 +144,15 @@ mode_compile (char const *mode_string) mode_t mentioned; do - { - octal_mode = 8 * octal_mode + *mode_string++ - '0'; - if (ALLM < octal_mode) - return NULL; - } + { + octal_mode = 8 * octal_mode + *mode_string++ - '0'; + if (ALLM < octal_mode) + return NULL; + } while ('0' <= *mode_string && *mode_string < '8'); if (*mode_string) - return NULL; + return NULL; mode = octal_to_mode (octal_mode); mentioned = (mode & (S_ISUID | S_ISGID)) | S_ISVTX | S_IRWXUGO; @@ -176,97 +176,97 @@ mode_compile (char const *mode_string) /* Turn on all the bits in `affected' for each group given. */ for (;; mode_string++) - switch (*mode_string) - { - default: - goto invalid; - case 'u': - affected |= S_ISUID | S_IRWXU; - break; - case 'g': - affected |= S_ISGID | S_IRWXG; - break; - case 'o': - affected |= S_ISVTX | S_IRWXO; - break; - case 'a': - affected |= CHMOD_MODE_BITS; - break; - case '=': case '+': case '-': - goto no_more_affected; - } + switch (*mode_string) + { + default: + goto invalid; + case 'u': + affected |= S_ISUID | S_IRWXU; + break; + case 'g': + affected |= S_ISGID | S_IRWXG; + break; + case 'o': + affected |= S_ISVTX | S_IRWXO; + break; + case 'a': + affected |= CHMOD_MODE_BITS; + break; + case '=': case '+': case '-': + goto no_more_affected; + } no_more_affected:; do - { - char op = *mode_string++; - mode_t value; - char flag = MODE_COPY_EXISTING; - struct mode_change *change; - - switch (*mode_string++) - { - case 'u': - /* Set the affected bits to the value of the `u' bits - on the same file. */ - value = S_IRWXU; - break; - case 'g': - /* Set the affected bits to the value of the `g' bits - on the same file. */ - value = S_IRWXG; - break; - case 'o': - /* Set the affected bits to the value of the `o' bits - on the same file. */ - value = S_IRWXO; - break; - - default: - value = 0; - flag = MODE_ORDINARY_CHANGE; - - for (mode_string--;; mode_string++) - switch (*mode_string) - { - case 'r': - value |= S_IRUSR | S_IRGRP | S_IROTH; - break; - case 'w': - value |= S_IWUSR | S_IWGRP | S_IWOTH; - break; - case 'x': - value |= S_IXUSR | S_IXGRP | S_IXOTH; - break; - case 'X': - flag = MODE_X_IF_ANY_X; - break; - case 's': - /* Set the setuid/gid bits if `u' or `g' is selected. */ - value |= S_ISUID | S_ISGID; - break; - case 't': - /* Set the "save text image" bit if `o' is selected. */ - value |= S_ISVTX; - break; - default: - goto no_more_values; - } - no_more_values:; - } - - change = &mc[used++]; - change->op = op; - change->flag = flag; - change->affected = affected; - change->value = value; - change->mentioned = (affected ? affected & value : value); - } + { + char op = *mode_string++; + mode_t value; + char flag = MODE_COPY_EXISTING; + struct mode_change *change; + + switch (*mode_string++) + { + case 'u': + /* Set the affected bits to the value of the `u' bits + on the same file. */ + value = S_IRWXU; + break; + case 'g': + /* Set the affected bits to the value of the `g' bits + on the same file. */ + value = S_IRWXG; + break; + case 'o': + /* Set the affected bits to the value of the `o' bits + on the same file. */ + value = S_IRWXO; + break; + + default: + value = 0; + flag = MODE_ORDINARY_CHANGE; + + for (mode_string--;; mode_string++) + switch (*mode_string) + { + case 'r': + value |= S_IRUSR | S_IRGRP | S_IROTH; + break; + case 'w': + value |= S_IWUSR | S_IWGRP | S_IWOTH; + break; + case 'x': + value |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + case 'X': + flag = MODE_X_IF_ANY_X; + break; + case 's': + /* Set the setuid/gid bits if `u' or `g' is selected. */ + value |= S_ISUID | S_ISGID; + break; + case 't': + /* Set the "save text image" bit if `o' is selected. */ + value |= S_ISVTX; + break; + default: + goto no_more_values; + } + no_more_values:; + } + + change = &mc[used++]; + change->op = op; + change->flag = flag; + change->affected = affected; + change->value = value; + change->mentioned = (affected ? affected & value : value); + } while (*mode_string == '=' || *mode_string == '+' - || *mode_string == '-'); + || *mode_string == '-'); if (*mode_string != ',') - break; + break; } if (*mode_string == 0) @@ -308,7 +308,7 @@ mode_create_from_ref (const char *ref_file) mode_t mode_adjust (mode_t oldmode, bool dir, mode_t umask_value, - struct mode_change const *changes, mode_t *pmode_bits) + struct mode_change const *changes, mode_t *pmode_bits) { /* The adjusted mode. */ mode_t newmode = oldmode & CHMOD_MODE_BITS; @@ -320,63 +320,63 @@ mode_adjust (mode_t oldmode, bool dir, mode_t umask_value, { mode_t affected = changes->affected; mode_t omit_change = - (dir ? S_ISUID | S_ISGID : 0) & ~ changes->mentioned; + (dir ? S_ISUID | S_ISGID : 0) & ~ changes->mentioned; mode_t value = changes->value; switch (changes->flag) - { - case MODE_ORDINARY_CHANGE: - break; - - case MODE_COPY_EXISTING: - /* Isolate in `value' the bits in `newmode' to copy. */ - value &= newmode; - - /* Copy the isolated bits to the other two parts. */ - value |= ((value & (S_IRUSR | S_IRGRP | S_IROTH) - ? S_IRUSR | S_IRGRP | S_IROTH : 0) - | (value & (S_IWUSR | S_IWGRP | S_IWOTH) - ? S_IWUSR | S_IWGRP | S_IWOTH : 0) - | (value & (S_IXUSR | S_IXGRP | S_IXOTH) - ? S_IXUSR | S_IXGRP | S_IXOTH : 0)); - break; - - case MODE_X_IF_ANY_X: - /* Affect the execute bits if execute bits are already set - or if the file is a directory. */ - if ((newmode & (S_IXUSR | S_IXGRP | S_IXOTH)) | dir) - value |= S_IXUSR | S_IXGRP | S_IXOTH; - break; - } + { + case MODE_ORDINARY_CHANGE: + break; + + case MODE_COPY_EXISTING: + /* Isolate in `value' the bits in `newmode' to copy. */ + value &= newmode; + + /* Copy the isolated bits to the other two parts. */ + value |= ((value & (S_IRUSR | S_IRGRP | S_IROTH) + ? S_IRUSR | S_IRGRP | S_IROTH : 0) + | (value & (S_IWUSR | S_IWGRP | S_IWOTH) + ? S_IWUSR | S_IWGRP | S_IWOTH : 0) + | (value & (S_IXUSR | S_IXGRP | S_IXOTH) + ? S_IXUSR | S_IXGRP | S_IXOTH : 0)); + break; + + case MODE_X_IF_ANY_X: + /* Affect the execute bits if execute bits are already set + or if the file is a directory. */ + if ((newmode & (S_IXUSR | S_IXGRP | S_IXOTH)) | dir) + value |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + } /* If WHO was specified, limit the change to the affected bits. - Otherwise, apply the umask. Either way, omit changes as - requested. */ + Otherwise, apply the umask. Either way, omit changes as + requested. */ value &= (affected ? affected : ~umask_value) & ~ omit_change; switch (changes->op) - { - case '=': - /* If WHO was specified, preserve the previous values of - bits that are not affected by this change operation. - Otherwise, clear all the bits. */ - { - mode_t preserved = (affected ? ~affected : 0) | omit_change; - mode_bits |= CHMOD_MODE_BITS & ~preserved; - newmode = (newmode & preserved) | value; - break; - } - - case '+': - mode_bits |= value; - newmode |= value; - break; - - case '-': - mode_bits |= value; - newmode &= ~value; - break; - } + { + case '=': + /* If WHO was specified, preserve the previous values of + bits that are not affected by this change operation. + Otherwise, clear all the bits. */ + { + mode_t preserved = (affected ? ~affected : 0) | omit_change; + mode_bits |= CHMOD_MODE_BITS & ~preserved; + newmode = (newmode & preserved) | value; + break; + } + + case '+': + mode_bits |= value; + newmode |= value; + break; + + case '-': + mode_bits |= value; + newmode &= ~value; + break; + } } if (pmode_bits) diff --git a/lib/modechange.h b/lib/modechange.h index f6f8e744d..a883af109 100644 --- a/lib/modechange.h +++ b/lib/modechange.h @@ -25,6 +25,6 @@ struct mode_change *mode_compile (const char *); struct mode_change *mode_create_from_ref (const char *); mode_t mode_adjust (mode_t, bool, mode_t, struct mode_change const *, - mode_t *); + mode_t *); #endif diff --git a/lib/mountlist.c b/lib/mountlist.c index 50e90eed4..8373eec4f 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -37,10 +37,10 @@ # include #endif -#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */ +#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */ # if HAVE_SYS_UCRED_H # include /* needed on OSF V4.0 for definition of NGROUPS, - NGROUPS is used as an array dimension in ucred.h */ + NGROUPS is used as an array dimension in ucred.h */ # include /* needed by powerpc-apple-darwin1.3.7 */ # endif # if HAVE_SYS_MOUNT_H @@ -56,44 +56,44 @@ # endif #endif /* MOUNTED_GETFSSTAT */ -#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ +#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ # include # if !defined MOUNTED -# if defined _PATH_MOUNTED /* GNU libc */ +# if defined _PATH_MOUNTED /* GNU libc */ # define MOUNTED _PATH_MOUNTED # endif -# if defined MNT_MNTTAB /* HP-UX. */ +# if defined MNT_MNTTAB /* HP-UX. */ # define MOUNTED MNT_MNTTAB # endif -# if defined MNTTABNAME /* Dynix. */ +# if defined MNTTABNAME /* Dynix. */ # define MOUNTED MNTTABNAME # endif # endif #endif -#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ +#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ # include #endif -#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ +#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ # include #endif -#ifdef MOUNTED_GETMNT /* Ultrix. */ +#ifdef MOUNTED_GETMNT /* Ultrix. */ # include # include #endif -#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */ +#ifdef MOUNTED_FS_STAT_DEV /* BeOS. */ # include # include #endif -#ifdef MOUNTED_FREAD /* SVR2. */ +#ifdef MOUNTED_FREAD /* SVR2. */ # include #endif -#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */ +#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */ # include # include # include @@ -103,11 +103,11 @@ # include #endif -#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ +#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ # include #endif -#ifdef MOUNTED_VMOUNT /* AIX. */ +#ifdef MOUNTED_VMOUNT /* AIX. */ # include # include #endif @@ -145,26 +145,26 @@ #undef closedir #ifndef ME_DUMMY -# define ME_DUMMY(Fs_name, Fs_type) \ - (strcmp (Fs_type, "autofs") == 0 \ - || strcmp (Fs_type, "none") == 0 \ - || strcmp (Fs_type, "proc") == 0 \ - || strcmp (Fs_type, "subfs") == 0 \ - /* for NetBSD 3.0 */ \ - || strcmp (Fs_type, "kernfs") == 0 \ - /* for Irix 6.5 */ \ +# define ME_DUMMY(Fs_name, Fs_type) \ + (strcmp (Fs_type, "autofs") == 0 \ + || strcmp (Fs_type, "none") == 0 \ + || strcmp (Fs_type, "proc") == 0 \ + || strcmp (Fs_type, "subfs") == 0 \ + /* for NetBSD 3.0 */ \ + || strcmp (Fs_type, "kernfs") == 0 \ + /* for Irix 6.5 */ \ || strcmp (Fs_type, "ignore") == 0) #endif #ifndef ME_REMOTE /* A file system is `remote' if its Fs_name contains a `:' or if (it is of type (smbfs or cifs) and its Fs_name starts with `//'). */ -# define ME_REMOTE(Fs_name, Fs_type) \ - (strchr (Fs_name, ':') != NULL \ - || ((Fs_name)[0] == '/' \ - && (Fs_name)[1] == '/' \ - && (strcmp (Fs_type, "smbfs") == 0 \ - || strcmp (Fs_type, "cifs") == 0))) +# define ME_REMOTE(Fs_name, Fs_type) \ + (strchr (Fs_name, ':') != NULL \ + || ((Fs_name)[0] == '/' \ + && (Fs_name)[1] == '/' \ + && (strcmp (Fs_type, "smbfs") == 0 \ + || strcmp (Fs_type, "cifs") == 0))) #endif #if MOUNTED_GETMNTINFO @@ -277,7 +277,7 @@ fsp_to_string (const struct statfs *fsp) #endif /* MOUNTED_GETMNTINFO */ -#ifdef MOUNTED_VMOUNT /* AIX. */ +#ifdef MOUNTED_VMOUNT /* AIX. */ static char * fstype_to_string (int t) { @@ -315,10 +315,10 @@ dev_from_mount_options (char const *mount_options) errno = 0; dev = strtoul (optval, &optvalend, 16); if (optval != optvalend - && (*optvalend == '\0' || *optvalend == ',') - && ! (dev == ULONG_MAX && errno == ERANGE) - && dev == (dev_t) dev) - return dev; + && (*optvalend == '\0' || *optvalend == ',') + && ! (dev == ULONG_MAX && errno == ERANGE) + && dev == (dev_t) dev) + return dev; } # endif @@ -383,18 +383,18 @@ read_file_system_list (bool need_fs_type) while ((mnt = getmntent (fp))) { - me = xmalloc (sizeof *me); - me->me_devname = xstrdup (mnt->mnt_fsname); - me->me_mountdir = xstrdup (mnt->mnt_dir); - me->me_type = xstrdup (mnt->mnt_type); - me->me_type_malloced = 1; - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = dev_from_mount_options (mnt->mnt_opts); - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (mnt->mnt_fsname); + me->me_mountdir = xstrdup (mnt->mnt_dir); + me->me_type = xstrdup (mnt->mnt_type); + me->me_type_malloced = 1; + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = dev_from_mount_options (mnt->mnt_opts); + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } if (endmntent (fp) == 0) @@ -402,7 +402,7 @@ read_file_system_list (bool need_fs_type) } #endif /* MOUNTED_GETMNTENT1. */ -#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ +#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */ { struct statfs *fsp; int entries; @@ -412,25 +412,25 @@ read_file_system_list (bool need_fs_type) return NULL; for (; entries-- > 0; fsp++) { - char *fs_type = fsp_to_string (fsp); - - me = xmalloc (sizeof *me); - me->me_devname = xstrdup (fsp->f_mntfromname); - me->me_mountdir = xstrdup (fsp->f_mntonname); - me->me_type = fs_type; - me->me_type_malloced = 0; - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + char *fs_type = fsp_to_string (fsp); + + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (fsp->f_mntfromname); + me->me_mountdir = xstrdup (fsp->f_mntonname); + me->me_type = fs_type; + me->me_type_malloced = 0; + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } } #endif /* MOUNTED_GETMNTINFO */ -#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ +#ifdef MOUNTED_GETMNTINFO2 /* NetBSD 3.0. */ { struct statvfs *fsp; int entries; @@ -440,44 +440,44 @@ read_file_system_list (bool need_fs_type) return NULL; for (; entries-- > 0; fsp++) { - me = xmalloc (sizeof *me); - me->me_devname = xstrdup (fsp->f_mntfromname); - me->me_mountdir = xstrdup (fsp->f_mntonname); - me->me_type = xstrdup (fsp->f_fstypename); - me->me_type_malloced = 1; - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (fsp->f_mntfromname); + me->me_mountdir = xstrdup (fsp->f_mntonname); + me->me_type = xstrdup (fsp->f_fstypename); + me->me_type_malloced = 1; + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } } #endif /* MOUNTED_GETMNTINFO2 */ -#ifdef MOUNTED_GETMNT /* Ultrix. */ +#ifdef MOUNTED_GETMNT /* Ultrix. */ { int offset = 0; int val; struct fs_data fsd; while (errno = 0, - 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, - (char *) 0))) + 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, + (char *) 0))) { - me = xmalloc (sizeof *me); - me->me_devname = xstrdup (fsd.fd_req.devname); - me->me_mountdir = xstrdup (fsd.fd_req.path); - me->me_type = gt_names[fsd.fd_req.fstype]; - me->me_type_malloced = 0; - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = fsd.fd_req.dev; - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (fsd.fd_req.devname); + me->me_mountdir = xstrdup (fsd.fd_req.path); + me->me_type = gt_names[fsd.fd_req.fstype]; + me->me_type_malloced = 0; + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = fsd.fd_req.dev; + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } if (val < 0) goto free_then_fail; @@ -537,7 +537,7 @@ read_file_system_list (bool need_fs_type) if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) { - struct rootdir_entry *re = xmalloc (sizeof *re); + struct rootdir_entry *re = xmalloc (sizeof *re); re->name = name; re->dev = statbuf.st_dev; re->ino = statbuf.st_ino; @@ -563,11 +563,11 @@ read_file_system_list (bool need_fs_type) if (re->dev == fi.dev && re->ino == fi.root) break; - me = xmalloc (sizeof *me); + me = xmalloc (sizeof *me); me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); me->me_type = xstrdup (fi.fsh_name); - me->me_type_malloced = 1; + me->me_type_malloced = 1; me->me_dev = fi.dev; me->me_dummy = 0; me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; @@ -588,7 +588,7 @@ read_file_system_list (bool need_fs_type) } #endif /* MOUNTED_FS_STAT_DEV */ -#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */ +#if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */ { int numsys, counter; size_t bufsize; @@ -606,24 +606,24 @@ read_file_system_list (bool need_fs_type) if (numsys < 0) { - free (stats); - return (NULL); + free (stats); + return (NULL); } for (counter = 0; counter < numsys; counter++) { - me = xmalloc (sizeof *me); - me->me_devname = xstrdup (stats[counter].f_mntfromname); - me->me_mountdir = xstrdup (stats[counter].f_mntonname); - me->me_type = xstrdup (FS_TYPE (stats[counter])); - me->me_type_malloced = 1; - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (stats[counter].f_mntfromname); + me->me_mountdir = xstrdup (stats[counter].f_mntonname); + me->me_type = xstrdup (FS_TYPE (stats[counter])); + me->me_type_malloced = 1; + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } free (stats); @@ -642,47 +642,47 @@ read_file_system_list (bool need_fs_type) while (fread (&mnt, sizeof mnt, 1, fp) > 0) { - me = xmalloc (sizeof *me); -# ifdef GETFSTYP /* SVR3. */ - me->me_devname = xstrdup (mnt.mt_dev); + me = xmalloc (sizeof *me); +# ifdef GETFSTYP /* SVR3. */ + me->me_devname = xstrdup (mnt.mt_dev); # else - me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6); - strcpy (me->me_devname, "/dev/"); - strcpy (me->me_devname + 5, mnt.mt_dev); + me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6); + strcpy (me->me_devname, "/dev/"); + strcpy (me->me_devname + 5, mnt.mt_dev); # endif - me->me_mountdir = xstrdup (mnt.mt_filsys); - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - me->me_type = ""; - me->me_type_malloced = 0; -# ifdef GETFSTYP /* SVR3. */ - if (need_fs_type) - { - struct statfs fsd; - char typebuf[FSTYPSZ]; - - if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 - && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) - { - me->me_type = xstrdup (typebuf); - me->me_type_malloced = 1; - } - } + me->me_mountdir = xstrdup (mnt.mt_filsys); + me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + me->me_type = ""; + me->me_type_malloced = 0; +# ifdef GETFSTYP /* SVR3. */ + if (need_fs_type) + { + struct statfs fsd; + char typebuf[FSTYPSZ]; + + if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 + && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) + { + me->me_type = xstrdup (typebuf); + me->me_type_malloced = 1; + } + } # endif - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } if (ferror (fp)) { - /* The last fread() call must have failed. */ - int saved_errno = errno; - fclose (fp); - errno = saved_errno; - goto free_then_fail; + /* The last fread() call must have failed. */ + int saved_errno = errno; + fclose (fp); + errno = saved_errno; + goto free_then_fail; } if (fclose (fp) == EOF) @@ -690,29 +690,29 @@ read_file_system_list (bool need_fs_type) } #endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */ -#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */ +#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes its own way. */ { struct mntent **mnttbl = getmnttbl (), **ent; for (ent=mnttbl;*ent;ent++) { - me = xmalloc (sizeof *me); - me->me_devname = xstrdup ( (*ent)->mt_resource); - me->me_mountdir = xstrdup ( (*ent)->mt_directory); - me->me_type = xstrdup ((*ent)->mt_fstype); - me->me_type_malloced = 1; - me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + me = xmalloc (sizeof *me); + me->me_devname = xstrdup ( (*ent)->mt_resource); + me->me_mountdir = xstrdup ( (*ent)->mt_directory); + me->me_type = xstrdup ((*ent)->mt_fstype); + me->me_type_malloced = 1; + me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } endmnttbl (); } #endif -#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ +#ifdef MOUNTED_GETMNTENT2 /* SVR4. */ { struct mnttab mnt; char *table = MNTTAB; @@ -731,19 +731,19 @@ read_file_system_list (bool need_fs_type) lockfd = open (MNTTAB_LOCK, O_RDONLY); if (0 <= lockfd) { - struct flock flock; - flock.l_type = F_RDLCK; - flock.l_whence = SEEK_SET; - flock.l_start = 0; - flock.l_len = 0; - while (fcntl (lockfd, F_SETLKW, &flock) == -1) - if (errno != EINTR) - { - int saved_errno = errno; - close (lockfd); - errno = saved_errno; - return NULL; - } + struct flock flock; + flock.l_type = F_RDLCK; + flock.l_whence = SEEK_SET; + flock.l_start = 0; + flock.l_len = 0; + while (fcntl (lockfd, F_SETLKW, &flock) == -1) + if (errno != EINTR) + { + int saved_errno = errno; + close (lockfd); + errno = saved_errno; + return NULL; + } } else if (errno != ENOENT) return NULL; @@ -755,23 +755,23 @@ read_file_system_list (bool need_fs_type) ret = errno; else { - while ((ret = getmntent (fp, &mnt)) == 0) - { - me = xmalloc (sizeof *me); - me->me_devname = xstrdup (mnt.mnt_special); - me->me_mountdir = xstrdup (mnt.mnt_mountp); - me->me_type = xstrdup (mnt.mnt_fstype); - me->me_type_malloced = 1; - me->me_dummy = MNT_IGNORE (&mnt) != 0; - me->me_remote = ME_REMOTE (me->me_devname, me->me_type); - me->me_dev = dev_from_mount_options (mnt.mnt_mntopts); - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; - } - - ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1; + while ((ret = getmntent (fp, &mnt)) == 0) + { + me = xmalloc (sizeof *me); + me->me_devname = xstrdup (mnt.mnt_special); + me->me_mountdir = xstrdup (mnt.mnt_mountp); + me->me_type = xstrdup (mnt.mnt_fstype); + me->me_type_malloced = 1; + me->me_dummy = MNT_IGNORE (&mnt) != 0; + me->me_remote = ME_REMOTE (me->me_devname, me->me_type); + me->me_dev = dev_from_mount_options (mnt.mnt_mntopts); + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; + } + + ret = fclose (fp) == EOF ? errno : 0 < ret ? 0 : -1; } if (0 <= lockfd && close (lockfd) != 0) @@ -779,13 +779,13 @@ read_file_system_list (bool need_fs_type) if (0 <= ret) { - errno = ret; - goto free_then_fail; + errno = ret; + goto free_then_fail; } } #endif /* MOUNTED_GETMNTENT2. */ -#ifdef MOUNTED_VMOUNT /* AIX. */ +#ifdef MOUNTED_VMOUNT /* AIX. */ { int bufsize; char *entries, *thisent; @@ -802,53 +802,53 @@ read_file_system_list (bool need_fs_type) n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); if (n_entries < 0) { - int saved_errno = errno; - free (entries); - errno = saved_errno; - return NULL; + int saved_errno = errno; + free (entries); + errno = saved_errno; + return NULL; } for (i = 0, thisent = entries; - i < n_entries; - i++, thisent += vmp->vmt_length) + i < n_entries; + i++, thisent += vmp->vmt_length) { - char *options, *ignore; - - vmp = (struct vmount *) thisent; - me = xmalloc (sizeof *me); - if (vmp->vmt_flags & MNT_REMOTE) - { - char *host, *dir; - - me->me_remote = 1; - /* Prepend the remote dirname. */ - host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; - dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; - me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2); - strcpy (me->me_devname, host); - strcat (me->me_devname, ":"); - strcat (me->me_devname, dir); - } - else - { - me->me_remote = 0; - me->me_devname = xstrdup (thisent + - vmp->vmt_data[VMT_OBJECT].vmt_off); - } - me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); - me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); - me->me_type_malloced = 1; - options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; - ignore = strstr (options, "ignore"); - me->me_dummy = (ignore - && (ignore == options || ignore[-1] == ',') - && (ignore[sizeof "ignore" - 1] == ',' - || ignore[sizeof "ignore" - 1] == '\0')); - me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */ - - /* Add to the linked list. */ - *mtail = me; - mtail = &me->me_next; + char *options, *ignore; + + vmp = (struct vmount *) thisent; + me = xmalloc (sizeof *me); + if (vmp->vmt_flags & MNT_REMOTE) + { + char *host, *dir; + + me->me_remote = 1; + /* Prepend the remote dirname. */ + host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; + dir = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; + me->me_devname = xmalloc (strlen (host) + strlen (dir) + 2); + strcpy (me->me_devname, host); + strcat (me->me_devname, ":"); + strcat (me->me_devname, dir); + } + else + { + me->me_remote = 0; + me->me_devname = xstrdup (thisent + + vmp->vmt_data[VMT_OBJECT].vmt_off); + } + me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); + me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); + me->me_type_malloced = 1; + options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; + ignore = strstr (options, "ignore"); + me->me_dummy = (ignore + && (ignore == options || ignore[-1] == ',') + && (ignore[sizeof "ignore" - 1] == ',' + || ignore[sizeof "ignore" - 1] == '\0')); + me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */ + + /* Add to the linked list. */ + *mtail = me; + mtail = &me->me_next; } free (entries); } @@ -865,13 +865,13 @@ read_file_system_list (bool need_fs_type) while (mount_list) { - me = mount_list->me_next; - free (mount_list->me_devname); - free (mount_list->me_mountdir); - if (mount_list->me_type_malloced) - free (mount_list->me_type); - free (mount_list); - mount_list = me; + me = mount_list->me_next; + free (mount_list->me_devname); + free (mount_list->me_mountdir); + if (mount_list->me_type_malloced) + free (mount_list->me_type); + free (mount_list); + mount_list = me; } errno = saved_errno; diff --git a/lib/mountlist.h b/lib/mountlist.h index e54bb49ef..5eb3e148a 100644 --- a/lib/mountlist.h +++ b/lib/mountlist.h @@ -25,12 +25,12 @@ /* A mount table entry. */ struct mount_entry { - char *me_devname; /* Device node name, including "/dev/". */ - char *me_mountdir; /* Mount point directory name. */ - char *me_type; /* "nfs", "4.2", etc. */ - dev_t me_dev; /* Device number of me_mountdir. */ - unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */ - unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ + char *me_devname; /* Device node name, including "/dev/". */ + char *me_mountdir; /* Mount point directory name. */ + char *me_type; /* "nfs", "4.2", etc. */ + dev_t me_dev; /* Device number of me_mountdir. */ + unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */ + unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */ struct mount_entry *me_next; }; diff --git a/lib/mpsort.c b/lib/mpsort.c index 43b25b6be..340091a29 100644 --- a/lib/mpsort.c +++ b/lib/mpsort.c @@ -28,15 +28,15 @@ typedef int (*comparison_function) (void const *, void const *); static void mpsort_with_tmp (void const **restrict, size_t, - void const **restrict, comparison_function); + void const **restrict, comparison_function); /* Sort a vector BASE containing N pointers, placing the sorted array into TMP. Compare pointers with CMP. N must be at least 2. */ static void mpsort_into_tmp (void const **restrict base, size_t n, - void const **restrict tmp, - comparison_function cmp) + void const **restrict tmp, + comparison_function cmp) { size_t n1 = n / 2; size_t n2 = n - n1; @@ -56,23 +56,23 @@ mpsort_into_tmp (void const **restrict base, size_t n, for (;;) if (cmp (ba, bb) <= 0) { - *tmp++ = ba; - a++; - if (a == alim) - { - a = b; - alim = blim; - break; - } - ba = base[a]; + *tmp++ = ba; + a++; + if (a == alim) + { + a = b; + alim = blim; + break; + } + ba = base[a]; } else { - *tmp++ = bb; - b++; - if (b == blim) - break; - bb = base[b]; + *tmp++ = bb; + b++; + if (b == blim) + break; + bb = base[b]; } memcpy (tmp, base + a, (alim - a) * sizeof *base); @@ -84,21 +84,21 @@ mpsort_into_tmp (void const **restrict base, size_t n, static void mpsort_with_tmp (void const **restrict base, size_t n, - void const **restrict tmp, - comparison_function cmp) + void const **restrict tmp, + comparison_function cmp) { if (n <= 2) { if (n == 2) - { - void const *p0 = base[0]; - void const *p1 = base[1]; - if (! (cmp (p0, p1) <= 0)) - { - base[0] = p1; - base[1] = p0; - } - } + { + void const *p0 = base[0]; + void const *p1 = base[1]; + if (! (cmp (p0, p1) <= 0)) + { + base[0] = p1; + base[1] = p0; + } + } } else { @@ -115,33 +115,33 @@ mpsort_with_tmp (void const **restrict base, size_t n, mpsort_with_tmp (base + n1, n2, tmp, cmp); if (n1 < 2) - tmp[0] = base[0]; + tmp[0] = base[0]; else - mpsort_into_tmp (base, n1, tmp, cmp); + mpsort_into_tmp (base, n1, tmp, cmp); tt = tmp[t]; bb = base[b]; for (i = 0; ; ) - if (cmp (tt, bb) <= 0) - { - base[i++] = tt; - t++; - if (t == tlim) - break; - tt = tmp[t]; - } - else - { - base[i++] = bb; - b++; - if (b == blim) - { - memcpy (base + i, tmp + t, (tlim - t) * sizeof *base); - break; - } - bb = base[b]; - } + if (cmp (tt, bb) <= 0) + { + base[i++] = tt; + t++; + if (t == tlim) + break; + tt = tmp[t]; + } + else + { + base[i++] = bb; + b++; + if (b == blim) + { + memcpy (base + i, tmp + t, (tlim - t) * sizeof *base); + break; + } + bb = base[b]; + } } } diff --git a/lib/nanosleep.c b/lib/nanosleep.c index 2b5bf5a9c..48b9ddca8 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -45,7 +45,7 @@ enum { BILLION = 1000 * 1000 * 1000 }; int rpl_nanosleep (const struct timespec *requested_delay, - struct timespec *remaining_delay) + struct timespec *remaining_delay) { /* nanosleep mishandles large sleeps due to internal overflow problems. The worst known case of this is cygwin 1.5.x, which @@ -115,12 +115,12 @@ my_usleep (const struct timespec *ts_delay) { time_t t1 = tv_delay.tv_sec + 1; if (t1 < tv_delay.tv_sec) - tv_delay.tv_usec = 1000000 - 1; /* close enough */ + tv_delay.tv_usec = 1000000 - 1; /* close enough */ else - { - tv_delay.tv_sec = t1; - tv_delay.tv_usec = 0; - } + { + tv_delay.tv_sec = t1; + tv_delay.tv_usec = 0; + } } select (0, NULL, NULL, NULL, &tv_delay); } @@ -130,7 +130,7 @@ my_usleep (const struct timespec *ts_delay) int rpl_nanosleep (const struct timespec *requested_delay, - struct timespec *remaining_delay) + struct timespec *remaining_delay) { static bool initialized; @@ -147,14 +147,14 @@ rpl_nanosleep (const struct timespec *requested_delay, sigaction (SIGCONT, NULL, &oldact); if (get_handler (&oldact) != SIG_IGN) - { - struct sigaction newact; - - newact.sa_handler = sighandler; - sigemptyset (&newact.sa_mask); - newact.sa_flags = 0; - sigaction (SIGCONT, &newact, NULL); - } + { + struct sigaction newact; + + newact.sa_handler = sighandler; + sigemptyset (&newact.sa_mask); + newact.sa_flags = 0; + sigaction (SIGCONT, &newact, NULL); + } initialized = true; } @@ -166,7 +166,7 @@ rpl_nanosleep (const struct timespec *requested_delay, { /* Calculate time remaining. */ /* FIXME: the code in sleep doesn't use this, so there's no - rush to implement it. */ + rush to implement it. */ errno = EINTR; } diff --git a/lib/netdb.in.h b/lib/netdb.in.h index c6aff668b..ec50d13c3 100644 --- a/lib/netdb.in.h +++ b/lib/netdb.in.h @@ -49,26 +49,26 @@ /* Structure to contain information about address of a service provider. */ struct addrinfo { - int ai_flags; /* Input flags. */ - int ai_family; /* Protocol family for socket. */ - int ai_socktype; /* Socket type. */ - int ai_protocol; /* Protocol for socket. */ - socklen_t ai_addrlen; /* Length of socket address. */ - struct sockaddr *ai_addr; /* Socket address for socket. */ - char *ai_canonname; /* Canonical name for service location. */ - struct addrinfo *ai_next; /* Pointer to next in list. */ + int ai_flags; /* Input flags. */ + int ai_family; /* Protocol family for socket. */ + int ai_socktype; /* Socket type. */ + int ai_protocol; /* Protocol for socket. */ + socklen_t ai_addrlen; /* Length of socket address. */ + struct sockaddr *ai_addr; /* Socket address for socket. */ + char *ai_canonname; /* Canonical name for service location. */ + struct addrinfo *ai_next; /* Pointer to next in list. */ }; # endif /* Possible values for `ai_flags' field in `addrinfo' structure. */ # ifndef AI_PASSIVE -# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ +# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ # endif # ifndef AI_CANONNAME -# define AI_CANONNAME 0x0002 /* Request for canonical name. */ +# define AI_CANONNAME 0x0002 /* Request for canonical name. */ # endif # ifndef AI_NUMERICSERV -# define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ +# define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ # endif # if 0 @@ -78,24 +78,24 @@ struct addrinfo define them. If they are restored, be sure to protect the definitions with #ifndef. */ -# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ -# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ -# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ -# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose - returned address type.. */ +# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ +# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ +# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ +# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose + returned address type.. */ # endif /* 0 */ /* Error values for `getaddrinfo' function. */ # ifndef EAI_BADFLAGS -# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ -# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ -# define EAI_AGAIN -3 /* Temporary failure in name resolution. */ -# define EAI_FAIL -4 /* Non-recoverable failure in name res. */ -# define EAI_NODATA -5 /* No address associated with NAME. */ -# define EAI_FAMILY -6 /* `ai_family' not supported. */ -# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ -# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ -# define EAI_MEMORY -10 /* Memory allocation failure. */ +# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ +# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ +# define EAI_AGAIN -3 /* Temporary failure in name resolution. */ +# define EAI_FAIL -4 /* Non-recoverable failure in name res. */ +# define EAI_NODATA -5 /* No address associated with NAME. */ +# define EAI_FAMILY -6 /* `ai_family' not supported. */ +# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ +# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ +# define EAI_MEMORY -10 /* Memory allocation failure. */ # endif /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least @@ -107,15 +107,15 @@ struct addrinfo # ifndef EAI_OVERFLOW /* Not defined on mingw32 and Haiku. */ -# define EAI_OVERFLOW -12 /* Argument buffer overflow. */ +# define EAI_OVERFLOW -12 /* Argument buffer overflow. */ # endif # ifndef EAI_ADDRFAMILY /* Not defined on mingw32. */ -# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ +# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ # endif # ifndef EAI_SYSTEM /* Not defined on mingw32. */ -# define EAI_SYSTEM -11 /* System error returned in `errno'. */ +# define EAI_SYSTEM -11 /* System error returned in `errno'. */ # endif # if 0 @@ -124,12 +124,12 @@ struct addrinfo If they are restored, be sure to protect the definitions with #ifndef. */ # ifndef EAI_INPROGRESS -# define EAI_INPROGRESS -100 /* Processing request in progress. */ -# define EAI_CANCELED -101 /* Request canceled. */ -# define EAI_NOTCANCELED -102 /* Request not canceled. */ -# define EAI_ALLDONE -103 /* All requests done. */ -# define EAI_INTR -104 /* Interrupted by a signal. */ -# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ +# define EAI_INPROGRESS -100 /* Processing request in progress. */ +# define EAI_CANCELED -101 /* Request canceled. */ +# define EAI_NOTCANCELED -102 /* Request not canceled. */ +# define EAI_ALLDONE -103 /* All requests done. */ +# define EAI_INTR -104 /* Interrupted by a signal. */ +# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ # endif # endif @@ -139,9 +139,9 @@ struct addrinfo For more details, see the POSIX:2001 specification . */ extern int getaddrinfo (const char *restrict nodename, - const char *restrict servname, - const struct addrinfo *restrict hints, - struct addrinfo **restrict res); + const char *restrict servname, + const struct addrinfo *restrict hints, + struct addrinfo **restrict res); # endif # if !@HAVE_DECL_FREEADDRINFO@ @@ -163,9 +163,9 @@ extern const char *gai_strerror (int ecode); For more details, see the POSIX:2001 specification . */ extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, - char *restrict node, socklen_t nodelen, - char *restrict service, socklen_t servicelen, - int flags); + char *restrict node, socklen_t nodelen, + char *restrict service, socklen_t servicelen, + int flags); # endif /* Possible flags for getnameinfo. */ diff --git a/lib/nproc.c b/lib/nproc.c index 7c9be94ae..9dafdf525 100644 --- a/lib/nproc.c +++ b/lib/nproc.c @@ -65,30 +65,30 @@ num_processors (enum nproc_query query) if (query == NPROC_CURRENT_OVERRIDABLE) { /* Test the environment variable OMP_NUM_THREADS, recognized also by all - programs that are based on OpenMP. The OpenMP spec says that the - value assigned to the environment variable "may have leading and - trailing white space". */ + programs that are based on OpenMP. The OpenMP spec says that the + value assigned to the environment variable "may have leading and + trailing white space". */ const char *envvalue = getenv ("OMP_NUM_THREADS"); if (envvalue != NULL) - { - while (*envvalue != '\0' && c_isspace (*envvalue)) - envvalue++; - /* Convert it from decimal to 'unsigned long'. */ - if (c_isdigit (*envvalue)) - { - char *endptr = NULL; - unsigned long int value = strtoul (envvalue, &endptr, 10); - - if (endptr != NULL) - { - while (*endptr != '\0' && c_isspace (*endptr)) - endptr++; - if (*endptr == '\0') - return (value > 0 ? value : 1); - } - } - } + { + while (*envvalue != '\0' && c_isspace (*envvalue)) + envvalue++; + /* Convert it from decimal to 'unsigned long'. */ + if (c_isdigit (*envvalue)) + { + char *endptr = NULL; + unsigned long int value = strtoul (envvalue, &endptr, 10); + + if (endptr != NULL) + { + while (*endptr != '\0' && c_isspace (*endptr)) + endptr++; + if (*endptr == '\0') + return (value > 0 ? value : 1); + } + } + } query = NPROC_CURRENT; } @@ -97,139 +97,139 @@ num_processors (enum nproc_query query) if (query == NPROC_CURRENT) { /* glibc >= 2.3.3 with NPTL and NetBSD 5 have pthread_getaffinity_np, - but with different APIs. Also it requires linking with -lpthread. - Therefore this code is not enabled. - glibc >= 2.3.4 has sched_getaffinity whereas NetBSD 5 has - sched_getaffinity_np. */ + but with different APIs. Also it requires linking with -lpthread. + Therefore this code is not enabled. + glibc >= 2.3.4 has sched_getaffinity whereas NetBSD 5 has + sched_getaffinity_np. */ #if HAVE_PTHREAD_AFFINITY_NP && defined __GLIBC__ && 0 { - cpu_set_t set; + cpu_set_t set; - if (pthread_getaffinity_np (pthread_self (), sizeof (set), &set) == 0) - { - unsigned long count; + if (pthread_getaffinity_np (pthread_self (), sizeof (set), &set) == 0) + { + unsigned long count; # ifdef CPU_COUNT - /* glibc >= 2.6 has the CPU_COUNT macro. */ - count = CPU_COUNT (&set); + /* glibc >= 2.6 has the CPU_COUNT macro. */ + count = CPU_COUNT (&set); # else - size_t i; + size_t i; - count = 0; - for (i = 0; i < CPU_SETSIZE; i++) - if (CPU_ISSET (i, &set)) - count++; + count = 0; + for (i = 0; i < CPU_SETSIZE; i++) + if (CPU_ISSET (i, &set)) + count++; # endif - if (count > 0) - return count; - } + if (count > 0) + return count; + } } #elif HAVE_PTHREAD_AFFINITY_NP && defined __NetBSD__ && 0 { - cpuset_t *set; - - set = cpuset_create (); - if (set != NULL) - { - unsigned long count = 0; - - if (pthread_getaffinity_np (pthread_self (), cpuset_size (set), set) - == 0) - { - cpuid_t i; - - for (i = 0;; i++) - { - int ret = cpuset_isset (i, set); - if (ret < 0) - break; - if (ret > 0) - count++; - } - } - cpuset_destroy (set); - if (count > 0) - return count; - } + cpuset_t *set; + + set = cpuset_create (); + if (set != NULL) + { + unsigned long count = 0; + + if (pthread_getaffinity_np (pthread_self (), cpuset_size (set), set) + == 0) + { + cpuid_t i; + + for (i = 0;; i++) + { + int ret = cpuset_isset (i, set); + if (ret < 0) + break; + if (ret > 0) + count++; + } + } + cpuset_destroy (set); + if (count > 0) + return count; + } } #elif HAVE_SCHED_GETAFFINITY_LIKE_GLIBC /* glibc >= 2.3.4 */ { - cpu_set_t set; + cpu_set_t set; - if (sched_getaffinity (0, sizeof (set), &set) == 0) - { - unsigned long count; + if (sched_getaffinity (0, sizeof (set), &set) == 0) + { + unsigned long count; # ifdef CPU_COUNT - /* glibc >= 2.6 has the CPU_COUNT macro. */ - count = CPU_COUNT (&set); + /* glibc >= 2.6 has the CPU_COUNT macro. */ + count = CPU_COUNT (&set); # else - size_t i; + size_t i; - count = 0; - for (i = 0; i < CPU_SETSIZE; i++) - if (CPU_ISSET (i, &set)) - count++; + count = 0; + for (i = 0; i < CPU_SETSIZE; i++) + if (CPU_ISSET (i, &set)) + count++; # endif - if (count > 0) - return count; - } + if (count > 0) + return count; + } } #elif HAVE_SCHED_GETAFFINITY_NP /* NetBSD >= 5 */ { - cpuset_t *set; - - set = cpuset_create (); - if (set != NULL) - { - unsigned long count = 0; - - if (sched_getaffinity_np (getpid (), cpuset_size (set), set) == 0) - { - cpuid_t i; - - for (i = 0;; i++) - { - int ret = cpuset_isset (i, set); - if (ret < 0) - break; - if (ret > 0) - count++; - } - } - cpuset_destroy (set); - if (count > 0) - return count; - } + cpuset_t *set; + + set = cpuset_create (); + if (set != NULL) + { + unsigned long count = 0; + + if (sched_getaffinity_np (getpid (), cpuset_size (set), set) == 0) + { + cpuid_t i; + + for (i = 0;; i++) + { + int ret = cpuset_isset (i, set); + if (ret < 0) + break; + if (ret > 0) + count++; + } + } + cpuset_destroy (set); + if (count > 0) + return count; + } } #endif #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ { /* This works on native Windows platforms. */ - DWORD_PTR process_mask; - DWORD_PTR system_mask; - - if (GetProcessAffinityMask (GetCurrentProcess (), - &process_mask, &system_mask)) - { - DWORD_PTR mask = process_mask; - unsigned long count = 0; - - for (; mask != 0; mask = mask >> 1) - if (mask & 1) - count++; - if (count > 0) - return count; - } + DWORD_PTR process_mask; + DWORD_PTR system_mask; + + if (GetProcessAffinityMask (GetCurrentProcess (), + &process_mask, &system_mask)) + { + DWORD_PTR mask = process_mask; + unsigned long count = 0; + + for (; mask != 0; mask = mask >> 1) + if (mask & 1) + count++; + if (count > 0) + return count; + } } #endif #if defined _SC_NPROCESSORS_ONLN { /* This works on glibc, MacOS X 10.5, FreeBSD, AIX, OSF/1, Solaris, - Cygwin, Haiku. */ - long int nprocs = sysconf (_SC_NPROCESSORS_ONLN); - if (nprocs > 0) - return nprocs; + Cygwin, Haiku. */ + long int nprocs = sysconf (_SC_NPROCESSORS_ONLN); + if (nprocs > 0) + return nprocs; } #endif } @@ -237,10 +237,10 @@ num_processors (enum nproc_query query) { #if defined _SC_NPROCESSORS_CONF { /* This works on glibc, MacOS X 10.5, FreeBSD, AIX, OSF/1, Solaris, - Cygwin, Haiku. */ - long int nprocs = sysconf (_SC_NPROCESSORS_CONF); - if (nprocs > 0) - return nprocs; + Cygwin, Haiku. */ + long int nprocs = sysconf (_SC_NPROCESSORS_CONF); + if (nprocs > 0) + return nprocs; } #endif } @@ -250,19 +250,19 @@ num_processors (enum nproc_query query) struct pst_dynamic psd; if (pstat_getdynamic (&psd, sizeof psd, 1, 0) >= 0) { - /* The field psd_proc_cnt contains the number of active processors. - In newer releases of HP-UX 11, the field psd_max_proc_cnt includes - deactivated processors. */ - if (query == NPROC_CURRENT) - { - if (psd.psd_proc_cnt > 0) - return psd.psd_proc_cnt; - } - else - { - if (psd.psd_max_proc_cnt > 0) - return psd.psd_max_proc_cnt; - } + /* The field psd_proc_cnt contains the number of active processors. + In newer releases of HP-UX 11, the field psd_max_proc_cnt includes + deactivated processors. */ + if (query == NPROC_CURRENT) + { + if (psd.psd_proc_cnt > 0) + return psd.psd_proc_cnt; + } + else + { + if (psd.psd_max_proc_cnt > 0) + return psd.psd_max_proc_cnt; + } } } #endif @@ -274,8 +274,8 @@ num_processors (enum nproc_query query) processes. */ int nprocs = sysmp (query == NPROC_CURRENT && getpid () != 0 - ? MP_NAPROCS - : MP_NPROCS); + ? MP_NAPROCS + : MP_NPROCS); if (nprocs > 0) return nprocs; } @@ -291,8 +291,8 @@ num_processors (enum nproc_query query) static int mib[2] = { CTL_HW, HW_NCPU }; if (sysctl (mib, ARRAY_SIZE (mib), &nprocs, &len, NULL, 0) == 0 - && len == sizeof (nprocs) - && 0 < nprocs) + && len == sizeof (nprocs) + && 0 < nprocs) return nprocs; } #endif diff --git a/lib/obstack.c b/lib/obstack.c index 5b87466d8..11cfff3fe 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -39,7 +39,7 @@ 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 /* Random thing to get __GNU_LIBRARY__. */ +#include /* Random thing to get __GNU_LIBRARY__. */ #if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1 # include # if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION @@ -141,9 +141,9 @@ compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0); int _obstack_begin (struct obstack *h, - int size, int alignment, - void *(*chunkfun) (long), - void (*freefun) (void *)) + int size, int alignment, + void *(*chunkfun) (long), + void (*freefun) (void *)) { register struct _obstack_chunk *chunk; /* points to new chunk */ @@ -153,16 +153,16 @@ _obstack_begin (struct obstack *h, /* 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. + 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. */ + 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)); + + 4 + DEFAULT_ROUNDING - 1) + & ~(DEFAULT_ROUNDING - 1)); size = 4096 - extra; } @@ -176,7 +176,7 @@ _obstack_begin (struct obstack *h, if (!chunk) (*obstack_alloc_failed_handler) (); h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents, - alignment - 1); + alignment - 1); h->chunk_limit = chunk->limit = (char *) chunk + h->chunk_size; chunk->prev = 0; @@ -188,9 +188,9 @@ _obstack_begin (struct obstack *h, int _obstack_begin_1 (struct obstack *h, int size, int alignment, - void *(*chunkfun) (void *, long), - void (*freefun) (void *, void *), - void *arg) + void *(*chunkfun) (void *, long), + void (*freefun) (void *, void *), + void *arg) { register struct _obstack_chunk *chunk; /* points to new chunk */ @@ -200,16 +200,16 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment, /* 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. + 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. */ + 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)); + + 4 + DEFAULT_ROUNDING - 1) + & ~(DEFAULT_ROUNDING - 1)); size = 4096 - extra; } @@ -224,7 +224,7 @@ _obstack_begin_1 (struct obstack *h, int size, int alignment, if (!chunk) (*obstack_alloc_failed_handler) (); h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents, - alignment - 1); + alignment - 1); h->chunk_limit = chunk->limit = (char *) chunk + h->chunk_size; chunk->prev = 0; @@ -245,7 +245,7 @@ _obstack_newchunk (struct obstack *h, int length) { register struct _obstack_chunk *old_chunk = h->chunk; register struct _obstack_chunk *new_chunk; - register long new_size; + register long new_size; register long obj_size = h->next_free - h->object_base; register long i; long already; @@ -274,12 +274,12 @@ _obstack_newchunk (struct obstack *h, int length) 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]; + 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. */ + 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 @@ -293,8 +293,8 @@ _obstack_newchunk (struct obstack *h, int length) 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))) + == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents, + h->alignment_mask))) { new_chunk->prev = old_chunk->prev; CALL_FREEFUN (h, old_chunk); @@ -320,8 +320,8 @@ int _obstack_allocated_p (struct obstack *h, void *obj); int _obstack_allocated_p (struct obstack *h, void *obj) { - register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ - register struct _obstack_chunk *plp; /* point to previous chunk if any */ + register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ + register struct _obstack_chunk *plp; /* point to previous chunk if any */ lp = (h)->chunk; /* We use >= rather than > since the object cannot be exactly at @@ -343,8 +343,8 @@ _obstack_allocated_p (struct obstack *h, void *obj) void __obstack_free (struct obstack *h, void *obj) { - register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ - register struct _obstack_chunk *plp; /* point to previous chunk if any */ + register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ + register 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. @@ -356,7 +356,7 @@ __obstack_free (struct obstack *h, void *obj) 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. */ + chunk contains an empty object, so assume that it may. */ h->maybe_empty_object = 1; } if (lp) @@ -427,4 +427,4 @@ print_and_abort (void) exit (obstack_exit_failure); } -#endif /* !ELIDE_CODE */ +#endif /* !ELIDE_CODE */ diff --git a/lib/obstack.h b/lib/obstack.h index 1bf4b2f1a..7a65bac61 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -1,6 +1,6 @@ /* obstack.h - object stack macros Copyright (C) 1988-1994,1996-1999,2003,2004,2005,2006 - Free Software Foundation, Inc. + 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 @@ -85,17 +85,17 @@ 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.) + 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.) */ @@ -133,56 +133,56 @@ extern "C" { relative to B. Otherwise, use the faster strategy of computing the alignment relative to 0. */ -#define __PTR_ALIGN(B, P, A) \ +#define __PTR_ALIGN(B, P, A) \ __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \ - P, A) + P, A) #include -struct _obstack_chunk /* Lives at front of each chunk. */ +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 */ + 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 */ +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 */ + 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. */ + } 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 */ + 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. */ + 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 *)); + void *(*) (long), void (*) (void *)); extern int _obstack_begin_1 (struct obstack *, int, int, - void *(*) (void *, long), - void (*) (void *, void *), void *); + 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', @@ -214,32 +214,32 @@ extern int obstack_exit_failure; /* Pointer to next byte not yet allocated in current chunk. */ -#define obstack_next_free(h) ((h)->next_free) +#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_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_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)) + _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)) + _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)) @@ -266,143 +266,143 @@ extern int obstack_exit_failure; 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); \ +# 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); \ +# 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); \ +# 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; \ +# 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; \ +# 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); \ +# 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)); \ +# 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); \ - *(const void **) __o1->next_free = (aptr); \ - __o1->next_free += sizeof (const void *); \ +# define obstack_ptr_grow_fast(OBSTACK,aptr) \ +__extension__ \ +({ struct obstack *__o1 = (OBSTACK); \ + *(const void **) __o1->next_free = (aptr); \ + __o1->next_free += sizeof (const void *); \ (void) 0; }) -# define obstack_int_grow_fast(OBSTACK,aint) \ -__extension__ \ -({ struct obstack *__o1 = (OBSTACK); \ - *(int *) __o1->next_free = (aint); \ - __o1->next_free += sizeof (int); \ +# define obstack_int_grow_fast(OBSTACK,aint) \ +__extension__ \ +({ struct obstack *__o1 = (OBSTACK); \ + *(int *) __o1->next_free = (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); \ +# 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)); \ +# 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)); \ +# 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)); \ +# 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; \ +# 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); \ +# 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; \ + __o->next_free = __o->object_base = (char *)__obj; \ else (__obstack_free) (__o, __obj); }) #else /* not __GNUC__ or not __STDC__ */ @@ -410,14 +410,14 @@ __extension__ \ # define obstack_object_size(h) \ (unsigned) ((h)->next_free - (h)->object_base) -# define obstack_room(h) \ +# 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)) + ((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 @@ -425,88 +425,88 @@ __extension__ \ 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) \ +# 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), \ +# 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, \ +# 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), \ +# 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), \ +# 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), \ +# 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) \ +# define obstack_ptr_grow_fast(h,aptr) \ (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr)) -# define obstack_int_grow_fast(h,aint) \ +# 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), \ +# 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) \ +# define obstack_alloc(h,length) \ (obstack_blank ((h), (length)), obstack_finish ((h))) -# define obstack_copy(h,where,length) \ +# define obstack_copy(h,where,length) \ (obstack_grow ((h), (where), (length)), obstack_finish ((h))) -# define obstack_copy0(h,where,length) \ +# 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, \ +# 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) \ +# 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__ or not __STDC__ */ #ifdef __cplusplus -} /* C++ */ +} /* C++ */ #endif #endif /* obstack.h */ diff --git a/lib/obstack_printf.c b/lib/obstack_printf.c index c2d0b5064..0dc1faccb 100644 --- a/lib/obstack_printf.c +++ b/lib/obstack_printf.c @@ -73,7 +73,7 @@ obstack_vprintf (struct obstack *obs, const char *format, va_list args) if (!str) { if (errno == ENOMEM) - obstack_alloc_failed_handler (); + obstack_alloc_failed_handler (); return -1; } if (str == base && str != buf) @@ -83,10 +83,10 @@ obstack_vprintf (struct obstack *obs, const char *format, va_list args) else { /* The output exceeded available obstack space or we used buf; - copy the resulting string. */ + copy the resulting string. */ obstack_grow (obs, str, len); if (str != buf) - free (str); + free (str); } return len; } diff --git a/lib/open-safer.c b/lib/open-safer.c index 48d558fa5..f9bde6ecf 100644 --- a/lib/open-safer.c +++ b/lib/open-safer.c @@ -36,7 +36,7 @@ open_safer (char const *file, int flags, ...) va_start (ap, 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'. */ + creates crashing code when 'mode_t' is smaller than 'int'. */ mode = va_arg (ap, PROMOTED_MODE_T); va_end (ap); diff --git a/lib/open.c b/lib/open.c index 8027b473a..82b5cd093 100644 --- a/lib/open.c +++ b/lib/open.c @@ -57,7 +57,7 @@ open (const char *filename, int flags, ...) 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'. */ + creates crashing code when 'mode_t' is smaller than 'int'. */ mode = va_arg (arg, PROMOTED_MODE_T); va_end (arg); @@ -94,10 +94,10 @@ open (const char *filename, int flags, ...) { size_t len = strlen (filename); if (len > 0 && filename[len - 1] == '/') - { - errno = EISDIR; - return -1; - } + { + errno = EISDIR; + return -1; + } } #endif @@ -144,16 +144,16 @@ open (const char *filename, int flags, ...) /* 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; - } - } + { + struct stat statbuf; + + if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) + { + close (fd); + errno = ENOTDIR; + return -1; + } + } } #endif diff --git a/lib/openat-die.c b/lib/openat-die.c index a507eac10..c19373434 100644 --- a/lib/openat-die.c +++ b/lib/openat-die.c @@ -31,7 +31,7 @@ void openat_save_fail (int errnum) { error (exit_failure, errnum, - _("unable to record current working directory")); + _("unable to record current working directory")); /* The `noreturn' attribute cannot be applied to error, since it returns when its first argument is 0. To help compilers understand that this @@ -49,7 +49,7 @@ void openat_restore_fail (int errnum) { error (exit_failure, errnum, - _("failed to return to initial working directory")); + _("failed to return to initial working directory")); /* As above. */ abort (); diff --git a/lib/openat-priv.h b/lib/openat-priv.h index 53016a14e..ab6e9a841 100644 --- a/lib/openat-priv.h +++ b/lib/openat-priv.h @@ -30,15 +30,15 @@ char *openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file); /proc support, and even on systems *with* ProcFS support. Return nonzero if the failure may be legitimate, e.g., because /proc is not readable, or the particular .../fd/N directory is not present. */ -#define EXPECTED_ERRNO(Errno) \ - ((Errno) == ENOTDIR || (Errno) == ENOENT \ - || (Errno) == EPERM || (Errno) == EACCES \ - || (Errno) == ENOSYS /* Solaris 8 */ \ +#define EXPECTED_ERRNO(Errno) \ + ((Errno) == ENOTDIR || (Errno) == ENOENT \ + || (Errno) == EPERM || (Errno) == EACCES \ + || (Errno) == ENOSYS /* Solaris 8 */ \ || (Errno) == EOPNOTSUPP /* FreeBSD */) /* Wrapper function shared among linkat and renameat. */ int at_func2 (int fd1, char const *file1, - int fd2, char const *file2, - int (*func) (char const *file1, char const *file2)); + int fd2, char const *file2, + int (*func) (char const *file1, char const *file2)); #endif /* _GL_HEADER_OPENAT_PRIV */ diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 76e1c6dd5..483201ce5 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -67,29 +67,29 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) if (! proc_status) { /* Set PROC_STATUS to a positive value if /proc/self/fd is - reliable, and a negative value otherwise. Solaris 10 - /proc/self/fd mishandles "..", and any file name might expand - to ".." after symbolic link expansion, so avoid /proc/self/fd - if it mishandles "..". Solaris 10 has openat, but this - problem is exhibited on code that built on Solaris 8 and - running on Solaris 10. */ + reliable, and a negative value otherwise. Solaris 10 + /proc/self/fd mishandles "..", and any file name might expand + to ".." after symbolic link expansion, so avoid /proc/self/fd + if it mishandles "..". Solaris 10 has openat, but this + problem is exhibited on code that built on Solaris 8 and + running on Solaris 10. */ int proc_self_fd = open ("/proc/self/fd", O_RDONLY); if (proc_self_fd < 0) - proc_status = -1; + proc_status = -1; else - { - struct stat proc_self_fd_dotdot_st; - struct stat proc_self_st; - char dotdot_buf[PROC_SELF_FD_NAME_SIZE_BOUND (sizeof ".." - 1)]; - sprintf (dotdot_buf, PROC_SELF_FD_FORMAT, proc_self_fd, ".."); - proc_status = - ((stat (dotdot_buf, &proc_self_fd_dotdot_st) == 0 - && stat ("/proc/self", &proc_self_st) == 0 - && SAME_INODE (proc_self_fd_dotdot_st, proc_self_st)) - ? 1 : -1); - close (proc_self_fd); - } + { + struct stat proc_self_fd_dotdot_st; + struct stat proc_self_st; + char dotdot_buf[PROC_SELF_FD_NAME_SIZE_BOUND (sizeof ".." - 1)]; + sprintf (dotdot_buf, PROC_SELF_FD_FORMAT, proc_self_fd, ".."); + proc_status = + ((stat (dotdot_buf, &proc_self_fd_dotdot_st) == 0 + && stat ("/proc/self", &proc_self_st) == 0 + && SAME_INODE (proc_self_fd_dotdot_st, proc_self_st)) + ? 1 : -1); + close (proc_self_fd); + } } if (proc_status < 0) diff --git a/lib/openat-safer.c b/lib/openat-safer.c index 58d9a5e5f..44f24d700 100644 --- a/lib/openat-safer.c +++ b/lib/openat-safer.c @@ -36,7 +36,7 @@ openat_safer (int fd, char const *file, int flags, ...) va_start (ap, 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'. */ + creates crashing code when 'mode_t' is smaller than 'int'. */ mode = va_arg (ap, PROMOTED_MODE_T); va_end (ap); diff --git a/lib/openat.h b/lib/openat.h index 433b9983d..fb8344a45 100644 --- a/lib/openat.h +++ b/lib/openat.h @@ -40,7 +40,7 @@ #if !HAVE_OPENAT int openat_permissive (int fd, char const *file, int flags, mode_t mode, - int *cwd_errno); + int *cwd_errno); bool openat_needs_fchdir (void); #else diff --git a/lib/pagealign_alloc.c b/lib/pagealign_alloc.c index 755130045..8aefea3f9 100644 --- a/lib/pagealign_alloc.c +++ b/lib/pagealign_alloc.c @@ -129,14 +129,14 @@ pagealign_alloc (size_t size) const int flags = MAP_ANONYMOUS | MAP_PRIVATE; # else /* !HAVE_MAP_ANONYMOUS */ static int fd = -1; /* Only open /dev/zero once in order to avoid limiting - the amount of memory we may allocate based on the - number of open file descriptors. */ + the amount of memory we may allocate based on the + number of open file descriptors. */ const int flags = MAP_FILE | MAP_PRIVATE; if (fd == -1) { fd = open ("/dev/zero", O_RDONLY, 0666); if (fd < 0) - error (EXIT_FAILURE, errno, _("Failed to open /dev/zero for read")); + error (EXIT_FAILURE, errno, _("Failed to open /dev/zero for read")); } # endif /* HAVE_MAP_ANONYMOUS */ ret = mmap (NULL, size, PROT_READ | PROT_WRITE, flags, fd, 0); @@ -156,7 +156,7 @@ pagealign_alloc (size_t size) if (unaligned_ptr == NULL) { /* Set errno. We don't know whether malloc already set errno: some - implementations of malloc do, some don't. */ + implementations of malloc do, some don't. */ errno = ENOMEM; return NULL; } diff --git a/lib/pathmax.h b/lib/pathmax.h index f18d7600f..7a858031f 100644 --- a/lib/pathmax.h +++ b/lib/pathmax.h @@ -28,7 +28,7 @@ # if !defined PATH_MAX && defined _PC_PATH_MAX && defined HAVE_PATHCONF # define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \ - : pathconf ("/", _PC_PATH_MAX)) + : pathconf ("/", _PC_PATH_MAX)) # endif /* Don't include sys/param.h if it already has been. */ diff --git a/lib/physmem.c b/lib/physmem.c index 4b532e1a0..2eb6e97fc 100644 --- a/lib/physmem.c +++ b/lib/physmem.c @@ -95,10 +95,10 @@ physmem_total (void) struct pst_static pss; if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)) { - double pages = pss.physical_memory; - double pagesize = pss.page_size; - if (0 <= pages && 0 <= pagesize) - return pages * pagesize; + double pages = pss.physical_memory; + double pagesize = pss.page_size; + if (0 <= pages && 0 <= pagesize) + return pages * pagesize; } } #endif @@ -108,10 +108,10 @@ physmem_total (void) struct rminfo realmem; if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) { - double pagesize = sysconf (_SC_PAGESIZE); - double pages = realmem.physmem; - if (0 <= pages && 0 <= pagesize) - return pages * pagesize; + double pagesize = sysconf (_SC_PAGESIZE); + double pages = realmem.physmem; + if (0 <= pages && 0 <= pagesize) + return pages * pagesize; } } #endif @@ -121,12 +121,12 @@ physmem_total (void) int physmem; if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem), - NULL, NULL, NULL) == 1) + NULL, NULL, NULL) == 1) { - double kbytes = physmem; + double kbytes = physmem; - if (0 <= kbytes) - return kbytes * 1024.0; + if (0 <= kbytes) + return kbytes * 1024.0; } } #endif @@ -138,7 +138,7 @@ physmem_total (void) static int mib[2] = { CTL_HW, HW_PHYSMEM }; if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 - && len == sizeof (physmem)) + && len == sizeof (physmem)) return (double) physmem; } #endif @@ -159,20 +159,20 @@ physmem_total (void) /* Use GlobalMemoryStatusEx if available. */ if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) { - lMEMORYSTATUSEX lms_ex; - lms_ex.dwLength = sizeof lms_ex; - if (!pfnex (&lms_ex)) - return 0.0; - return (double) lms_ex.ullTotalPhys; + lMEMORYSTATUSEX lms_ex; + lms_ex.dwLength = sizeof lms_ex; + if (!pfnex (&lms_ex)) + return 0.0; + return (double) lms_ex.ullTotalPhys; } /* Fall back to GlobalMemoryStatus which is always available. but returns wrong results for physical memory > 4GB. */ else { - MEMORYSTATUS ms; - GlobalMemoryStatus (&ms); - return (double) ms.dwTotalPhys; + MEMORYSTATUS ms; + GlobalMemoryStatus (&ms); + return (double) ms.dwTotalPhys; } } #endif @@ -199,12 +199,12 @@ physmem_available (void) struct pst_static pss; struct pst_dynamic psd; if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0) - && 0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0)) + && 0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0)) { - double pages = psd.psd_free; - double pagesize = pss.page_size; - if (0 <= pages && 0 <= pagesize) - return pages * pagesize; + double pages = psd.psd_free; + double pagesize = pss.page_size; + if (0 <= pages && 0 <= pagesize) + return pages * pagesize; } } #endif @@ -214,10 +214,10 @@ physmem_available (void) struct rminfo realmem; if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) { - double pagesize = sysconf (_SC_PAGESIZE); - double pages = realmem.availrmem; - if (0 <= pages && 0 <= pagesize) - return pages * pagesize; + double pagesize = sysconf (_SC_PAGESIZE); + double pages = realmem.availrmem; + if (0 <= pages && 0 <= pagesize) + return pages * pagesize; } } #endif @@ -228,11 +228,11 @@ physmem_available (void) if (table (TBL_VMSTATS, 0, &vmstats, 1, sizeof (vmstats)) == 1) { - double pages = vmstats.free_count; - double pagesize = vmstats.pagesize; + double pages = vmstats.free_count; + double pagesize = vmstats.pagesize; - if (0 <= pages && 0 <= pagesize) - return pages * pagesize; + if (0 <= pages && 0 <= pagesize) + return pages * pagesize; } } #endif @@ -244,7 +244,7 @@ physmem_available (void) static int mib[2] = { CTL_HW, HW_USERMEM }; if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0 - && len == sizeof (usermem)) + && len == sizeof (usermem)) return (double) usermem; } #endif @@ -260,20 +260,20 @@ physmem_available (void) /* Use GlobalMemoryStatusEx if available. */ if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) { - lMEMORYSTATUSEX lms_ex; - lms_ex.dwLength = sizeof lms_ex; - if (!pfnex (&lms_ex)) - return 0.0; - return (double) lms_ex.ullAvailPhys; + lMEMORYSTATUSEX lms_ex; + lms_ex.dwLength = sizeof lms_ex; + if (!pfnex (&lms_ex)) + return 0.0; + return (double) lms_ex.ullAvailPhys; } /* Fall back to GlobalMemoryStatus which is always available. but returns wrong results for physical memory > 4GB */ else { - MEMORYSTATUS ms; - GlobalMemoryStatus (&ms); - return (double) ms.dwAvailPhys; + MEMORYSTATUS ms; + GlobalMemoryStatus (&ms); + return (double) ms.dwAvailPhys; } } #endif diff --git a/lib/pipe-filter-aux.h b/lib/pipe-filter-aux.h index 49644312d..4c88c316c 100644 --- a/lib/pipe-filter-aux.h +++ b/lib/pipe-filter-aux.h @@ -84,7 +84,7 @@ nonintr_write (int fd, const void *buf, size_t count) static inline int nonintr_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout) + struct timeval *timeout) { int retval; diff --git a/lib/pipe-filter-gi.c b/lib/pipe-filter-gi.c index 340b38af0..e45d39a80 100644 --- a/lib/pipe-filter-gi.c +++ b/lib/pipe-filter-gi.c @@ -86,13 +86,13 @@ static inline int filter_init (struct pipe_filter_gi *filter); /* Write count bytes starting at buf, while at the same time invoking the read iterator (the functions prepare_read/done_read) when needed. */ static void filter_loop (struct pipe_filter_gi *filter, - const char *wbuf, size_t count); + const char *wbuf, size_t count); /* Perform cleanup actions at the end. finish_reading is true if there was no error, or false if some error occurred already. */ static inline void filter_cleanup (struct pipe_filter_gi *filter, - bool finish_reading); + bool finish_reading); #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ @@ -108,25 +108,25 @@ reader_thread_func (void *thread_arg) size_t bufsize; void *buf = filter->prepare_read (&bufsize, filter->private_data); if (!(buf != NULL && bufsize > 0)) - /* prepare_read returned wrong values. */ - abort (); + /* prepare_read returned wrong values. */ + abort (); { - ssize_t nread = - read (filter->fd[0], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); - EnterCriticalSection (&filter->lock); - /* If the writer already encountered an error, terminate. */ - if (filter->writer_terminated) - break; - if (nread < 0) - { - filter->reader_errno = errno; - break; - } - else if (nread > 0) - filter->done_read (buf, nread, filter->private_data); - else /* nread == 0 */ - break; - LeaveCriticalSection (&filter->lock); + ssize_t nread = + read (filter->fd[0], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); + EnterCriticalSection (&filter->lock); + /* If the writer already encountered an error, terminate. */ + if (filter->writer_terminated) + break; + if (nread < 0) + { + filter->reader_errno = errno; + break; + } + else if (nread > 0) + filter->done_read (buf, nread, filter->private_data); + else /* nread == 0 */ + break; + LeaveCriticalSection (&filter->lock); } } @@ -144,12 +144,12 @@ filter_init (struct pipe_filter_gi *filter) filter->reader_thread_handle = (HANDLE) _beginthreadex (NULL, 100000, reader_thread_func, filter, - 0, NULL); + 0, NULL); if (filter->reader_thread_handle == NULL) { if (filter->exit_on_error) - error (EXIT_FAILURE, 0, _("creation of reading thread failed")); + error (EXIT_FAILURE, 0, _("creation of reading thread failed")); return -1; } else @@ -162,41 +162,41 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count) if (!filter->writer_terminated) { for (;;) - { - ssize_t nwritten; - - /* Allow the reader thread to continue. */ - LeaveCriticalSection (&filter->lock); - - nwritten = - write (filter->fd[1], wbuf, count > SSIZE_MAX ? SSIZE_MAX : count); - - /* Get the lock back from the reader thread. */ - EnterCriticalSection (&filter->lock); - - if (nwritten < 0) - { - /* Don't assume that the gnulib modules 'write' and 'sigpipe' are - used. */ - if (GetLastError () == ERROR_NO_DATA) - errno = EPIPE; - filter->writer_errno = errno; - filter->writer_terminated = true; - break; - } - else if (nwritten > 0) - { - count -= nwritten; - if (count == 0) - break; - wbuf += nwritten; - } - else /* nwritten == 0 */ - { - filter->writer_terminated = true; - break; - } - } + { + ssize_t nwritten; + + /* Allow the reader thread to continue. */ + LeaveCriticalSection (&filter->lock); + + nwritten = + write (filter->fd[1], wbuf, count > SSIZE_MAX ? SSIZE_MAX : count); + + /* Get the lock back from the reader thread. */ + EnterCriticalSection (&filter->lock); + + if (nwritten < 0) + { + /* Don't assume that the gnulib modules 'write' and 'sigpipe' are + used. */ + if (GetLastError () == ERROR_NO_DATA) + errno = EPIPE; + filter->writer_errno = errno; + filter->writer_terminated = true; + break; + } + else if (nwritten > 0) + { + count -= nwritten; + if (count == 0) + break; + wbuf += nwritten; + } + else /* nwritten == 0 */ + { + filter->writer_terminated = true; + break; + } + } } } @@ -248,15 +248,15 @@ filter_init (struct pipe_filter_gi *filter) int fcntl_flags; if ((fcntl_flags = fcntl (filter->fd[1], F_GETFL, 0)) < 0 - || fcntl (filter->fd[1], F_SETFL, fcntl_flags | O_NONBLOCK) == -1 - || (fcntl_flags = fcntl (filter->fd[0], F_GETFL, 0)) < 0 - || fcntl (filter->fd[0], F_SETFL, fcntl_flags | O_NONBLOCK) == -1) + || fcntl (filter->fd[1], F_SETFL, fcntl_flags | O_NONBLOCK) == -1 + || (fcntl_flags = fcntl (filter->fd[0], F_GETFL, 0)) < 0 + || fcntl (filter->fd[0], F_SETFL, fcntl_flags | O_NONBLOCK) == -1) { - if (filter->exit_on_error) - error (EXIT_FAILURE, errno, - _("cannot set up nonblocking I/O to %s subprocess"), - filter->progname); - return -1; + if (filter->exit_on_error) + error (EXIT_FAILURE, errno, + _("cannot set up nonblocking I/O to %s subprocess"), + filter->progname); + return -1; } } @@ -280,13 +280,13 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count) if (!done_writing) { if (filter->writer_terminated || filter->reader_terminated) - /* pipe_filter_gi_write was called when it should not be. */ - abort (); + /* pipe_filter_gi_write was called when it should not be. */ + abort (); } else { if (filter->reader_terminated) - return; + return; } /* Loop, trying to write the given buffer or reading, whichever is @@ -294,50 +294,50 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count) for (;;) { /* Here filter->writer_terminated is false. When it becomes true, this - loop is terminated. */ + loop is terminated. */ /* Whereas filter->reader_terminated is initially false but may become - true during this loop. */ + true during this loop. */ /* Here, if !done_writing, count > 0. When count becomes 0, this loop - is terminated. */ + is terminated. */ /* Here, if done_writing, filter->reader_terminated is false. When - filter->reader_terminated becomes true, this loop is terminated. */ + filter->reader_terminated becomes true, this loop is terminated. */ # if HAVE_SELECT int n; /* See whether reading or writing is possible. */ n = 1; if (!filter->reader_terminated) - { - FD_SET (filter->fd[0], &filter->readfds); - n = filter->fd[0] + 1; - } + { + FD_SET (filter->fd[0], &filter->readfds); + n = filter->fd[0] + 1; + } if (!done_writing) - { - FD_SET (filter->fd[1], &filter->writefds); - if (n <= filter->fd[1]) - n = filter->fd[1] + 1; - } + { + FD_SET (filter->fd[1], &filter->writefds); + if (n <= filter->fd[1]) + n = filter->fd[1] + 1; + } n = select (n, - (!filter->reader_terminated ? &filter->readfds : NULL), - (!done_writing ? &filter->writefds : NULL), - NULL, NULL); + (!filter->reader_terminated ? &filter->readfds : NULL), + (!done_writing ? &filter->writefds : NULL), + NULL, NULL); if (n < 0) - { - if (filter->exit_on_error) - error (EXIT_FAILURE, errno, - _("communication with %s subprocess failed"), - filter->progname); - filter->writer_errno = errno; - filter->writer_terminated = true; - break; - } + { + if (filter->exit_on_error) + error (EXIT_FAILURE, errno, + _("communication with %s subprocess failed"), + filter->progname); + filter->writer_errno = errno; + filter->writer_terminated = true; + break; + } if (!done_writing && FD_ISSET (filter->fd[1], &filter->writefds)) - goto try_write; + goto try_write; if (!filter->reader_terminated - && FD_ISSET (filter->fd[0], &filter->readfds)) - goto try_read; + && FD_ISSET (filter->fd[0], &filter->readfds)) + goto try_read; /* How could select() return if none of the two descriptors is ready? */ abort (); # endif @@ -348,29 +348,29 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count) # endif if (!done_writing) { - ssize_t nwritten = - write (filter->fd[1], wbuf, count > SSIZE_MAX ? SSIZE_MAX : count); - if (nwritten < 0) - { - if (!IS_EAGAIN (errno)) - { - if (filter->exit_on_error) - error (EXIT_FAILURE, errno, - _("write to %s subprocess failed"), - filter->progname); - filter->writer_errno = errno; - filter->writer_terminated = true; - break; - } - } - else if (nwritten > 0) - { - count -= nwritten; - if (count == 0) - break; - wbuf += nwritten; - } - } + ssize_t nwritten = + write (filter->fd[1], wbuf, count > SSIZE_MAX ? SSIZE_MAX : count); + if (nwritten < 0) + { + if (!IS_EAGAIN (errno)) + { + if (filter->exit_on_error) + error (EXIT_FAILURE, errno, + _("write to %s subprocess failed"), + filter->progname); + filter->writer_errno = errno; + filter->writer_terminated = true; + break; + } + } + else if (nwritten > 0) + { + count -= nwritten; + if (count == 0) + break; + wbuf += nwritten; + } + } # if HAVE_SELECT continue; # endif @@ -380,38 +380,38 @@ filter_loop (struct pipe_filter_gi *filter, const char *wbuf, size_t count) try_read: # endif if (!filter->reader_terminated) - { - size_t bufsize; - void *buf = filter->prepare_read (&bufsize, filter->private_data); - if (!(buf != NULL && bufsize > 0)) - /* prepare_read returned wrong values. */ - abort (); - { - ssize_t nread = - read (filter->fd[0], buf, - bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); - if (nread < 0) - { - if (!IS_EAGAIN (errno)) - { - if (filter->exit_on_error) - error (EXIT_FAILURE, errno, - _("read from %s subprocess failed"), - filter->progname); - filter->reader_errno = errno; - filter->reader_terminated = true; - break; - } - } - else if (nread > 0) - filter->done_read (buf, nread, filter->private_data); - else /* nread == 0 */ - { - filter->reader_terminated = true; - if (done_writing) - break; - } - } + { + size_t bufsize; + void *buf = filter->prepare_read (&bufsize, filter->private_data); + if (!(buf != NULL && bufsize > 0)) + /* prepare_read returned wrong values. */ + abort (); + { + ssize_t nread = + read (filter->fd[0], buf, + bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); + if (nread < 0) + { + if (!IS_EAGAIN (errno)) + { + if (filter->exit_on_error) + error (EXIT_FAILURE, errno, + _("read from %s subprocess failed"), + filter->progname); + filter->reader_errno = errno; + filter->reader_terminated = true; + break; + } + } + else if (nread > 0) + filter->done_read (buf, nread, filter->private_data); + else /* nread == 0 */ + { + filter->reader_terminated = true; + if (done_writing) + break; + } + } } # if HAVE_SELECT continue; @@ -444,13 +444,13 @@ filter_terminate (struct pipe_filter_gi *filter) filter_cleanup (filter, !filter->reader_terminated); close (filter->fd[0]); filter->exitstatus = - wait_subprocess (filter->child, filter->progname, true, - filter->null_stderr, true, filter->exit_on_error, - NULL); + wait_subprocess (filter->child, filter->progname, true, + filter->null_stderr, true, filter->exit_on_error, + NULL); if (filter->exitstatus != 0 && filter->exit_on_error) - error (EXIT_FAILURE, 0, - _("subprocess %s terminated with exit code %d"), - filter->progname, filter->exitstatus); + error (EXIT_FAILURE, 0, + _("subprocess %s terminated with exit code %d"), + filter->progname, filter->exitstatus); filter->exited = true; } } @@ -478,11 +478,11 @@ filter_retcode (struct pipe_filter_gi *filter) struct pipe_filter_gi * pipe_filter_gi_create (const char *progname, - const char *prog_path, const char **prog_argv, - bool null_stderr, bool exit_on_error, - prepare_read_fn prepare_read, - done_read_fn done_read, - void *private_data) + const char *prog_path, const char **prog_argv, + bool null_stderr, bool exit_on_error, + prepare_read_fn prepare_read, + done_read_fn done_read, + void *private_data) { struct pipe_filter_gi *filter; @@ -491,8 +491,8 @@ pipe_filter_gi_create (const char *progname, /* Open a bidirectional pipe to a subprocess. */ filter->child = create_pipe_bidi (progname, prog_path, (char **) prog_argv, - null_stderr, true, exit_on_error, - filter->fd); + null_stderr, true, exit_on_error, + filter->fd); filter->progname = progname; filter->null_stderr = null_stderr; filter->exit_on_error = exit_on_error; @@ -509,7 +509,7 @@ pipe_filter_gi_create (const char *progname, if (filter->child == -1) { /* Child process could not be created. - Arrange for filter_retcode (filter) to be the current errno. */ + Arrange for filter_retcode (filter) to be the current errno. */ filter->writer_errno = errno; filter->writer_terminated = true; filter->exited = true; @@ -522,7 +522,7 @@ pipe_filter_gi_create (const char *progname, int pipe_filter_gi_write (struct pipe_filter_gi *filter, - const void *buf, size_t size) + const void *buf, size_t size) { if (buf == NULL) /* Invalid argument. */ @@ -535,10 +535,10 @@ pipe_filter_gi_write (struct pipe_filter_gi *filter, { filter_loop (filter, buf, size); if (filter->writer_terminated || filter->reader_terminated) - { - filter_terminate (filter); - return filter_retcode (filter); - } + { + filter_terminate (filter); + return filter_retcode (filter); + } } return 0; } diff --git a/lib/pipe-filter-ii.c b/lib/pipe-filter-ii.c index cbdaf94f6..9c95aae7a 100644 --- a/lib/pipe-filter-ii.c +++ b/lib/pipe-filter-ii.c @@ -73,23 +73,23 @@ writer_thread_func (void *thread_arg) size_t bufsize; const void *buf = l->prepare_write (&bufsize, l->private_data); if (buf != NULL) - { - ssize_t nwritten = - write (l->fd[1], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); - if (nwritten < 0) - { - /* Don't assume that the gnulib modules 'write' and 'sigpipe' are - used. */ - if (GetLastError () == ERROR_NO_DATA) - errno = EPIPE; - l->writer_errno = errno; - break; - } - else if (nwritten > 0) - l->done_write ((void *) buf, nwritten, l->private_data); - } + { + ssize_t nwritten = + write (l->fd[1], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); + if (nwritten < 0) + { + /* Don't assume that the gnulib modules 'write' and 'sigpipe' are + used. */ + if (GetLastError () == ERROR_NO_DATA) + errno = EPIPE; + l->writer_errno = errno; + break; + } + else if (nwritten > 0) + l->done_write ((void *) buf, nwritten, l->private_data); + } else - break; + break; } l->writer_terminated = true; @@ -107,20 +107,20 @@ reader_thread_func (void *thread_arg) size_t bufsize; void *buf = l->prepare_read (&bufsize, l->private_data); if (!(buf != NULL && bufsize > 0)) - /* prepare_read returned wrong values. */ - abort (); + /* prepare_read returned wrong values. */ + abort (); { - ssize_t nread = - read (l->fd[0], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); - if (nread < 0) - { - l->reader_errno = errno; - break; - } - else if (nread > 0) - l->done_read (buf, nread, l->private_data); - else /* nread == 0 */ - break; + ssize_t nread = + read (l->fd[0], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); + if (nread < 0) + { + l->reader_errno = errno; + break; + } + else if (nread > 0) + l->done_read (buf, nread, l->private_data); + else /* nread == 0 */ + break; } } @@ -133,13 +133,13 @@ reader_thread_func (void *thread_arg) int pipe_filter_ii_execute (const char *progname, - const char *prog_path, const char **prog_argv, - bool null_stderr, bool exit_on_error, - prepare_write_fn prepare_write, - done_write_fn done_write, - prepare_read_fn prepare_read, - done_read_fn done_read, - void *private_data) + const char *prog_path, const char **prog_argv, + bool null_stderr, bool exit_on_error, + prepare_write_fn prepare_write, + done_write_fn done_write, + prepare_read_fn prepare_read, + done_read_fn done_read, + void *private_data) { pid_t child; int fd[2]; @@ -149,8 +149,8 @@ pipe_filter_ii_execute (const char *progname, /* Open a bidirectional pipe to a subprocess. */ child = create_pipe_bidi (progname, prog_path, (char **) prog_argv, - null_stderr, true, exit_on_error, - fd); + null_stderr, true, exit_on_error, + fd); if (child == -1) return -1; @@ -188,72 +188,72 @@ pipe_filter_ii_execute (const char *progname, (HANDLE) _beginthreadex (NULL, 100000, reader_thread_func, &l, 0, NULL); if (writer_thread_handle == NULL || reader_thread_handle == NULL) { - if (exit_on_error) - error (EXIT_FAILURE, 0, _("creation of threads failed")); - if (reader_thread_handle != NULL) - CloseHandle (reader_thread_handle); - if (writer_thread_handle != NULL) - CloseHandle (writer_thread_handle); - goto fail; + if (exit_on_error) + error (EXIT_FAILURE, 0, _("creation of threads failed")); + if (reader_thread_handle != NULL) + CloseHandle (reader_thread_handle); + if (writer_thread_handle != NULL) + CloseHandle (writer_thread_handle); + goto fail; } writer_cleaned_up = false; reader_cleaned_up = false; for (;;) { - DWORD ret; - - /* Here !(writer_cleaned_up && reader_cleaned_up). */ - if (writer_cleaned_up) - ret = WaitForSingleObject (reader_thread_handle, INFINITE); - else if (reader_cleaned_up) - ret = WaitForSingleObject (writer_thread_handle, INFINITE); - else - ret = WaitForMultipleObjects (2, handles, FALSE, INFINITE); - if (!(ret == WAIT_OBJECT_0 + 0 || ret == WAIT_OBJECT_0 + 1)) - abort (); - - if (l.writer_terminated) - { - /* The writer thread has just terminated. */ - l.writer_terminated = false; - CloseHandle (writer_thread_handle); - if (l.writer_errno) - { - if (exit_on_error) - error (EXIT_FAILURE, l.writer_errno, - _("write to %s subprocess failed"), progname); - if (!reader_cleaned_up) - { - TerminateThread (reader_thread_handle, 1); - CloseHandle (reader_thread_handle); - } - goto fail; - } - /* Tell the child there is nothing more the parent will send. */ - close (fd[1]); - writer_cleaned_up = true; - } - if (l.reader_terminated) - { - /* The reader thread has just terminated. */ - l.reader_terminated = false; - CloseHandle (reader_thread_handle); - if (l.reader_errno) - { - if (exit_on_error) - error (EXIT_FAILURE, l.reader_errno, - _("read from %s subprocess failed"), progname); - if (!writer_cleaned_up) - { - TerminateThread (writer_thread_handle, 1); - CloseHandle (writer_thread_handle); - } - goto fail; - } - reader_cleaned_up = true; - } - if (writer_cleaned_up && reader_cleaned_up) - break; + DWORD ret; + + /* Here !(writer_cleaned_up && reader_cleaned_up). */ + if (writer_cleaned_up) + ret = WaitForSingleObject (reader_thread_handle, INFINITE); + else if (reader_cleaned_up) + ret = WaitForSingleObject (writer_thread_handle, INFINITE); + else + ret = WaitForMultipleObjects (2, handles, FALSE, INFINITE); + if (!(ret == WAIT_OBJECT_0 + 0 || ret == WAIT_OBJECT_0 + 1)) + abort (); + + if (l.writer_terminated) + { + /* The writer thread has just terminated. */ + l.writer_terminated = false; + CloseHandle (writer_thread_handle); + if (l.writer_errno) + { + if (exit_on_error) + error (EXIT_FAILURE, l.writer_errno, + _("write to %s subprocess failed"), progname); + if (!reader_cleaned_up) + { + TerminateThread (reader_thread_handle, 1); + CloseHandle (reader_thread_handle); + } + goto fail; + } + /* Tell the child there is nothing more the parent will send. */ + close (fd[1]); + writer_cleaned_up = true; + } + if (l.reader_terminated) + { + /* The reader thread has just terminated. */ + l.reader_terminated = false; + CloseHandle (reader_thread_handle); + if (l.reader_errno) + { + if (exit_on_error) + error (EXIT_FAILURE, l.reader_errno, + _("read from %s subprocess failed"), progname); + if (!writer_cleaned_up) + { + TerminateThread (writer_thread_handle, 1); + CloseHandle (writer_thread_handle); + } + goto fail; + } + reader_cleaned_up = true; + } + if (writer_cleaned_up && reader_cleaned_up) + break; } } #else @@ -289,16 +289,16 @@ pipe_filter_ii_execute (const char *progname, 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) - { - if (exit_on_error) - error (EXIT_FAILURE, errno, - _("cannot set up nonblocking I/O to %s subprocess"), - progname); - goto fail; - } + || 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) + { + if (exit_on_error) + error (EXIT_FAILURE, errno, + _("cannot set up nonblocking I/O to %s subprocess"), + progname); + goto fail; + } } # if HAVE_SELECT @@ -309,105 +309,105 @@ pipe_filter_ii_execute (const char *progname, for (;;) { # if HAVE_SELECT - int n; - - FD_SET (fd[0], &readfds); - n = fd[0] + 1; - if (!done_writing) - { - FD_SET (fd[1], &writefds); - if (n <= fd[1]) - n = fd[1] + 1; - } - - n = select (n, &readfds, (!done_writing ? &writefds : NULL), NULL, - NULL); - if (n < 0) - { - if (exit_on_error) - error (EXIT_FAILURE, errno, - _("communication with %s subprocess failed"), progname); - goto fail; - } - if (!done_writing && FD_ISSET (fd[1], &writefds)) - goto try_write; - if (FD_ISSET (fd[0], &readfds)) - goto try_read; - /* How could select() return if none of the two descriptors is ready? */ - abort (); + int n; + + FD_SET (fd[0], &readfds); + n = fd[0] + 1; + if (!done_writing) + { + FD_SET (fd[1], &writefds); + if (n <= fd[1]) + n = fd[1] + 1; + } + + n = select (n, &readfds, (!done_writing ? &writefds : NULL), NULL, + NULL); + if (n < 0) + { + if (exit_on_error) + error (EXIT_FAILURE, errno, + _("communication with %s subprocess failed"), progname); + goto fail; + } + if (!done_writing && FD_ISSET (fd[1], &writefds)) + goto try_write; + if (FD_ISSET (fd[0], &readfds)) + goto try_read; + /* How could select() return if none of the two descriptors is ready? */ + abort (); # endif - /* Attempt to write. */ + /* Attempt to write. */ # if HAVE_SELECT try_write: # endif - if (!done_writing) - { - size_t bufsize; - const void *buf = prepare_write (&bufsize, private_data); - if (buf != NULL) - { - ssize_t nwritten = - write (fd[1], buf, - bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); - if (nwritten < 0) - { - if (!IS_EAGAIN (errno)) - { - if (exit_on_error) - error (EXIT_FAILURE, errno, - _("write to %s subprocess failed"), progname); - goto fail; - } - } - else if (nwritten > 0) - done_write ((void *) buf, nwritten, private_data); - } - else - { - /* Tell the child there is nothing more the parent will send. */ - close (fd[1]); - done_writing = true; - } - } + if (!done_writing) + { + size_t bufsize; + const void *buf = prepare_write (&bufsize, private_data); + if (buf != NULL) + { + ssize_t nwritten = + write (fd[1], buf, + bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); + if (nwritten < 0) + { + if (!IS_EAGAIN (errno)) + { + if (exit_on_error) + error (EXIT_FAILURE, errno, + _("write to %s subprocess failed"), progname); + goto fail; + } + } + else if (nwritten > 0) + done_write ((void *) buf, nwritten, private_data); + } + else + { + /* Tell the child there is nothing more the parent will send. */ + close (fd[1]); + done_writing = true; + } + } # if HAVE_SELECT - continue; + continue; # endif - /* Attempt to read. */ + /* Attempt to read. */ # if HAVE_SELECT try_read: # endif - { - size_t bufsize; - void *buf = prepare_read (&bufsize, private_data); - if (!(buf != NULL && bufsize > 0)) - /* prepare_read returned wrong values. */ - abort (); - { - ssize_t nread = - read (fd[0], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); - if (nread < 0) - { - if (!IS_EAGAIN (errno)) - { - if (exit_on_error) - error (EXIT_FAILURE, errno, - _("read from %s subprocess failed"), progname); - goto fail; - } - } - else if (nread > 0) - done_read (buf, nread, private_data); - else /* nread == 0 */ - { - if (done_writing) - break; - } - } - } + { + size_t bufsize; + void *buf = prepare_read (&bufsize, private_data); + if (!(buf != NULL && bufsize > 0)) + /* prepare_read returned wrong values. */ + abort (); + { + ssize_t nread = + read (fd[0], buf, bufsize > SSIZE_MAX ? SSIZE_MAX : bufsize); + if (nread < 0) + { + if (!IS_EAGAIN (errno)) + { + if (exit_on_error) + error (EXIT_FAILURE, errno, + _("read from %s subprocess failed"), progname); + goto fail; + } + } + else if (nread > 0) + done_read (buf, nread, private_data); + else /* nread == 0 */ + { + if (done_writing) + break; + } + } + } # if HAVE_SELECT - continue; + continue; # endif } } @@ -423,10 +423,10 @@ pipe_filter_ii_execute (const char *progname, { int exitstatus = wait_subprocess (child, progname, false, null_stderr, - true, exit_on_error, NULL); + true, exit_on_error, NULL); if (exitstatus != 0 && exit_on_error) error (EXIT_FAILURE, 0, _("%s subprocess terminated with exit code %d"), - progname, exitstatus); + progname, exitstatus); return exitstatus; } diff --git a/lib/pipe-filter.h b/lib/pipe-filter.h index 091823588..7979bd6c7 100644 --- a/lib/pipe-filter.h +++ b/lib/pipe-filter.h @@ -84,9 +84,9 @@ extern "C" { num_bytes_written > 0. Here p is always the private_data argument passed to the main function. */ typedef const void * (*prepare_write_fn) (size_t *num_bytes_p, - void *private_data); + void *private_data); typedef void (*done_write_fn) (void *data_written, size_t num_bytes_written, - void *private_data); + void *private_data); /* These two functions together describe the side that reads data from the subprocess when it has the form of an iterator. @@ -97,9 +97,9 @@ typedef void (*done_write_fn) (void *data_written, size_t num_bytes_written, bytes were read into the buffer. Here p is always the private_data argument passed to the main function. */ typedef void * (*prepare_read_fn) (size_t *num_bytes_p, - void *private_data); + void *private_data); typedef void (*done_read_fn) (void *data_read, size_t num_bytes_read, - void *private_data); + void *private_data); /* ============================ pipe_filter_ii ============================ */ @@ -133,13 +133,13 @@ typedef void (*done_read_fn) (void *data_read, size_t num_bytes_read, - the positive exit code of the subprocess if that failed. */ extern int pipe_filter_ii_execute (const char *progname, - const char *prog_path, const char **prog_argv, - bool null_stderr, bool exit_on_error, - prepare_write_fn prepare_write, - done_write_fn done_write, - prepare_read_fn prepare_read, - done_read_fn done_read, - void *private_data); + const char *prog_path, const char **prog_argv, + bool null_stderr, bool exit_on_error, + prepare_write_fn prepare_write, + done_write_fn done_write, + prepare_read_fn prepare_read, + done_read_fn done_read, + void *private_data); /* ============================ pipe_filter_ig ============================ */ @@ -179,11 +179,11 @@ struct pipe_filter_gi; Return the freshly created 'struct pipe_filter_gi'. */ extern struct pipe_filter_gi * pipe_filter_gi_create (const char *progname, - const char *prog_path, const char **prog_argv, - bool null_stderr, bool exit_on_error, - prepare_read_fn prepare_read, - done_read_fn done_read, - void *private_data); + const char *prog_path, const char **prog_argv, + bool null_stderr, bool exit_on_error, + prepare_read_fn prepare_read, + done_read_fn done_read, + void *private_data); /* Write size bytes starting at buf into the pipe and in the meanwhile possibly call the prepare_read and done_read functions specified to @@ -203,7 +203,7 @@ extern struct pipe_filter_gi * - the positive exit code of the subprocess if that failed. */ extern int pipe_filter_gi_write (struct pipe_filter_gi *filter, - const void *buf, size_t size); + const void *buf, size_t size); /* Finish reading the output via the prepare_read/done_read functions specified to pipe_filter_gi_create. diff --git a/lib/pipe.c b/lib/pipe.c index c3db1b586..3a4a3e6eb 100644 --- a/lib/pipe.c +++ b/lib/pipe.c @@ -105,12 +105,12 @@ nonintr_open (const char *pathname, int oflag, mode_t mode) */ 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]) + 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__ @@ -163,22 +163,22 @@ create_pipe (const char *progname, 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)))) + || ((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)))) + || 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))))) + || 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). */ @@ -192,16 +192,16 @@ create_pipe (const char *progname, [un]setenv(). */ { child = spawnvpe (P_NOWAIT, prog_path, (const char **) prog_argv, - (const char **) environ); + (const char **) environ); if (child < 0 && errno == ENOEXEC) - { - /* prog is not an 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); - } + { + /* prog is not an 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 (stdinfd >= 0) close (stdinfd); @@ -225,12 +225,12 @@ create_pipe (const char *progname, if (child == -1) { if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, errno, - _("%s subprocess failed"), progname); + error (exit_on_error ? EXIT_FAILURE : 0, errno, + _("%s subprocess failed"), progname); if (pipe_stdout) - close (ifd[0]); + close (ifd[0]); if (pipe_stdin) - close (ofd[1]); + close (ofd[1]); return -1; } @@ -277,79 +277,79 @@ create_pipe (const char *progname, 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)) + (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); + posix_spawn_file_actions_destroy (&actions); if (attrs_allocated) - posix_spawnattr_destroy (&attrs); + posix_spawnattr_destroy (&attrs); if (slave_process) - unblock_fatal_signals (); + unblock_fatal_signals (); if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, err, - _("%s subprocess failed"), progname); + error (exit_on_error ? EXIT_FAILURE : 0, err, + _("%s subprocess failed"), progname); if (pipe_stdout) - { - close (ifd[0]); - close (ifd[1]); - } + { + close (ifd[0]); + close (ifd[1]); + } if (pipe_stdin) - { - close (ofd[0]); - close (ofd[1]); - } + { + close (ofd[0]); + close (ofd[1]); + } return -1; } posix_spawn_file_actions_destroy (&actions); @@ -384,15 +384,15 @@ create_pipe (const char *progname, */ 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]) + 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); + true, true, NULL, NULL, + null_stderr, slave_process, exit_on_error, + fd); return result; } @@ -405,16 +405,16 @@ create_pipe_bidi (const char *progname, */ 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]) + 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); + false, true, prog_stdin, NULL, + null_stderr, slave_process, exit_on_error, + iofd); if (result != -1) fd[0] = iofd[0]; return result; @@ -429,16 +429,16 @@ create_pipe_in (const char *progname, */ 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]) + 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); + 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/lib/pipe.h b/lib/pipe.h index 082f6875f..5f00c4c41 100644 --- a/lib/pipe.h +++ b/lib/pipe.h @@ -82,10 +82,10 @@ extern "C" { * 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]); + 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. @@ -95,10 +95,10 @@ extern pid_t create_pipe_out (const char *progname, * */ 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]); + 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. * @@ -123,10 +123,10 @@ extern pid_t create_pipe_in (const char *progname, * 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]); + 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__ diff --git a/lib/pipe2.c b/lib/pipe2.c index 7def1b15c..0fdb97a23 100644 --- a/lib/pipe2.c +++ b/lib/pipe2.c @@ -51,13 +51,13 @@ pipe2 (int fd[2], int flags) 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; + int result = pipe2 (fd, flags); + if (!(result < 0 && errno == ENOSYS)) + { + have_pipe2_really = 1; + return result; + } + have_pipe2_really = -1; } } #endif @@ -96,10 +96,10 @@ pipe2 (int fd[2], int flags) 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; + || 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) @@ -107,10 +107,10 @@ pipe2 (int fd[2], int flags) 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; + || 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 diff --git a/lib/poll.c b/lib/poll.c index 3fa8872f7..7711b4586 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -112,10 +112,10 @@ typedef enum _FILE_INFORMATION_CLASS { } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; typedef DWORD (WINAPI *PNtQueryInformationFile) - (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); + (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); # ifndef PIPE_BUF -# define PIPE_BUF 512 +# define PIPE_BUF 512 # endif /* Compute revents values for file handle H. If some events cannot happen @@ -137,74 +137,74 @@ win32_compute_revents (HANDLE h, int *p_sought) { case FILE_TYPE_PIPE: if (!once_only) - { - NtQueryInformationFile = (PNtQueryInformationFile) - GetProcAddress (GetModuleHandle ("ntdll.dll"), - "NtQueryInformationFile"); - once_only = TRUE; - } + { + NtQueryInformationFile = (PNtQueryInformationFile) + GetProcAddress (GetModuleHandle ("ntdll.dll"), + "NtQueryInformationFile"); + once_only = TRUE; + } happened = 0; if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0) - { - if (avail) - happened |= *p_sought & (POLLIN | POLLRDNORM); - } + { + if (avail) + happened |= *p_sought & (POLLIN | POLLRDNORM); + } else - { - /* It was the write-end of the pipe. Check if it is writable. - If NtQueryInformationFile fails, optimistically assume the pipe is - writable. This could happen on Win9x, where NtQueryInformationFile - is not available, or if we inherit a pipe that doesn't permit - FILE_READ_ATTRIBUTES access on the write end (I think this should - not happen since WinXP SP2; WINE seems fine too). Otherwise, - ensure that enough space is available for atomic writes. */ + { + /* It was the write-end of the pipe. Check if it is writable. + If NtQueryInformationFile fails, optimistically assume the pipe is + writable. This could happen on Win9x, where NtQueryInformationFile + is not available, or if we inherit a pipe that doesn't permit + FILE_READ_ATTRIBUTES access on the write end (I think this should + not happen since WinXP SP2; WINE seems fine too). Otherwise, + ensure that enough space is available for atomic writes. */ memset (&iosb, 0, sizeof (iosb)); memset (&fpli, 0, sizeof (fpli)); if (!NtQueryInformationFile || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), - FilePipeLocalInformation) - || fpli.WriteQuotaAvailable >= PIPE_BUF - || (fpli.OutboundQuota < PIPE_BUF && - fpli.WriteQuotaAvailable == fpli.OutboundQuota)) - happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); - } + FilePipeLocalInformation) + || fpli.WriteQuotaAvailable >= PIPE_BUF + || (fpli.OutboundQuota < PIPE_BUF && + fpli.WriteQuotaAvailable == fpli.OutboundQuota)) + happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); + } return happened; case FILE_TYPE_CHAR: ret = WaitForSingleObject (h, 0); if (!IsConsoleHandle (h)) - return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0; + return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0; nbuffer = avail = 0; bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); if (bRet) - { - /* Input buffer. */ - *p_sought &= POLLIN | POLLRDNORM; - if (nbuffer == 0) - return POLLHUP; - if (!*p_sought) - return 0; - - irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD)); - bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail); - if (!bRet || avail == 0) - return POLLHUP; - - for (i = 0; i < avail; i++) - if (irbuffer[i].EventType == KEY_EVENT) - return *p_sought; - return 0; - } + { + /* Input buffer. */ + *p_sought &= POLLIN | POLLRDNORM; + if (nbuffer == 0) + return POLLHUP; + if (!*p_sought) + return 0; + + irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD)); + bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail); + if (!bRet || avail == 0) + return POLLHUP; + + for (i = 0; i < avail; i++) + if (irbuffer[i].EventType == KEY_EVENT) + return *p_sought; + return 0; + } else - { - /* Screen buffer. */ - *p_sought &= POLLOUT | POLLWRNORM | POLLWRBAND; - return *p_sought; - } + { + /* Screen buffer. */ + *p_sought &= POLLOUT | POLLWRNORM | POLLWRBAND; + return *p_sought; + } default: ret = WaitForSingleObject (h, 0); @@ -240,7 +240,7 @@ win32_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents) /* Distinguish hung-up sockets from other errors. */ else if (r == 0 || error == WSAESHUTDOWN || error == WSAECONNRESET - || error == WSAECONNABORTED || error == WSAENETRESET) + || error == WSAECONNABORTED || error == WSAENETRESET) happened |= POLLHUP; else @@ -276,27 +276,27 @@ compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds) r = recv (fd, NULL, 0, MSG_PEEK); socket_errno = (r < 0) ? errno : 0; if (r == 0 || socket_errno == ENOTSOCK) - ioctl (fd, FIONREAD, &r); + ioctl (fd, FIONREAD, &r); # else char data[64]; r = recv (fd, data, sizeof (data), MSG_PEEK); socket_errno = (r < 0) ? errno : 0; # endif if (r == 0) - happened |= POLLHUP; + happened |= POLLHUP; /* If the event happened on an unconnected server socket, that's fine. */ else if (r > 0 || ( /* (r == -1) && */ socket_errno == ENOTCONN)) - happened |= (POLLIN | POLLRDNORM) & sought; + happened |= (POLLIN | POLLRDNORM) & sought; /* Distinguish hung-up sockets from other errors. */ else if (socket_errno == ESHUTDOWN || socket_errno == ECONNRESET - || socket_errno == ECONNABORTED || socket_errno == ENETRESET) - happened |= POLLHUP; + || socket_errno == ECONNABORTED || socket_errno == ENETRESET) + happened |= POLLHUP; else - happened |= POLLERR; + happened |= POLLERR; } if (FD_ISSET (fd, wfds)) @@ -328,7 +328,7 @@ poll (pfd, nfd, timeout) if (nfd < 0 || (nfd > sc_open_max && (sc_open_max != -1 - || nfd > (sc_open_max = sysconf (_SC_OPEN_MAX))))) + || nfd > (sc_open_max = sysconf (_SC_OPEN_MAX))))) { errno = EINVAL; return -1; @@ -381,30 +381,30 @@ poll (pfd, nfd, timeout) for (i = 0; i < nfd; i++) { if (pfd[i].fd < 0) - continue; + continue; if (pfd[i].events & (POLLIN | POLLRDNORM)) - FD_SET (pfd[i].fd, &rfds); + FD_SET (pfd[i].fd, &rfds); /* see select(2): "the only exceptional condition detectable is out-of-band data received on a socket", hence we push POLLWRBAND events onto wfds instead of efds. */ if (pfd[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND)) - FD_SET (pfd[i].fd, &wfds); + FD_SET (pfd[i].fd, &wfds); if (pfd[i].events & (POLLPRI | POLLRDBAND)) - FD_SET (pfd[i].fd, &efds); + FD_SET (pfd[i].fd, &efds); if (pfd[i].fd >= maxfd - && (pfd[i].events & (POLLIN | POLLOUT | POLLPRI - | POLLRDNORM | POLLRDBAND - | POLLWRNORM | POLLWRBAND))) - { - maxfd = pfd[i].fd; - if (maxfd > FD_SETSIZE) - { - errno = EOVERFLOW; - return -1; - } - } + && (pfd[i].events & (POLLIN | POLLOUT | POLLPRI + | POLLRDNORM | POLLRDBAND + | POLLWRNORM | POLLWRBAND))) + { + maxfd = pfd[i].fd; + if (maxfd > FD_SETSIZE) + { + errno = EOVERFLOW; + return -1; + } + } } /* examine fd sets */ @@ -421,11 +421,11 @@ poll (pfd, nfd, timeout) { int happened = compute_revents (pfd[i].fd, pfd[i].events, &rfds, &wfds, &efds); - if (happened) - { - pfd[i].revents = happened; - rc++; - } + if (happened) + { + pfd[i].revents = happened; + rc++; + } } return rc; @@ -464,8 +464,8 @@ poll (pfd, nfd, timeout) if (pfd[i].fd < 0) continue; if (!(sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND - | POLLPRI | POLLRDBAND))) - continue; + | POLLPRI | POLLRDBAND))) + continue; h = (HANDLE) _get_osfhandle (pfd[i].fd); assert (h != NULL); @@ -475,42 +475,42 @@ poll (pfd, nfd, timeout) /* see above; socket handles are mapped onto select. */ if (sought & (POLLIN | POLLRDNORM)) - { + { requested |= FD_READ | FD_ACCEPT; - FD_SET ((SOCKET) h, &rfds); - } + FD_SET ((SOCKET) h, &rfds); + } if (sought & (POLLOUT | POLLWRNORM | POLLWRBAND)) - { + { requested |= FD_WRITE | FD_CONNECT; - FD_SET ((SOCKET) h, &wfds); - } + FD_SET ((SOCKET) h, &wfds); + } if (sought & (POLLPRI | POLLRDBAND)) - { + { requested |= FD_OOB; - FD_SET ((SOCKET) h, &xfds); - } + FD_SET ((SOCKET) h, &xfds); + } if (requested) WSAEventSelect ((SOCKET) h, hEvent, requested); } else { - /* Poll now. If we get an event, do not poll again. Also, - screen buffer handles are waitable, and they'll block until - a character is available. win32_compute_revents eliminates - bits for the "wrong" direction. */ + /* Poll now. If we get an event, do not poll again. Also, + screen buffer handles are waitable, and they'll block until + a character is available. win32_compute_revents eliminates + bits for the "wrong" direction. */ pfd[i].revents = win32_compute_revents (h, &sought); - if (sought) - handle_array[nhandles++] = h; + if (sought) + handle_array[nhandles++] = h; if (pfd[i].revents) - wait_timeout = 0; + wait_timeout = 0; } } if (select (0, &rfds, &wfds, &xfds, &tv0) > 0) { /* Do MsgWaitForMultipleObjects anyway to dispatch messages, but - no need to call select again. */ + no need to call select again. */ poll_again = FALSE; wait_timeout = 0; } @@ -526,20 +526,20 @@ poll (pfd, nfd, timeout) for (;;) { ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE, - wait_timeout, QS_ALLINPUT); + wait_timeout, QS_ALLINPUT); if (ret == WAIT_OBJECT_0 + nhandles) - { + { /* new input of some other kind */ - BOOL bRet; + BOOL bRet; while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0) { TranslateMessage (&msg); DispatchMessage (&msg); } - } + } else - break; + break; } if (poll_again) @@ -556,27 +556,27 @@ poll (pfd, nfd, timeout) continue; if (!(pfd[i].events & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND))) - continue; + continue; h = (HANDLE) _get_osfhandle (pfd[i].fd); if (h != handle_array[nhandles]) { /* It's a socket. */ WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev); - WSAEventSelect ((SOCKET) h, 0, 0); - - /* If we're lucky, WSAEnumNetworkEvents already provided a way - to distinguish FD_READ and FD_ACCEPT; this saves a recv later. */ - if (FD_ISSET ((SOCKET) h, &rfds) - && !(ev.lNetworkEvents & (FD_READ | FD_ACCEPT))) - ev.lNetworkEvents |= FD_READ | FD_ACCEPT; - if (FD_ISSET ((SOCKET) h, &wfds)) - ev.lNetworkEvents |= FD_WRITE | FD_CONNECT; - if (FD_ISSET ((SOCKET) h, &xfds)) - ev.lNetworkEvents |= FD_OOB; + WSAEventSelect ((SOCKET) h, 0, 0); + + /* If we're lucky, WSAEnumNetworkEvents already provided a way + to distinguish FD_READ and FD_ACCEPT; this saves a recv later. */ + if (FD_ISSET ((SOCKET) h, &rfds) + && !(ev.lNetworkEvents & (FD_READ | FD_ACCEPT))) + ev.lNetworkEvents |= FD_READ | FD_ACCEPT; + if (FD_ISSET ((SOCKET) h, &wfds)) + ev.lNetworkEvents |= FD_WRITE | FD_CONNECT; + if (FD_ISSET ((SOCKET) h, &xfds)) + ev.lNetworkEvents |= FD_OOB; happened = win32_compute_revents_socket ((SOCKET) h, pfd[i].events, - ev.lNetworkEvents); + ev.lNetworkEvents); } else { diff --git a/lib/poll.in.h b/lib/poll.in.h index 6ab04812f..a6b1ed2d0 100644 --- a/lib/poll.in.h +++ b/lib/poll.in.h @@ -23,12 +23,12 @@ #define _GL_POLL_H /* fake a poll(2) environment */ -#define POLLIN 0x0001 /* any readable data available */ -#define POLLPRI 0x0002 /* OOB/Urgent readable data */ -#define POLLOUT 0x0004 /* file descriptor is writeable */ -#define POLLERR 0x0008 /* some poll error occurred */ -#define POLLHUP 0x0010 /* file descriptor was "hung up" */ -#define POLLNVAL 0x0020 /* requested events "invalid" */ +#define POLLIN 0x0001 /* any readable data available */ +#define POLLPRI 0x0002 /* OOB/Urgent readable data */ +#define POLLOUT 0x0004 /* file descriptor is writeable */ +#define POLLERR 0x0008 /* some poll error occurred */ +#define POLLHUP 0x0010 /* file descriptor was "hung up" */ +#define POLLNVAL 0x0020 /* requested events "invalid" */ #define POLLRDNORM 0x0040 #define POLLRDBAND 0x0080 #define POLLWRNORM 0x0100 @@ -36,9 +36,9 @@ struct pollfd { - int fd; /* which file descriptor to poll */ - short events; /* events we are interested in */ - short revents; /* events found on return */ + int fd; /* which file descriptor to poll */ + short events; /* events we are interested in */ + short revents; /* events found on return */ }; typedef unsigned long nfds_t; diff --git a/lib/popen-safer.c b/lib/popen-safer.c index 3d87c28bb..0fd335011 100644 --- a/lib/popen-safer.c +++ b/lib/popen-safer.c @@ -41,9 +41,9 @@ open_noinherit (char const *name, int flags) { fd = open (name, flags | O_CLOEXEC); if (have_cloexec == 0 && (0 <= fd || errno == EINVAL)) - have_cloexec = (0 <= fd ? 1 : -1); + have_cloexec = (0 <= fd ? 1 : -1); if (have_cloexec == 1) - return fd; + return fd; } #endif @@ -85,7 +85,7 @@ popen_safer (char const *cmd, char const *mode) else { /* Either all fd's are tied up, or fd is safe and the real popen - will reuse it. */ + will reuse it. */ close (fd); fp = popen (cmd, mode); } diff --git a/lib/popen.c b/lib/popen.c index 92a8050fd..5abf92448 100644 --- a/lib/popen.c +++ b/lib/popen.c @@ -59,16 +59,16 @@ rpl_popen (const char *filename, const char *mode) if (cloexec0 < 0) { if (open ("/dev/null", O_RDONLY) != STDIN_FILENO - || fcntl (STDIN_FILENO, F_SETFD, - fcntl (STDIN_FILENO, F_GETFD) | FD_CLOEXEC) == -1) - abort (); + || fcntl (STDIN_FILENO, F_SETFD, + fcntl (STDIN_FILENO, F_GETFD) | FD_CLOEXEC) == -1) + abort (); } if (cloexec1 < 0) { if (open ("/dev/null", O_RDONLY) != STDOUT_FILENO - || fcntl (STDOUT_FILENO, F_SETFD, - fcntl (STDOUT_FILENO, F_GETFD) | FD_CLOEXEC) == -1) - abort (); + || fcntl (STDOUT_FILENO, F_SETFD, + fcntl (STDOUT_FILENO, F_GETFD) | FD_CLOEXEC) == -1) + abort (); } result = popen (filename, mode); /* Now, close any dummy fd's created in the parent. */ diff --git a/lib/posixtm.c b/lib/posixtm.c index b94c3410d..7ed9c0d29 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -66,33 +66,33 @@ year (struct tm *tm, const int *digit_pair, size_t n, unsigned int syntax_bits) case 1: tm->tm_year = *digit_pair; /* Deduce the century based on the year. - POSIX requires that 00-68 be interpreted as 2000-2068, - and that 69-99 be interpreted as 1969-1999. */ + POSIX requires that 00-68 be interpreted as 2000-2068, + and that 69-99 be interpreted as 1969-1999. */ if (digit_pair[0] <= 68) - { - if (syntax_bits & PDS_PRE_2000) - return 1; - tm->tm_year += 100; - } + { + if (syntax_bits & PDS_PRE_2000) + return 1; + tm->tm_year += 100; + } break; case 2: if (! (syntax_bits & PDS_CENTURY)) - return 1; + return 1; tm->tm_year = digit_pair[0] * 100 + digit_pair[1] - 1900; break; case 0: { - time_t now; - struct tm *tmp; - - /* Use current year. */ - time (&now); - tmp = localtime (&now); - if (! tmp) - return 1; - tm->tm_year = tmp->tm_year; + time_t now; + struct tm *tmp; + + /* Use current year. */ + time (&now); + tmp = localtime (&now); + if (! tmp) + return 1; + tm->tm_year = tmp->tm_year; } break; @@ -113,8 +113,8 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) size_t s_len = strlen (s); size_t len = (((syntax_bits & PDS_SECONDS) && (dot = strchr (s, '.'))) - ? (size_t) (dot - s) - : s_len); + ? (size_t) (dot - s) + : s_len); if (len != 8 && len != 10 && len != 12) return 1; @@ -122,10 +122,10 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) if (dot) { if (!(syntax_bits & PDS_SECONDS)) - return 1; + return 1; if (s_len - len != 3) - return 1; + return 1; } for (i = 0; i < len; i++) @@ -140,7 +140,7 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) if (syntax_bits & PDS_LEADING_YEAR) { if (year (tm, p, len - 4, syntax_bits)) - return 1; + return 1; p += len - 4; len = 4; } @@ -156,7 +156,7 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) if (syntax_bits & PDS_TRAILING_YEAR) { if (year (tm, p, len, syntax_bits)) - return 1; + return 1; } /* Handle seconds. */ @@ -170,7 +170,7 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) ++dot; if (!ISDIGIT (dot[0]) || !ISDIGIT (dot[1])) - return 1; + return 1; seconds = 10 * (dot[0] - '0') + dot[1] - '0'; tm->tm_sec = seconds; @@ -201,10 +201,10 @@ posixtime (time_t *p, const char *s, unsigned int syntax_bits) else { /* mktime returns -1 for errors, but -1 is also a valid time_t - value. Check whether an error really occurred. */ + value. Check whether an error really occurred. */ tm = localtime (&t); if (! tm) - return false; + return false; } /* Reject dates like "September 31" and times like "25:61". diff --git a/lib/posixver.c b/lib/posixver.c index 73a648256..89b7c1898 100644 --- a/lib/posixver.c +++ b/lib/posixver.c @@ -48,7 +48,7 @@ posix2_version (void) char *e; long int i = strtol (s, &e, 10); if (! *e) - v = i; + v = i; } return v < INT_MIN ? INT_MIN : v < INT_MAX ? v : INT_MAX; diff --git a/lib/pread.c b/lib/pread.c index 7094ea7d0..3b12fd78c 100644 --- a/lib/pread.c +++ b/lib/pread.c @@ -56,7 +56,7 @@ pread (int fd, void *buf, size_t nbyte, off_t offset) if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1) { if (result == -1) - __set_errno (save_errno); + __set_errno (save_errno); return -1; } __set_errno (save_errno); diff --git a/lib/printf-args.c b/lib/printf-args.c index e9942397a..96c6302c5 100644 --- a/lib/printf-args.c +++ b/lib/printf-args.c @@ -43,146 +43,146 @@ PRINTF_FETCHARGS (va_list args, arguments *a) switch (ap->type) { case TYPE_SCHAR: - ap->a.a_schar = va_arg (args, /*signed char*/ int); - break; + 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; + ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); + break; case TYPE_SHORT: - ap->a.a_short = va_arg (args, /*short*/ int); - break; + ap->a.a_short = va_arg (args, /*short*/ int); + break; case TYPE_USHORT: - ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); - break; + ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); + break; case TYPE_INT: - ap->a.a_int = va_arg (args, int); - break; + ap->a.a_int = va_arg (args, int); + break; case TYPE_UINT: - ap->a.a_uint = va_arg (args, unsigned int); - break; + ap->a.a_uint = va_arg (args, unsigned int); + break; case TYPE_LONGINT: - ap->a.a_longint = va_arg (args, long int); - break; + ap->a.a_longint = va_arg (args, long int); + break; case TYPE_ULONGINT: - ap->a.a_ulongint = va_arg (args, unsigned long int); - break; + 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; + 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; + 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; + ap->a.a_double = va_arg (args, double); + break; case TYPE_LONGDOUBLE: - ap->a.a_longdouble = va_arg (args, long double); - break; + ap->a.a_longdouble = va_arg (args, long double); + break; case TYPE_CHAR: - ap->a.a_char = va_arg (args, int); - break; + 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; + /* 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + /* Unknown type. */ + return -1; } return 0; } diff --git a/lib/printf-args.h b/lib/printf-args.h index 6f75e2aea..7428038a2 100644 --- a/lib/printf-args.h +++ b/lib/printf-args.h @@ -93,42 +93,42 @@ 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; + 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; + 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; + float a_float; + double a_double; + long double a_longdouble; + int a_char; #if HAVE_WINT_T - wint_t a_wide_char; + wint_t a_wide_char; #endif - const char* a_string; + const char* a_string; #if HAVE_WCHAR_T - const wchar_t* a_wide_string; + 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; + 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; + 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; + const uint8_t * a_u8_string; + const uint16_t * a_u16_string; + const uint32_t * a_u32_string; #endif } a; diff --git a/lib/printf-frexp.c b/lib/printf-frexp.c index da5c9c3a4..a01ab19e8 100644 --- a/lib/printf-frexp.c +++ b/lib/printf-frexp.c @@ -92,76 +92,76 @@ FUNC (DOUBLE x, int *expptr) 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. */ + /* 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. */ + /* 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 @@ -169,12 +169,12 @@ FUNC (DOUBLE x, int *expptr) 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]; - } + 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. */ diff --git a/lib/printf-parse.c b/lib/printf-parse.c index b11f6bb22..a089a95e2 100644 --- a/lib/printf-parse.c +++ b/lib/printf-parse.c @@ -80,10 +80,10 @@ STATIC 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 */ + 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; @@ -99,501 +99,501 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) a->arg = NULL; #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 \ - ? realloc (a->arg, memory_size) \ - : malloc (memory_size)); \ - if (memory == NULL) \ - /* Out of memory. */ \ - goto out_of_memory; \ - 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; \ + { \ + 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 \ + ? realloc (a->arg, memory_size) \ + : malloc (memory_size)); \ + if (memory == NULL) \ + /* Out of memory. */ \ + goto out_of_memory; \ + 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++; - } - 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++; - } + { + 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++; + } + 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 MacOS 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++; - } + /* On MacOS 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 Win32, 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; - } + /* On native Win32, 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': + 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 + /* 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 '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 + /* 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 '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; + type = TYPE_WIDE_CHAR; #else - goto error; + goto error; #endif - else - type = TYPE_CHAR; - break; + else + type = TYPE_CHAR; + break; #if HAVE_WINT_T - case 'C': - type = TYPE_WIDE_CHAR; - c = 'c'; - break; + case 'C': + type = TYPE_WIDE_CHAR; + c = 'c'; + break; #endif - case 's': - if (flags >= 8) + case 's': + if (flags >= 8) #if HAVE_WCHAR_T - type = TYPE_WIDE_STRING; + type = TYPE_WIDE_STRING; #else - goto error; + goto error; #endif - else - type = TYPE_STRING; - break; + else + type = TYPE_STRING; + break; #if HAVE_WCHAR_T - case 'S': - type = TYPE_WIDE_STRING; - c = 's'; - break; + case 'S': + type = TYPE_WIDE_STRING; + c = 's'; + break; #endif - case 'p': - type = TYPE_POINTER; - break; - case 'n': + 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 + /* 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 '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; + /* 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 *) realloc (d->dir, memory_size); - if (memory == NULL) - /* Out of memory. */ - goto out_of_memory; - d->dir = memory; - } - } + 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 *) realloc (d->dir, memory_size); + if (memory == NULL) + /* Out of memory. */ + goto out_of_memory; + d->dir = memory; + } + } #if CHAR_T_ONLY_ASCII else if (!c_isascii (c)) - { - /* Non-ASCII character. Not supported. */ - goto error; - } + { + /* Non-ASCII character. Not supported. */ + goto error; + } #endif } d->dir[d->count].dir_start = cp; diff --git a/lib/printf-parse.h b/lib/printf-parse.h index de7fc49b6..8dc15d9e8 100644 --- a/lib/printf-parse.h +++ b/lib/printf-parse.h @@ -26,15 +26,15 @@ /* 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 +#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 /* arg_index value indicating that no argument is consumed. */ -#define ARG_NONE (~(size_t)0) +#define ARG_NONE (~(size_t)0) /* xxx_directive: A parsed directive. xxx_directives: A parsed format string. */ @@ -163,10 +163,10 @@ 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); + arguments *a); extern int u32_printf_parse (const uint32_t *format, u32_directives *d, - arguments *a); + arguments *a); #else # ifdef STATIC STATIC diff --git a/lib/priv-set.c b/lib/priv-set.c index 0051ce670..3155beccd 100644 --- a/lib/priv-set.c +++ b/lib/priv-set.c @@ -41,21 +41,21 @@ priv_set_initialize (void) { eff_set = priv_allocset (); if (!eff_set) - { - return -1; - } + { + return -1; + } rem_set = priv_allocset (); if (!rem_set) - { - priv_freeset (eff_set); - return -1; - } + { + priv_freeset (eff_set); + return -1; + } if (getppriv (PRIV_EFFECTIVE, eff_set) != 0) - { - priv_freeset (eff_set); - priv_freeset (rem_set); - return -1; - } + { + priv_freeset (eff_set); + priv_freeset (rem_set); + return -1; + } priv_emptyset (rem_set); initialized = true; } @@ -89,13 +89,13 @@ priv_set_remove (const char *priv) if (priv_ismember (eff_set, priv)) { /* priv_addset/priv_delset can only fail if priv is invalid, which is - checked above by the priv_ismember call. */ + checked above by the priv_ismember call. */ priv_delset (eff_set, priv); if (setppriv (PRIV_SET, PRIV_EFFECTIVE, eff_set) != 0) - { - priv_addset (eff_set, priv); - return -1; - } + { + priv_addset (eff_set, priv); + return -1; + } priv_addset (rem_set, priv); } else @@ -122,13 +122,13 @@ priv_set_restore (const char *priv) if (priv_ismember (rem_set, priv)) { /* priv_addset/priv_delset can only fail if priv is invalid, which is - checked above by the priv_ismember call. */ + checked above by the priv_ismember call. */ priv_addset (eff_set, priv); if (setppriv (PRIV_SET, PRIV_EFFECTIVE, eff_set) != 0) - { - priv_delset (eff_set, priv); - return -1; - } + { + priv_delset (eff_set, priv); + return -1; + } priv_delset (rem_set, priv); } else diff --git a/lib/progname.c b/lib/progname.c index 2e82ac9ed..a5e5eaf88 100644 --- a/lib/progname.c +++ b/lib/progname.c @@ -52,7 +52,7 @@ set_program_name (const char *argv0) { /* 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); + stderr); abort (); } @@ -62,14 +62,14 @@ set_program_name (const char *argv0) { 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. */ + { + 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; + program_invocation_short_name = (char *) argv0; #endif - } + } } /* But don't strip off a leading / in general, because when the user diff --git a/lib/progname.h b/lib/progname.h index b223970f6..da4ee7eba 100644 --- a/lib/progname.h +++ b/lib/progname.h @@ -41,8 +41,8 @@ extern void set_program_name (const char *argv0); /* 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); + 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) diff --git a/lib/progreloc.c b/lib/progreloc.c index 9ae08fb70..56d3294cd 100644 --- a/lib/progreloc.c +++ b/lib/progreloc.c @@ -113,19 +113,19 @@ maybe_executable (const char *filename) if (executable_fd >= 0) { /* If we already have an executable_fd, check that filename points to - the same inode. */ + the same inode. */ struct stat statexe; struct stat statfile; if (fstat (executable_fd, &statexe) >= 0) - { - if (stat (filename, &statfile) < 0) - return false; - if (!(statfile.st_dev - && statfile.st_dev == statexe.st_dev - && statfile.st_ino == statexe.st_ino)) - return false; - } + { + if (stat (filename, &statfile) < 0) + return false; + if (!(statfile.st_dev + && statfile.st_dev == statexe.st_dev + && statfile.st_ino == statexe.st_ino)) + return false; + } } #endif #endif @@ -192,9 +192,9 @@ find_executable (const char *argv0) sprintf (buf, "/proc/%d/exe", getpid ()); link = xreadlink (buf); if (link != NULL && link[0] != '[') - return link; + return link; if (executable_fd < 0) - executable_fd = open (buf, O_RDONLY, 0); + executable_fd = open (buf, O_RDONLY, 0); } } #endif @@ -216,57 +216,57 @@ find_executable (const char *argv0) { const char *p; for (p = argv0; *p; p++) - if (*p == '/') - { - has_slash = true; - break; - } + if (*p == '/') + { + has_slash = true; + break; + } } if (!has_slash) { - /* exec searches paths without slashes in the directory list given - by $PATH. */ - const char *path = getenv ("PATH"); - - if (path != NULL) - { - const char *p; - const char *p_next; - - for (p = path; *p; p = p_next) - { - const char *q; - size_t p_len; - char *concat_name; - - for (q = p; *q; q++) - if (*q == ':') - break; - p_len = q - p; - p_next = (*q == '\0' ? q : q + 1); - - /* We have a path item at p, of length p_len. - Now concatenate the path item and argv0. */ - concat_name = (char *) xmalloc (p_len + strlen (argv0) + 2); + /* exec searches paths without slashes in the directory list given + by $PATH. */ + const char *path = getenv ("PATH"); + + if (path != NULL) + { + const char *p; + const char *p_next; + + for (p = path; *p; p = p_next) + { + const char *q; + size_t p_len; + char *concat_name; + + for (q = p; *q; q++) + if (*q == ':') + break; + p_len = q - p; + p_next = (*q == '\0' ? q : q + 1); + + /* We have a path item at p, of length p_len. + Now concatenate the path item and argv0. */ + concat_name = (char *) xmalloc (p_len + strlen (argv0) + 2); #ifdef NO_XMALLOC - if (concat_name == NULL) - return NULL; + if (concat_name == NULL) + return NULL; #endif - if (p_len == 0) - /* An empty PATH element designates the current directory. */ - strcpy (concat_name, argv0); - else - { - memcpy (concat_name, p, p_len); - concat_name[p_len] = '/'; - strcpy (concat_name + p_len + 1, argv0); - } - if (maybe_executable (concat_name)) - return canonicalize_file_name (concat_name); - free (concat_name); - } - } - /* Not found in the PATH, assume the current directory. */ + if (p_len == 0) + /* An empty PATH element designates the current directory. */ + strcpy (concat_name, argv0); + else + { + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, argv0); + } + if (maybe_executable (concat_name)) + return canonicalize_file_name (concat_name); + free (concat_name); + } + } + /* Not found in the PATH, assume the current directory. */ } /* exec treats paths containing slashes as relative to the current directory. */ @@ -283,7 +283,7 @@ static char *executable_fullname; static void prepare_relocate (const char *orig_installprefix, const char *orig_installdir, - const char *argv0) + const char *argv0) { char *curr_prefix; @@ -292,7 +292,7 @@ prepare_relocate (const char *orig_installprefix, const char *orig_installdir, /* Determine the current installation prefix from it. */ curr_prefix = compute_curr_prefix (orig_installprefix, orig_installdir, - executable_fullname); + executable_fullname); if (curr_prefix != NULL) { /* Now pass this prefix to all copies of the relocate.c source file. */ @@ -306,8 +306,8 @@ prepare_relocate (const char *orig_installprefix, const char *orig_installdir, directory, for relocatability. */ void set_program_name_and_installdir (const char *argv0, - const char *orig_installprefix, - const char *orig_installdir) + const char *orig_installprefix, + const char *orig_installdir) { const char *argv0_stripped = argv0; @@ -319,42 +319,42 @@ set_program_name_and_installdir (const char *argv0, const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); if (argv0_len > 4 + exeext_len) if (memcmp (argv0 + argv0_len - exeext_len - 4, ".bin", 4) == 0) - { - if (sizeof (EXEEXT) > sizeof ("")) - { - /* Compare using an inlined copy of c_strncasecmp(), because - the filenames may have undergone a case conversion since - they were packaged. In other words, EXEEXT may be ".exe" - on one system and ".EXE" on another. */ - static const char exeext[] = EXEEXT; - const char *s1 = argv0 + argv0_len - exeext_len; - const char *s2 = exeext; - for (; *s1 != '\0'; s1++, s2++) - { - unsigned char c1 = *s1; - unsigned char c2 = *s2; - if ((c1 >= 'A' && c1 <= 'Z' ? c1 - 'A' + 'a' : c1) - != (c2 >= 'A' && c2 <= 'Z' ? c2 - 'A' + 'a' : c2)) - goto done_stripping; - } - } - /* Remove ".bin" before EXEEXT or its equivalent. */ - { - char *shorter = (char *) xmalloc (argv0_len - 4 + 1); + { + if (sizeof (EXEEXT) > sizeof ("")) + { + /* Compare using an inlined copy of c_strncasecmp(), because + the filenames may have undergone a case conversion since + they were packaged. In other words, EXEEXT may be ".exe" + on one system and ".EXE" on another. */ + static const char exeext[] = EXEEXT; + const char *s1 = argv0 + argv0_len - exeext_len; + const char *s2 = exeext; + for (; *s1 != '\0'; s1++, s2++) + { + unsigned char c1 = *s1; + unsigned char c2 = *s2; + if ((c1 >= 'A' && c1 <= 'Z' ? c1 - 'A' + 'a' : c1) + != (c2 >= 'A' && c2 <= 'Z' ? c2 - 'A' + 'a' : c2)) + goto done_stripping; + } + } + /* Remove ".bin" before EXEEXT or its equivalent. */ + { + char *shorter = (char *) xmalloc (argv0_len - 4 + 1); #ifdef NO_XMALLOC - if (shorter != NULL) + if (shorter != NULL) #endif - { - memcpy (shorter, argv0, argv0_len - exeext_len - 4); - if (sizeof (EXEEXT) > sizeof ("")) - memcpy (shorter + argv0_len - exeext_len - 4, - argv0 + argv0_len - exeext_len - 4, - exeext_len); - shorter[argv0_len - 4] = '\0'; - argv0_stripped = shorter; - } - } - done_stripping: ; + { + memcpy (shorter, argv0, argv0_len - exeext_len - 4); + if (sizeof (EXEEXT) > sizeof ("")) + memcpy (shorter + argv0_len - exeext_len - 4, + argv0 + argv0_len - exeext_len - 4, + exeext_len); + shorter[argv0_len - 4] = '\0'; + argv0_stripped = shorter; + } + } + done_stripping: ; } } diff --git a/lib/propername.c b/lib/propername.c index 381a7a72c..966e0f655 100644 --- a/lib/propername.c +++ b/lib/propername.c @@ -55,92 +55,92 @@ mbsstr_trimmed_wordbounded (const char *string, const char *sub) { const char *tsub_in_string = mbsstr (string, tsub); if (tsub_in_string == NULL) - break; + break; else - { - if (MB_CUR_MAX > 1) - { - mbui_iterator_t string_iter; - bool word_boundary_before; - bool word_boundary_after; - - mbui_init (string_iter, string); - word_boundary_before = true; - if (mbui_cur_ptr (string_iter) < tsub_in_string) - { - mbchar_t last_char_before_tsub; - do - { - if (!mbui_avail (string_iter)) - abort (); - last_char_before_tsub = mbui_cur (string_iter); - mbui_advance (string_iter); - } - while (mbui_cur_ptr (string_iter) < tsub_in_string); - if (mb_isalnum (last_char_before_tsub)) - word_boundary_before = false; - } - - mbui_init (string_iter, tsub_in_string); - { - mbui_iterator_t tsub_iter; - - for (mbui_init (tsub_iter, tsub); - mbui_avail (tsub_iter); - mbui_advance (tsub_iter)) - { - if (!mbui_avail (string_iter)) - abort (); - mbui_advance (string_iter); - } - } - word_boundary_after = true; - if (mbui_avail (string_iter)) - { - mbchar_t first_char_after_tsub = mbui_cur (string_iter); - if (mb_isalnum (first_char_after_tsub)) - word_boundary_after = false; - } - - if (word_boundary_before && word_boundary_after) - { - found = true; - break; - } - - mbui_init (string_iter, tsub_in_string); - if (!mbui_avail (string_iter)) - break; - string = tsub_in_string + mb_len (mbui_cur (string_iter)); - } - else - { - bool word_boundary_before; - const char *p; - bool word_boundary_after; - - word_boundary_before = true; - if (string < tsub_in_string) - if (isalnum ((unsigned char) tsub_in_string[-1])) - word_boundary_before = false; - - p = tsub_in_string + strlen (tsub); - word_boundary_after = true; - if (*p != '\0') - if (isalnum ((unsigned char) *p)) - word_boundary_after = false; - - if (word_boundary_before && word_boundary_after) - { - found = true; - break; - } - - if (*tsub_in_string == '\0') - break; - string = tsub_in_string + 1; - } - } + { + if (MB_CUR_MAX > 1) + { + mbui_iterator_t string_iter; + bool word_boundary_before; + bool word_boundary_after; + + mbui_init (string_iter, string); + word_boundary_before = true; + if (mbui_cur_ptr (string_iter) < tsub_in_string) + { + mbchar_t last_char_before_tsub; + do + { + if (!mbui_avail (string_iter)) + abort (); + last_char_before_tsub = mbui_cur (string_iter); + mbui_advance (string_iter); + } + while (mbui_cur_ptr (string_iter) < tsub_in_string); + if (mb_isalnum (last_char_before_tsub)) + word_boundary_before = false; + } + + mbui_init (string_iter, tsub_in_string); + { + mbui_iterator_t tsub_iter; + + for (mbui_init (tsub_iter, tsub); + mbui_avail (tsub_iter); + mbui_advance (tsub_iter)) + { + if (!mbui_avail (string_iter)) + abort (); + mbui_advance (string_iter); + } + } + word_boundary_after = true; + if (mbui_avail (string_iter)) + { + mbchar_t first_char_after_tsub = mbui_cur (string_iter); + if (mb_isalnum (first_char_after_tsub)) + word_boundary_after = false; + } + + if (word_boundary_before && word_boundary_after) + { + found = true; + break; + } + + mbui_init (string_iter, tsub_in_string); + if (!mbui_avail (string_iter)) + break; + string = tsub_in_string + mb_len (mbui_cur (string_iter)); + } + else + { + bool word_boundary_before; + const char *p; + bool word_boundary_after; + + word_boundary_before = true; + if (string < tsub_in_string) + if (isalnum ((unsigned char) tsub_in_string[-1])) + word_boundary_before = false; + + p = tsub_in_string + strlen (tsub); + word_boundary_after = true; + if (*p != '\0') + if (isalnum ((unsigned char) *p)) + word_boundary_after = false; + + if (word_boundary_before && word_boundary_after) + { + found = true; + break; + } + + if (*tsub_in_string == '\0') + break; + string = tsub_in_string + 1; + } + } } free (tsub); return found; @@ -158,16 +158,16 @@ proper_name (const char *name) { /* See whether the translation contains the original name. */ if (mbsstr_trimmed_wordbounded (translation, name)) - return translation; + return translation; else - { - /* Return "TRANSLATION (NAME)". */ - char *result = - XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char); - - sprintf (result, "%s (%s)", translation, name); - return result; - } + { + /* Return "TRANSLATION (NAME)". */ + char *result = + XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char); + + sprintf (result, "%s (%s)", translation, name); + return result; + } } else return name; @@ -196,37 +196,37 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8) { #if HAVE_ICONV name_converted = alloc_name_converted = - xstr_iconv (name_utf8, "UTF-8", locale_code); + xstr_iconv (name_utf8, "UTF-8", locale_code); # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \ || _LIBICONV_VERSION >= 0x0105 { - char *converted_translit; + char *converted_translit; - size_t len = strlen (locale_code); - char *locale_code_translit = XNMALLOC (len + 10 + 1, char); - memcpy (locale_code_translit, locale_code, len); - memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1); + size_t len = strlen (locale_code); + char *locale_code_translit = XNMALLOC (len + 10 + 1, char); + memcpy (locale_code_translit, locale_code, len); + memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1); - converted_translit = - xstr_iconv (name_utf8, "UTF-8", locale_code_translit); + converted_translit = + xstr_iconv (name_utf8, "UTF-8", locale_code_translit); - free (locale_code_translit); + free (locale_code_translit); - if (converted_translit != NULL) - { + if (converted_translit != NULL) + { # if !_LIBICONV_VERSION - /* Don't use the transliteration if it added question marks. - glibc's transliteration falls back to question marks; libiconv's - transliteration does not. - mbschr is equivalent to strchr in this case. */ - if (strchr (converted_translit, '?') != NULL) - free (converted_translit); - else + /* Don't use the transliteration if it added question marks. + glibc's transliteration falls back to question marks; libiconv's + transliteration does not. + mbschr is equivalent to strchr in this case. */ + if (strchr (converted_translit, '?') != NULL) + free (converted_translit); + else # endif - name_converted_translit = alloc_name_converted_translit = - converted_translit; - } + name_converted_translit = alloc_name_converted_translit = + converted_translit; + } } # endif #endif @@ -239,8 +239,8 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8) /* The name in locale encoding. */ name = (name_converted != NULL ? name_converted : - name_converted_translit != NULL ? name_converted_translit : - name_ascii); + name_converted_translit != NULL ? name_converted_translit : + name_ascii); /* See whether we have a translation. Some translators have not understood that they should use the UTF-8 form of the name, if possible. So if the @@ -249,39 +249,39 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8) { /* See whether the translation contains the original name. */ if (mbsstr_trimmed_wordbounded (translation, name_ascii) - || (name_converted != NULL - && mbsstr_trimmed_wordbounded (translation, name_converted)) - || (name_converted_translit != NULL - && mbsstr_trimmed_wordbounded (translation, name_converted_translit))) - { - if (alloc_name_converted != NULL) - free (alloc_name_converted); - if (alloc_name_converted_translit != NULL) - free (alloc_name_converted_translit); - return translation; - } + || (name_converted != NULL + && mbsstr_trimmed_wordbounded (translation, name_converted)) + || (name_converted_translit != NULL + && mbsstr_trimmed_wordbounded (translation, name_converted_translit))) + { + if (alloc_name_converted != NULL) + free (alloc_name_converted); + if (alloc_name_converted_translit != NULL) + free (alloc_name_converted_translit); + return translation; + } else - { - /* Return "TRANSLATION (NAME)". */ - char *result = - XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char); - - sprintf (result, "%s (%s)", translation, name); - - if (alloc_name_converted != NULL) - free (alloc_name_converted); - if (alloc_name_converted_translit != NULL) - free (alloc_name_converted_translit); - return result; - } + { + /* Return "TRANSLATION (NAME)". */ + char *result = + XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char); + + sprintf (result, "%s (%s)", translation, name); + + if (alloc_name_converted != NULL) + free (alloc_name_converted); + if (alloc_name_converted_translit != NULL) + free (alloc_name_converted_translit); + return result; + } } else { if (alloc_name_converted != NULL && alloc_name_converted != name) - free (alloc_name_converted); + free (alloc_name_converted); if (alloc_name_converted_translit != NULL - && alloc_name_converted_translit != name) - free (alloc_name_converted_translit); + && alloc_name_converted_translit != name) + free (alloc_name_converted_translit); return name; } } diff --git a/lib/propername.h b/lib/propername.h index d603b1ae0..81f44046a 100644 --- a/lib/propername.h +++ b/lib/propername.h @@ -96,7 +96,7 @@ extern const char * proper_name (const char *name); escape sequences. NAME_ASCII is a fallback written only with ASCII characters. */ extern const char * proper_name_utf8 (const char *name_ascii, - const char *name_utf8); + const char *name_utf8); #ifdef __cplusplus } diff --git a/lib/pthread.in.h b/lib/pthread.in.h index ae91ed2e2..cbf61ba99 100644 --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -29,8 +29,8 @@ typedef int pthread_attr_t; static int pthread_create (pthread_t *restrict thread, - const pthread_attr_t *restrict attr, - void *(*start_routine)(void*), void *restrict arg) + const pthread_attr_t *restrict attr, + void *(*start_routine)(void*), void *restrict arg) { errno = EAGAIN; return -1; diff --git a/lib/putenv.c b/lib/putenv.c index cc14b9389..d6dcdab0b 100644 --- a/lib/putenv.c +++ b/lib/putenv.c @@ -44,8 +44,8 @@ extern char **environ; /* This lock protects against simultaneous modifications of `environ'. */ # include __libc_lock_define_initialized (static, envlock) -# define LOCK __libc_lock_lock (envlock) -# define UNLOCK __libc_lock_unlock (envlock) +# define LOCK __libc_lock_lock (envlock) +# define UNLOCK __libc_lock_unlock (envlock) #else # define LOCK # define UNLOCK @@ -71,13 +71,13 @@ _unsetenv (const char *name) while (*ep != NULL) if (!strncmp (*ep, name, len) && (*ep)[len] == '=') { - /* Found it. Remove this pointer by moving later ones back. */ - char **dp = ep; + /* 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. */ + do + dp[0] = dp[1]; + while (*dp++); + /* Continue the loop in case NAME appears again. */ } else ++ep; @@ -106,7 +106,7 @@ putenv (char *string) size = 0; for (ep = environ; *ep != NULL; ++ep) if (!strncmp (*ep, string, name_end - string) && - (*ep)[name_end - string] == '=') + (*ep)[name_end - string] == '=') break; else ++size; @@ -116,9 +116,9 @@ putenv (char *string) static char **last_environ = NULL; char **new_environ = (char **) malloc ((size + 2) * sizeof (char *)); if (new_environ == NULL) - return -1; + return -1; (void) memcpy ((void *) new_environ, (void *) environ, - size * sizeof (char *)); + size * sizeof (char *)); new_environ[size] = (char *) string; new_environ[size + 1] = NULL; free (last_environ); diff --git a/lib/quotearg.c b/lib/quotearg.c index 8380e9de6..6ed6afa5c 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -100,7 +100,7 @@ clone_quoting_options (struct quoting_options *o) { int e = errno; struct quoting_options *p = xmemdup (o ? o : &default_quoting_options, - sizeof *o); + sizeof *o); errno = e; return p; } @@ -202,11 +202,11 @@ gettext_quote (char const *msgid, enum quoting_style s) 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) + 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; @@ -219,9 +219,9 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, #define STORE(c) \ do \ { \ - if (len < buffersize) \ - buffer[len] = (c); \ - len++; \ + if (len < buffersize) \ + buffer[len] = (c); \ + len++; \ } \ while (0) @@ -233,7 +233,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, /* Fall through. */ case c_quoting_style: if (!elide_outer_quotes) - STORE ('"'); + STORE ('"'); backslash_escapes = true; quote_string = "\""; quote_string_len = 1; @@ -248,36 +248,36 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, 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 - "'". If the catalog has no translation, - locale_quoting_style quotes `like this', and - clocale_quoting_style quotes "like this". - - For example, an American English Unicode locale should - translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and - should translate "'" to U+201D (RIGHT DOUBLE QUOTATION - MARK). A British English Unicode locale should instead - translate these to U+2018 (LEFT SINGLE QUOTATION MARK) - and U+2019 (RIGHT SINGLE QUOTATION MARK), respectively. - - If you don't know what to put here, please see - - 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); + 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 + "'". If the catalog has no translation, + locale_quoting_style quotes `like this', and + clocale_quoting_style quotes "like this". + + For example, an American English Unicode locale should + translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and + should translate "'" to U+201D (RIGHT DOUBLE QUOTATION + MARK). A British English Unicode locale should instead + translate these to U+2018 (LEFT SINGLE QUOTATION MARK) + and U+2019 (RIGHT SINGLE QUOTATION MARK), respectively. + + If you don't know what to put here, please see + + 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; @@ -287,7 +287,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, /* Fall through. */ case shell_always_quoting_style: if (!elide_outer_quotes) - STORE ('\''); + STORE ('\''); quote_string = "'"; quote_string_len = 1; break; @@ -307,287 +307,287 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, bool is_right_quote = false; if (backslash_escapes - && quote_string_len - && i + quote_string_len <= argsize - && memcmp (arg + i, quote_string, quote_string_len) == 0) - { - if (elide_outer_quotes) - goto force_outer_quoting_style; - is_right_quote = true; - } + && quote_string_len + && i + quote_string_len <= 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; - } - } - } + { + 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; + && 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; + goto force_outer_quoting_style; STORE ('\\'); store_c: @@ -610,9 +610,9 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, /* 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); + quoting_style, + flags & ~QA_ELIDE_OUTER_QUOTES, NULL, + left_quote, right_quote); } /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of @@ -626,14 +626,14 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, ARGSIZE. */ size_t quotearg_buffer (char *buffer, size_t buffersize, - char const *arg, size_t argsize, - struct quoting_options const *o) + 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); + p->style, p->flags, p->quote_these_too, + p->left_quote, p->right_quote); errno = e; return r; } @@ -641,7 +641,7 @@ quotearg_buffer (char *buffer, size_t buffersize, /* Equivalent to quotearg_alloc (ARG, ARGSIZE, NULL, O). */ char * quotearg_alloc (char const *arg, size_t argsize, - struct quoting_options const *o) + struct quoting_options const *o) { return quotearg_alloc_mem (arg, argsize, NULL, o); } @@ -654,20 +654,20 @@ quotearg_alloc (char const *arg, size_t argsize, flag. */ char * quotearg_alloc_mem (char const *arg, size_t argsize, size_t *size, - struct quoting_options const *o) + 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; + 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); + p->quote_these_too, + p->left_quote, p->right_quote); errno = e; if (size) *size = bufsize - 1; @@ -719,7 +719,7 @@ quotearg_free (void) 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) + struct quoting_options const *options) { int e = errno; @@ -732,19 +732,19 @@ quotearg_n_options (int n, char const *arg, size_t argsize, 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. */ + 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 (); + xalloc_die (); slotvec = sv = xrealloc (preallocated ? NULL : sv, n1 * sizeof *sv); if (preallocated) - *sv = slotvec0; + *sv = slotvec0; memset (sv + nslots, 0, (n1 - nslots) * sizeof *sv); nslots = n1; } @@ -755,21 +755,21 @@ quotearg_n_options (int n, char const *arg, size_t argsize, /* 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); + 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); + 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; @@ -810,7 +810,7 @@ quotearg_n_style (int n, enum quoting_style s, char const *arg) char * quotearg_n_style_mem (int n, enum quoting_style s, - char const *arg, size_t argsize) + char const *arg, size_t argsize) { struct quoting_options const o = quoting_options_from_style (s); return quotearg_n_options (n, arg, argsize, &o); @@ -857,16 +857,16 @@ quotearg_colon_mem (char const *arg, size_t argsize) char * quotearg_n_custom (int n, char const *left_quote, - char const *right_quote, char const *arg) + char const *right_quote, char const *arg) { return quotearg_n_custom_mem (n, left_quote, right_quote, arg, - SIZE_MAX); + SIZE_MAX); } char * quotearg_n_custom_mem (int n, char const *left_quote, - char const *right_quote, - char const *arg, size_t argsize) + 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); @@ -875,15 +875,15 @@ quotearg_n_custom_mem (int n, char const *left_quote, char * quotearg_custom (char const *left_quote, char const *right_quote, - char const *arg) + 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) + char const *arg, size_t argsize) { return quotearg_n_custom_mem (0, left_quote, right_quote, arg, - argsize); + argsize); } diff --git a/lib/quotearg.h b/lib/quotearg.h index 63c47f13c..557059981 100644 --- a/lib/quotearg.h +++ b/lib/quotearg.h @@ -276,8 +276,8 @@ int set_quoting_flags (struct quoting_options *o, int i); 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); + 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. @@ -291,14 +291,14 @@ void set_custom_quoting (struct quoting_options *o, 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); + 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); + 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 @@ -307,7 +307,7 @@ char *quotearg_alloc (char const *arg, size_t argsize, 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); + 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. @@ -338,14 +338,14 @@ char *quotearg_n_style (int n, enum quoting_style s, char const *arg); 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); + 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); + 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. */ @@ -365,23 +365,23 @@ char *quotearg_colon_mem (char const *arg, size_t argsize); 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); + 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); + 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); + char const *arg); /* Equivalent to quotearg_n_custom_mem (0, LEFT_QUOTE, RIGHT_QUOTE, ARG, - ARGSIZE). */ + ARGSIZE). */ char *quotearg_custom_mem (char const *left_quote, - char const *right_quote, - char const *arg, size_t argsize); + char const *right_quote, + char const *arg, size_t argsize); /* Free any dynamically allocated memory. */ void quotearg_free (void); diff --git a/lib/random_r.c b/lib/random_r.c index 4d486005b..d9585044b 100644 --- a/lib/random_r.c +++ b/lib/random_r.c @@ -45,7 +45,7 @@ /* * This is derived from the Berkeley source: - * @(#)random.c 5.5 (Berkeley) 7/6/88 + * @(#)random.c 5.5 (Berkeley) 7/6/88 * It was reworked for the GNU C Library by Roland McGrath. * Rewritten to be reentrant by Ulrich Drepper, 1995 */ @@ -101,40 +101,40 @@ separation between the two lower order coefficients of the trinomial. */ /* Linear congruential. */ -#define TYPE_0 0 -#define BREAK_0 8 -#define DEG_0 0 -#define SEP_0 0 +#define TYPE_0 0 +#define BREAK_0 8 +#define DEG_0 0 +#define SEP_0 0 /* x**7 + x**3 + 1. */ -#define TYPE_1 1 -#define BREAK_1 32 -#define DEG_1 7 -#define SEP_1 3 +#define TYPE_1 1 +#define BREAK_1 32 +#define DEG_1 7 +#define SEP_1 3 /* x**15 + x + 1. */ -#define TYPE_2 2 -#define BREAK_2 64 -#define DEG_2 15 -#define SEP_2 1 +#define TYPE_2 2 +#define BREAK_2 64 +#define DEG_2 15 +#define SEP_2 1 /* x**31 + x**3 + 1. */ -#define TYPE_3 3 -#define BREAK_3 128 -#define DEG_3 31 -#define SEP_3 3 +#define TYPE_3 3 +#define BREAK_3 128 +#define DEG_3 31 +#define SEP_3 3 /* x**63 + x + 1. */ -#define TYPE_4 4 -#define BREAK_4 256 -#define DEG_4 63 -#define SEP_4 1 +#define TYPE_4 4 +#define BREAK_4 256 +#define DEG_4 63 +#define SEP_4 1 /* Array versions of the above information to make code run faster. Relies on fact that TYPE_i == i. */ -#define MAX_TYPES 5 /* Max number of types above. */ +#define MAX_TYPES 5 /* Max number of types above. */ struct random_poly_info { @@ -197,13 +197,13 @@ __srandom_r (unsigned int seed, struct random_data *buf) for (i = 1; i < kc; ++i) { /* This does: - state[i] = (16807 * state[i - 1]) % 2147483647; - but avoids overflowing 31 bits. */ + state[i] = (16807 * state[i - 1]) % 2147483647; + but avoids overflowing 31 bits. */ long int hi = word / 127773; long int lo = word % 127773; word = 16807 * lo - 2836 * hi; if (word < 0) - word += 2147483647; + word += 2147483647; *++dst = word; } @@ -238,7 +238,7 @@ weak_alias (__srandom_r, srandom_r) Returns a pointer to the old state. */ int __initstate_r (unsigned int seed, char *arg_state, size_t n, - struct random_data *buf) + struct random_data *buf) { int32_t *old_state; int32_t *state; @@ -254,9 +254,9 @@ __initstate_r (unsigned int seed, char *arg_state, size_t n, { int old_type = buf->rand_type; if (old_type == TYPE_0) - old_state[-1] = TYPE_0; + old_state[-1] = TYPE_0; else - old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type; + old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type; } if (n >= BREAK_3) @@ -264,10 +264,10 @@ __initstate_r (unsigned int seed, char *arg_state, size_t n, else if (n < BREAK_1) { if (n < BREAK_0) - { - __set_errno (EINVAL); - goto fail; - } + { + __set_errno (EINVAL); + goto fail; + } type = TYPE_0; } else @@ -279,7 +279,7 @@ __initstate_r (unsigned int seed, char *arg_state, size_t n, buf->rand_type = type; buf->rand_sep = separation; buf->rand_deg = degree; - state = &((int32_t *) arg_state)[1]; /* First location. */ + state = &((int32_t *) arg_state)[1]; /* First location. */ /* Must set END_PTR before srandom. */ buf->end_ptr = &state[degree]; @@ -395,16 +395,16 @@ __random_r (struct random_data *buf, int32_t *result) *result = (val >> 1) & 0x7fffffff; ++fptr; if (fptr >= end_ptr) - { - fptr = state; - ++rptr; - } + { + fptr = state; + ++rptr; + } else - { - ++rptr; - if (rptr >= end_ptr) - rptr = state; - } + { + ++rptr; + if (rptr >= end_ptr) + rptr = state; + } buf->fptr = fptr; buf->rptr = rptr; } diff --git a/lib/read-file.c b/lib/read-file.c index 1045b494c..8092d2e8a 100644 --- a/lib/read-file.c +++ b/lib/read-file.c @@ -45,36 +45,36 @@ fread_file (FILE * stream, size_t * length) size_t requested; if (size + BUFSIZ + 1 > alloc) - { - char *new_buf; + { + char *new_buf; - alloc += alloc / 2; - if (alloc < size + BUFSIZ + 1) - alloc = size + BUFSIZ + 1; + alloc += alloc / 2; + if (alloc < size + BUFSIZ + 1) + alloc = size + BUFSIZ + 1; - new_buf = realloc (buf, alloc); - if (!new_buf) - { - save_errno = errno; - break; - } + new_buf = realloc (buf, alloc); + if (!new_buf) + { + save_errno = errno; + break; + } - buf = new_buf; - } + buf = new_buf; + } requested = alloc - size - 1; count = fread (buf + size, 1, requested, stream); size += count; if (count != requested) - { - save_errno = errno; - if (ferror (stream)) - break; - buf[size] = '\0'; - *length = size; - return buf; - } + { + save_errno = errno; + if (ferror (stream)) + break; + buf[size] = '\0'; + *length = size; + return buf; + } } free (buf); @@ -99,10 +99,10 @@ internal_read_file (const char *filename, size_t * length, const char *mode) if (fclose (stream) != 0) { if (out) - { - save_errno = errno; - free (out); - } + { + save_errno = errno; + free (out); + } errno = save_errno; return NULL; } diff --git a/lib/readline.c b/lib/readline.c index 4be5f3457..3b497638e 100644 --- a/lib/readline.c +++ b/lib/readline.c @@ -48,7 +48,7 @@ readline (const char *prompt) return NULL; while (*out && (out[strlen (out) - 1] == '\r' - || out[strlen (out) - 1] == '\n')) + || out[strlen (out) - 1] == '\n')) out[strlen (out) - 1] = '\0'; return out; diff --git a/lib/readtokens.c b/lib/readtokens.c index 01750989c..e8712f20f 100644 --- a/lib/readtokens.c +++ b/lib/readtokens.c @@ -60,9 +60,9 @@ init_tokenbuffer (token_buffer *tokenbuffer) size_t readtoken (FILE *stream, - const char *delim, - size_t n_delim, - token_buffer *tokenbuffer) + const char *delim, + size_t n_delim, + token_buffer *tokenbuffer) { char *p; int c; @@ -79,13 +79,13 @@ readtoken (FILE *stream, { same_delimiters = true; for (i = 0; i < n_delim; i++) - { - if (delim[i] != saved_delim[i]) - { - same_delimiters = false; - break; - } - } + { + if (delim[i] != saved_delim[i]) + { + same_delimiters = false; + break; + } + } } if (!same_delimiters) @@ -94,10 +94,10 @@ readtoken (FILE *stream, saved_delim = delim; memset (isdelim, 0, sizeof isdelim); for (j = 0; j < n_delim; j++) - { - unsigned char ch = delim[j]; - isdelim[ch] = 1; - } + { + unsigned char ch = delim[j]; + isdelim[ch] = 1; + } } /* FIXME: don't fool with this caching. Use strchr instead. */ @@ -113,21 +113,21 @@ readtoken (FILE *stream, for (;;) { if (c < 0 && i == 0) - return -1; + return -1; if (i == n) - p = x2nrealloc (p, &n, sizeof *p); + p = x2nrealloc (p, &n, sizeof *p); if (c < 0) - { - p[i] = 0; - break; - } + { + p[i] = 0; + break; + } if (isdelim[c]) - { - p[i] = 0; - break; - } + { + p[i] = 0; + break; + } p[i++] = c; c = getc (stream); } @@ -146,11 +146,11 @@ readtoken (FILE *stream, size_t readtokens (FILE *stream, - size_t projected_n_tokens, - const char *delim, - size_t n_delim, - char ***tokens_out, - size_t **token_lengths) + size_t projected_n_tokens, + const char *delim, + size_t n_delim, + char ***tokens_out, + size_t **token_lengths) { token_buffer tb, *token = &tb; char **tokens; @@ -161,7 +161,7 @@ readtokens (FILE *stream, if (projected_n_tokens == 0) projected_n_tokens = 64; else - projected_n_tokens++; /* add one for trailing NULL pointer */ + projected_n_tokens++; /* add one for trailing NULL pointer */ sz = projected_n_tokens; tokens = xnmalloc (sz, sizeof *tokens); @@ -174,18 +174,18 @@ readtokens (FILE *stream, char *tmp; size_t token_length = readtoken (stream, delim, n_delim, token); if (n_tokens >= sz) - { - tokens = x2nrealloc (tokens, &sz, sizeof *tokens); - lengths = xnrealloc (lengths, sz, sizeof *lengths); - } + { + tokens = x2nrealloc (tokens, &sz, sizeof *tokens); + lengths = xnrealloc (lengths, sz, sizeof *lengths); + } if (token_length == (size_t) -1) - { - /* don't increment n_tokens for NULL entry */ - tokens[n_tokens] = NULL; - lengths[n_tokens] = 0; - break; - } + { + /* don't increment n_tokens for NULL entry */ + tokens[n_tokens] = NULL; + lengths[n_tokens] = 0; + break; + } tmp = xnmalloc (token_length + 1, sizeof *tmp); lengths[n_tokens] = token_length; tokens[n_tokens] = memcpy (tmp, token->buffer, token_length + 1); diff --git a/lib/readtokens.h b/lib/readtokens.h index 1c3cafeb1..14aef5fba 100644 --- a/lib/readtokens.h +++ b/lib/readtokens.h @@ -33,10 +33,10 @@ void init_tokenbuffer (token_buffer *tokenbuffer); size_t readtoken (FILE *stream, const char *delim, size_t n_delim, - token_buffer *tokenbuffer); + token_buffer *tokenbuffer); size_t readtokens (FILE *stream, size_t projected_n_tokens, - const char *delim, size_t n_delim, - char ***tokens_out, size_t **token_lengths); + const char *delim, size_t n_delim, + char ***tokens_out, size_t **token_lengths); #endif /* not READTOKENS_H */ diff --git a/lib/readtokens0.c b/lib/readtokens0.c index ccd2860c0..34246a7ed 100644 --- a/lib/readtokens0.c +++ b/lib/readtokens0.c @@ -70,23 +70,23 @@ readtokens0 (FILE *in, struct Tokens *t) { int c = fgetc (in); if (c == EOF) - { - size_t len = obstack_object_size (&t->o_data); - /* If the current object has nonzero length, then there - was no NUL byte at EOF -- or maybe there was an error, - in which case, we need to append a NUL byte to our buffer. */ - if (len) - { - obstack_1grow (&t->o_data, '\0'); - save_token (t); - } - - break; - } + { + size_t len = obstack_object_size (&t->o_data); + /* If the current object has nonzero length, then there + was no NUL byte at EOF -- or maybe there was an error, + in which case, we need to append a NUL byte to our buffer. */ + if (len) + { + obstack_1grow (&t->o_data, '\0'); + save_token (t); + } + + break; + } obstack_1grow (&t->o_data, c); if (c == '\0') - save_token (t); + save_token (t); } /* Add a NULL pointer at the end, in case the caller (like du) diff --git a/lib/readutmp.c b/lib/readutmp.c index aeec20572..64cb9f558 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -71,7 +71,7 @@ desirable_utmp_entry (STRUCT_UTMP const *u, int options) if ((options & READ_UTMP_CHECK_PIDS) && user_proc && (UT_PID (u) <= 0 - || (kill (UT_PID (u), 0) < 0 && errno == ESRCH))) + || (kill (UT_PID (u), 0) < 0 && errno == ESRCH))) return false; return true; } @@ -87,7 +87,7 @@ desirable_utmp_entry (STRUCT_UTMP const *u, int options) int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf, - int options) + int options) { size_t n_read = 0; size_t n_alloc = 0; @@ -105,10 +105,10 @@ read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf, while ((u = GET_UTMP_ENT ()) != NULL) if (desirable_utmp_entry (u, options)) { - if (n_read == n_alloc) - utmp = x2nrealloc (utmp, &n_alloc, sizeof *utmp); + if (n_read == n_alloc) + utmp = x2nrealloc (utmp, &n_alloc, sizeof *utmp); - utmp[n_read++] = *u; + utmp[n_read++] = *u; } END_UTMP_ENT (); @@ -123,7 +123,7 @@ read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf, int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf, - int options) + int options) { size_t n_read = 0; size_t n_alloc = 0; @@ -137,9 +137,9 @@ read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf, for (;;) { if (n_read == n_alloc) - utmp = x2nrealloc (utmp, &n_alloc, sizeof *utmp); + utmp = x2nrealloc (utmp, &n_alloc, sizeof *utmp); if (fread (&utmp[n_read], sizeof utmp[n_read], 1, f) == 0) - break; + break; n_read += desirable_utmp_entry (&utmp[n_read], options); } diff --git a/lib/readutmp.h b/lib/readutmp.h index 1e43a31e8..a0aeec25f 100644 --- a/lib/readutmp.h +++ b/lib/readutmp.h @@ -197,9 +197,9 @@ enum { UT_USER_SIZE = sizeof UT_USER ((STRUCT_UTMP *) 0) }; # define UT_TYPE_USER_PROCESS(U) 0 # endif -# define IS_USER_PROCESS(U) \ - (UT_USER (U)[0] \ - && (UT_TYPE_USER_PROCESS (U) \ +# define IS_USER_PROCESS(U) \ + (UT_USER (U)[0] \ + && (UT_TYPE_USER_PROCESS (U) \ || (UT_TYPE_NOT_DEFINED && UT_TIME_MEMBER (U) != 0))) /* Options for read_utmp. */ @@ -211,6 +211,6 @@ enum char *extract_trimmed_name (const STRUCT_UTMP *ut); int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf, - int options); + int options); #endif /* __READUTMP_H__ */ diff --git a/lib/realloc.c b/lib/realloc.c index b61c2ca82..dc1adc9f7 100644 --- a/lib/realloc.c +++ b/lib/realloc.c @@ -71,7 +71,7 @@ rpl_realloc (void *p, size_t n) { #if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE if (n == 0) - n = 1; + n = 1; #endif result = malloc (n); } diff --git a/lib/recvfrom.c b/lib/recvfrom.c index 52fa3c8d4..a9c0affea 100644 --- a/lib/recvfrom.c +++ b/lib/recvfrom.c @@ -30,7 +30,7 @@ int rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from, - int *fromlen) + int *fromlen) { int frombufsize = *fromlen; SOCKET sock = FD_TO_SOCKET (fd); diff --git a/lib/relocatable.c b/lib/relocatable.c index b49442003..995d3acf8 100644 --- a/lib/relocatable.c +++ b/lib/relocatable.c @@ -22,7 +22,7 @@ This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 +# define _GNU_SOURCE 1 #endif #include @@ -102,11 +102,11 @@ static size_t curr_prefix_len; instead of "/"). */ static void set_this_relocation_prefix (const char *orig_prefix_arg, - const char *curr_prefix_arg) + const char *curr_prefix_arg) { if (orig_prefix_arg != NULL && curr_prefix_arg != NULL /* Optimization: if orig_prefix and curr_prefix are equal, the - relocation is a nop. */ + relocation is a nop. */ && strcmp (orig_prefix_arg, curr_prefix_arg) != 0) { /* Duplicate the argument strings. */ @@ -118,14 +118,14 @@ set_this_relocation_prefix (const char *orig_prefix_arg, #ifdef NO_XMALLOC if (memory != NULL) #endif - { - memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); - orig_prefix = memory; - memory += orig_prefix_len + 1; - memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); - curr_prefix = memory; - return; - } + { + memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); + orig_prefix = memory; + memory += orig_prefix_len + 1; + memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); + curr_prefix = memory; + return; + } } orig_prefix = NULL; curr_prefix = NULL; @@ -168,8 +168,8 @@ static #endif char * compute_curr_prefix (const char *orig_installprefix, - const char *orig_installdir, - const char *curr_pathname) + const char *orig_installdir, + const char *curr_pathname) { char *curr_installdir; const char *rel_installdir; @@ -194,9 +194,9 @@ compute_curr_prefix (const char *orig_installprefix, while (p > p_base) { - p--; - if (ISSLASH (*p)) - break; + p--; + if (ISSLASH (*p)) + break; } q = (char *) xmalloc (p - curr_pathname + 1); @@ -219,46 +219,46 @@ compute_curr_prefix (const char *orig_installprefix, while (rp > rel_installdir && cp > cp_base) { - bool same = false; - const char *rpi = rp; - const char *cpi = cp; - - while (rpi > rel_installdir && cpi > cp_base) - { - rpi--; - cpi--; - if (ISSLASH (*rpi) || ISSLASH (*cpi)) - { - if (ISSLASH (*rpi) && ISSLASH (*cpi)) - same = true; - break; - } - /* Do case-insensitive comparison if the file system is always or - often case-insensitive. It's better to accept the comparison - if the difference is only in case, rather than to fail. */ + bool same = false; + const char *rpi = rp; + const char *cpi = cp; + + while (rpi > rel_installdir && cpi > cp_base) + { + rpi--; + cpi--; + if (ISSLASH (*rpi) || ISSLASH (*cpi)) + { + if (ISSLASH (*rpi) && ISSLASH (*cpi)) + same = true; + break; + } + /* Do case-insensitive comparison if the file system is always or + often case-insensitive. It's better to accept the comparison + if the difference is only in case, rather than to fail. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ - /* Win32, Cygwin, OS/2, DOS - case insignificant file system */ - if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) - != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) - break; + /* Win32, Cygwin, OS/2, DOS - case insignificant file system */ + if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) + != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) + break; #else - if (*rpi != *cpi) - break; + if (*rpi != *cpi) + break; #endif - } - if (!same) - break; - /* The last pathname component was the same. opi and cpi now point - to the slash before it. */ - rp = rpi; - cp = cpi; + } + if (!same) + break; + /* The last pathname component was the same. opi and cpi now point + to the slash before it. */ + rp = rpi; + cp = cpi; } if (rp > rel_installdir) { - /* Unexpected: The curr_installdir does not end with rel_installdir. */ - free (curr_installdir); - return NULL; + /* Unexpected: The curr_installdir does not end with rel_installdir. */ + free (curr_installdir); + return NULL; } { @@ -268,10 +268,10 @@ compute_curr_prefix (const char *orig_installprefix, curr_prefix = (char *) xmalloc (curr_prefix_len + 1); #ifdef NO_XMALLOC if (curr_prefix == NULL) - { - free (curr_installdir); - return NULL; - } + { + free (curr_installdir); + return NULL; + } #endif memcpy (curr_prefix, curr_installdir, curr_prefix_len); curr_prefix[curr_prefix_len] = '\0'; @@ -305,30 +305,30 @@ DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved) static char location[MAX_PATH]; if (!GetModuleFileName (module_handle, location, sizeof (location))) - /* Shouldn't happen. */ - return FALSE; + /* Shouldn't happen. */ + return FALSE; if (!IS_PATH_WITH_DIR (location)) - /* Shouldn't happen. */ - return FALSE; + /* Shouldn't happen. */ + return FALSE; { #if defined __CYGWIN__ - /* On Cygwin, we need to convert paths coming from Win32 system calls - to the Unix-like slashified notation. */ - static char location_as_posix_path[2 * MAX_PATH]; - /* There's no error return defined for cygwin_conv_to_posix_path. - See cygwin-api/func-cygwin-conv-to-posix-path.html. - Does it overflow the buffer of expected size MAX_PATH or does it - truncate the path? I don't know. Let's catch both. */ - cygwin_conv_to_posix_path (location, location_as_posix_path); - location_as_posix_path[MAX_PATH - 1] = '\0'; - if (strlen (location_as_posix_path) >= MAX_PATH - 1) - /* A sign of buffer overflow or path truncation. */ - return FALSE; - shared_library_fullname = strdup (location_as_posix_path); + /* On Cygwin, we need to convert paths coming from Win32 system calls + to the Unix-like slashified notation. */ + static char location_as_posix_path[2 * MAX_PATH]; + /* There's no error return defined for cygwin_conv_to_posix_path. + See cygwin-api/func-cygwin-conv-to-posix-path.html. + Does it overflow the buffer of expected size MAX_PATH or does it + truncate the path? I don't know. Let's catch both. */ + cygwin_conv_to_posix_path (location, location_as_posix_path); + location_as_posix_path[MAX_PATH - 1] = '\0'; + if (strlen (location_as_posix_path) >= MAX_PATH - 1) + /* A sign of buffer overflow or path truncation. */ + return FALSE; + shared_library_fullname = strdup (location_as_posix_path); #else - shared_library_fullname = strdup (location); + shared_library_fullname = strdup (location); #endif } } @@ -351,37 +351,37 @@ find_shared_library_fullname () { unsigned long address = (unsigned long) &find_shared_library_fullname; for (;;) - { - unsigned long start, end; - int c; - - if (fscanf (fp, "%lx-%lx", &start, &end) != 2) - break; - if (address >= start && address <= end - 1) - { - /* Found it. Now see if this line contains a filename. */ - while (c = getc (fp), c != EOF && c != '\n' && c != '/') - continue; - if (c == '/') - { - size_t size; - int len; - - ungetc (c, fp); - shared_library_fullname = NULL; size = 0; - len = getline (&shared_library_fullname, &size, fp); - if (len >= 0) - { - /* Success: filled shared_library_fullname. */ - if (len > 0 && shared_library_fullname[len - 1] == '\n') - shared_library_fullname[len - 1] = '\0'; - } - } - break; - } - while (c = getc (fp), c != EOF && c != '\n') - continue; - } + { + unsigned long start, end; + int c; + + if (fscanf (fp, "%lx-%lx", &start, &end) != 2) + break; + if (address >= start && address <= end - 1) + { + /* Found it. Now see if this line contains a filename. */ + while (c = getc (fp), c != EOF && c != '\n' && c != '/') + continue; + if (c == '/') + { + size_t size; + int len; + + ungetc (c, fp); + shared_library_fullname = NULL; size = 0; + len = getline (&shared_library_fullname, &size, fp); + if (len >= 0) + { + /* Success: filled shared_library_fullname. */ + if (len > 0 && shared_library_fullname[len - 1] == '\n') + shared_library_fullname[len - 1] = '\0'; + } + } + break; + } + while (c = getc (fp), c != EOF && c != '\n') + continue; + } fclose (fp); } #endif @@ -422,28 +422,28 @@ relocate (const char *pathname) if (!initialized) { /* At this point, orig_prefix and curr_prefix likely have already been - set through the main program's set_program_name_and_installdir - function. This is sufficient in the case that the library has - initially been installed in the same orig_prefix. But we can do - better, to also cover the cases that 1. it has been installed - in a different prefix before being moved to orig_prefix and (later) - to curr_prefix, 2. unlike the program, it has not moved away from - orig_prefix. */ + set through the main program's set_program_name_and_installdir + function. This is sufficient in the case that the library has + initially been installed in the same orig_prefix. But we can do + better, to also cover the cases that 1. it has been installed + in a different prefix before being moved to orig_prefix and (later) + to curr_prefix, 2. unlike the program, it has not moved away from + orig_prefix. */ const char *orig_installprefix = INSTALLPREFIX; const char *orig_installdir = INSTALLDIR; char *curr_prefix_better; curr_prefix_better = - compute_curr_prefix (orig_installprefix, orig_installdir, - get_shared_library_fullname ()); + compute_curr_prefix (orig_installprefix, orig_installdir, + get_shared_library_fullname ()); set_relocation_prefix (orig_installprefix, - curr_prefix_better != NULL - ? curr_prefix_better - : curr_prefix); + curr_prefix_better != NULL + ? curr_prefix_better + : curr_prefix); if (curr_prefix_better != NULL) - free (curr_prefix_better); + free (curr_prefix_better); initialized = 1; } @@ -457,34 +457,34 @@ relocate (const char *pathname) && strncmp (pathname, orig_prefix, orig_prefix_len) == 0) { if (pathname[orig_prefix_len] == '\0') - { - /* pathname equals orig_prefix. */ - char *result = (char *) xmalloc (strlen (curr_prefix) + 1); + { + /* pathname equals orig_prefix. */ + char *result = (char *) xmalloc (strlen (curr_prefix) + 1); #ifdef NO_XMALLOC - if (result != NULL) + if (result != NULL) #endif - { - strcpy (result, curr_prefix); - return result; - } - } + { + strcpy (result, curr_prefix); + return result; + } + } else if (ISSLASH (pathname[orig_prefix_len])) - { - /* pathname starts with orig_prefix. */ - const char *pathname_tail = &pathname[orig_prefix_len]; - char *result = - (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); + { + /* pathname starts with orig_prefix. */ + const char *pathname_tail = &pathname[orig_prefix_len]; + char *result = + (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); #ifdef NO_XMALLOC - if (result != NULL) + if (result != NULL) #endif - { - memcpy (result, curr_prefix, curr_prefix_len); - strcpy (result + curr_prefix_len, pathname_tail); - return result; - } - } + { + memcpy (result, curr_prefix, curr_prefix_len); + strcpy (result + curr_prefix_len, pathname_tail); + return result; + } + } } /* Nothing to relocate. */ return pathname; diff --git a/lib/relocatable.h b/lib/relocatable.h index 5dfd71083..3acb5343e 100644 --- a/lib/relocatable.h +++ b/lib/relocatable.h @@ -46,7 +46,7 @@ extern "C" { instead of "/"). */ extern RELOCATABLE_DLL_EXPORTED void set_relocation_prefix (const char *orig_prefix, - const char *curr_prefix); + const char *curr_prefix); /* Returns the pathname, relocated according to the current installation directory. @@ -65,8 +65,8 @@ extern const char * relocate (const char *pathname); file, and the current pathname of this file. Returns it, freshly allocated. Returns NULL upon failure. */ extern char * compute_curr_prefix (const char *orig_installprefix, - const char *orig_installdir, - const char *curr_pathname); + const char *orig_installdir, + const char *curr_pathname); #else diff --git a/lib/relocwrapper.c b/lib/relocwrapper.c index 42c64cfb9..18f93835a 100644 --- a/lib/relocwrapper.c +++ b/lib/relocwrapper.c @@ -66,34 +66,34 @@ add_dotbin (const char *filename) if (result != NULL) { if (sizeof (EXEEXT) > sizeof ("")) - { - /* EXEEXT handling. */ - const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); - static const char exeext[] = EXEEXT; - if (filename_len > exeext_len) - { - /* Compare using an inlined copy of c_strncasecmp(), because - the filenames may have undergone a case conversion since - they were packaged. In other words, EXEEXT may be ".exe" - on one system and ".EXE" on another. */ - const char *s1 = filename + filename_len - exeext_len; - const char *s2 = exeext; - for (; *s1 != '\0'; s1++, s2++) - { - unsigned char c1 = *s1; - unsigned char c2 = *s2; - if (c_tolower (c1) != c_tolower (c2)) - goto simple_append; - } - /* Insert ".bin" before EXEEXT or its equivalent. */ - memcpy (result, filename, filename_len - exeext_len); - memcpy (result + filename_len - exeext_len, ".bin", 4); - memcpy (result + filename_len - exeext_len + 4, - filename + filename_len - exeext_len, - exeext_len + 1); - return result; - } - } + { + /* EXEEXT handling. */ + const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); + static const char exeext[] = EXEEXT; + if (filename_len > exeext_len) + { + /* Compare using an inlined copy of c_strncasecmp(), because + the filenames may have undergone a case conversion since + they were packaged. In other words, EXEEXT may be ".exe" + on one system and ".EXE" on another. */ + const char *s1 = filename + filename_len - exeext_len; + const char *s2 = exeext; + for (; *s1 != '\0'; s1++, s2++) + { + unsigned char c1 = *s1; + unsigned char c2 = *s2; + if (c_tolower (c1) != c_tolower (c2)) + goto simple_append; + } + /* Insert ".bin" before EXEEXT or its equivalent. */ + memcpy (result, filename, filename_len - exeext_len); + memcpy (result + filename_len - exeext_len, ".bin", 4); + memcpy (result + filename_len - exeext_len + 4, + filename + filename_len - exeext_len, + exeext_len + 1); + return result; + } + } simple_append: /* Simply append ".bin". */ memcpy (result, filename, filename_len); @@ -187,6 +187,6 @@ main (int argc, char *argv[]) activate_libdirs (); execv (argv[0], argv); fprintf (stderr, "%s: could not execute %s: %s\n", - program_name, argv[0], strerror (errno)); + program_name, argv[0], strerror (errno)); exit (127); } diff --git a/lib/rijndael-alg-fst.c b/lib/rijndael-alg-fst.c index dcd812c44..c00528b36 100644 --- a/lib/rijndael-alg-fst.c +++ b/lib/rijndael-alg-fst.c @@ -737,23 +737,23 @@ static const uint32_t rcon[] = { }; #define GETU32(pt) (((uint32_t)((pt)[0] & 0xFF) << 24) ^ \ - ((uint32_t)((pt)[1] & 0xFF) << 16) ^ \ - ((uint32_t)((pt)[2] & 0xFF) << 8) ^ \ - ((uint32_t)((pt)[3] & 0xFF))) -#define PUTU32(ct, st) { \ - (ct)[0] = (char)((st) >> 24); \ - (ct)[1] = (char)((st) >> 16); \ - (ct)[2] = (char)((st) >> 8); \ + ((uint32_t)((pt)[1] & 0xFF) << 16) ^ \ + ((uint32_t)((pt)[2] & 0xFF) << 8) ^ \ + ((uint32_t)((pt)[3] & 0xFF))) +#define PUTU32(ct, st) { \ + (ct)[0] = (char)((st) >> 24); \ + (ct)[1] = (char)((st) >> 16); \ + (ct)[2] = (char)((st) >> 8); \ (ct)[3] = (char)(st); } /** * Expand the cipher key into the encryption key schedule. * - * @return the number of rounds for the given cipher key size. + * @return the number of rounds for the given cipher key size. */ int rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ], - const char cipherKey[], size_t keyBits) + const char cipherKey[], size_t keyBits) { size_t i = 0; uint32_t temp; @@ -765,78 +765,78 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ], if (keyBits == 128) { for (;;) - { - temp = rk[3]; - rk[4] = rk[0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i]; - rk[5] = rk[1] ^ rk[4]; - rk[6] = rk[2] ^ rk[5]; - rk[7] = rk[3] ^ rk[6]; - if (++i == 10) - { - return 10; - } - rk += 4; - } + { + temp = rk[3]; + rk[4] = rk[0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i]; + rk[5] = rk[1] ^ rk[4]; + rk[6] = rk[2] ^ rk[5]; + rk[7] = rk[3] ^ rk[6]; + if (++i == 10) + { + return 10; + } + rk += 4; + } } rk[4] = GETU32 (cipherKey + 16); rk[5] = GETU32 (cipherKey + 20); if (keyBits == 192) { for (;;) - { - temp = rk[5]; - rk[6] = rk[0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i]; - rk[7] = rk[1] ^ rk[6]; - rk[8] = rk[2] ^ rk[7]; - rk[9] = rk[3] ^ rk[8]; - if (++i == 8) - { - return 12; - } - rk[10] = rk[4] ^ rk[9]; - rk[11] = rk[5] ^ rk[10]; - rk += 6; - } + { + temp = rk[5]; + rk[6] = rk[0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i]; + rk[7] = rk[1] ^ rk[6]; + rk[8] = rk[2] ^ rk[7]; + rk[9] = rk[3] ^ rk[8]; + if (++i == 8) + { + return 12; + } + rk[10] = rk[4] ^ rk[9]; + rk[11] = rk[5] ^ rk[10]; + rk += 6; + } } rk[6] = GETU32 (cipherKey + 24); rk[7] = GETU32 (cipherKey + 28); if (keyBits == 256) { for (;;) - { - temp = rk[7]; - rk[8] = rk[0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i]; - rk[9] = rk[1] ^ rk[8]; - rk[10] = rk[2] ^ rk[9]; - rk[11] = rk[3] ^ rk[10]; - if (++i == 7) - { - return 14; - } - temp = rk[11]; - rk[12] = rk[4] ^ - (Te4[(temp >> 24)] & 0xff000000) ^ - (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(temp) & 0xff] & 0x000000ff); - rk[13] = rk[5] ^ rk[12]; - rk[14] = rk[6] ^ rk[13]; - rk[15] = rk[7] ^ rk[14]; + { + temp = rk[7]; + rk[8] = rk[0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i]; + rk[9] = rk[1] ^ rk[8]; + rk[10] = rk[2] ^ rk[9]; + rk[11] = rk[3] ^ rk[10]; + if (++i == 7) + { + return 14; + } + temp = rk[11]; + rk[12] = rk[4] ^ + (Te4[(temp >> 24)] & 0xff000000) ^ + (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(temp) & 0xff] & 0x000000ff); + rk[13] = rk[5] ^ rk[12]; + rk[14] = rk[6] ^ rk[13]; + rk[15] = rk[7] ^ rk[14]; - rk += 8; - } + rk += 8; + } } return 0; } @@ -844,11 +844,11 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ], /** * Expand the cipher key into the decryption key schedule. * - * @return the number of rounds for the given cipher key size. + * @return the number of rounds for the given cipher key size. */ int rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ], - const char cipherKey[], size_t keyBits) + const char cipherKey[], size_t keyBits) { size_t Nr, i, j; uint32_t temp; @@ -877,32 +877,32 @@ rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ], { rk += 4; rk[0] = - Td0[Te4[(rk[0] >> 24)] & 0xff] ^ - Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[0]) & 0xff] & 0xff]; + Td0[Te4[(rk[0] >> 24)] & 0xff] ^ + Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[0]) & 0xff] & 0xff]; rk[1] = - Td0[Te4[(rk[1] >> 24)] & 0xff] ^ - Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[1]) & 0xff] & 0xff]; + Td0[Te4[(rk[1] >> 24)] & 0xff] ^ + Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[1]) & 0xff] & 0xff]; rk[2] = - Td0[Te4[(rk[2] >> 24)] & 0xff] ^ - Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[2]) & 0xff] & 0xff]; + Td0[Te4[(rk[2] >> 24)] & 0xff] ^ + Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[2]) & 0xff] & 0xff]; rk[3] = - Td0[Te4[(rk[3] >> 24)] & 0xff] ^ - Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[3]) & 0xff] & 0xff]; + Td0[Te4[(rk[3] >> 24)] & 0xff] ^ + Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[3]) & 0xff] & 0xff]; } return Nr; } void rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr, - const char pt[16], char ct[16]) + const char pt[16], char ct[16]) { uint32_t s0, s1, s2, s3, t0, t1, t2, t3; size_t r; @@ -922,44 +922,44 @@ rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr, for (;;) { t0 = - Te0[(s0 >> 24)] ^ - Te1[(s1 >> 16) & 0xff] ^ - Te2[(s2 >> 8) & 0xff] ^ Te3[(s3) & 0xff] ^ rk[4]; + Te0[(s0 >> 24)] ^ + Te1[(s1 >> 16) & 0xff] ^ + Te2[(s2 >> 8) & 0xff] ^ Te3[(s3) & 0xff] ^ rk[4]; t1 = - Te0[(s1 >> 24)] ^ - Te1[(s2 >> 16) & 0xff] ^ - Te2[(s3 >> 8) & 0xff] ^ Te3[(s0) & 0xff] ^ rk[5]; + Te0[(s1 >> 24)] ^ + Te1[(s2 >> 16) & 0xff] ^ + Te2[(s3 >> 8) & 0xff] ^ Te3[(s0) & 0xff] ^ rk[5]; t2 = - Te0[(s2 >> 24)] ^ - Te1[(s3 >> 16) & 0xff] ^ - Te2[(s0 >> 8) & 0xff] ^ Te3[(s1) & 0xff] ^ rk[6]; + Te0[(s2 >> 24)] ^ + Te1[(s3 >> 16) & 0xff] ^ + Te2[(s0 >> 8) & 0xff] ^ Te3[(s1) & 0xff] ^ rk[6]; t3 = - Te0[(s3 >> 24)] ^ - Te1[(s0 >> 16) & 0xff] ^ - Te2[(s1 >> 8) & 0xff] ^ Te3[(s2) & 0xff] ^ rk[7]; + Te0[(s3 >> 24)] ^ + Te1[(s0 >> 16) & 0xff] ^ + Te2[(s1 >> 8) & 0xff] ^ Te3[(s2) & 0xff] ^ rk[7]; rk += 8; if (--r == 0) - { - break; - } + { + break; + } s0 = - Te0[(t0 >> 24)] ^ - Te1[(t1 >> 16) & 0xff] ^ - Te2[(t2 >> 8) & 0xff] ^ Te3[(t3) & 0xff] ^ rk[0]; + Te0[(t0 >> 24)] ^ + Te1[(t1 >> 16) & 0xff] ^ + Te2[(t2 >> 8) & 0xff] ^ Te3[(t3) & 0xff] ^ rk[0]; s1 = - Te0[(t1 >> 24)] ^ - Te1[(t2 >> 16) & 0xff] ^ - Te2[(t3 >> 8) & 0xff] ^ Te3[(t0) & 0xff] ^ rk[1]; + Te0[(t1 >> 24)] ^ + Te1[(t2 >> 16) & 0xff] ^ + Te2[(t3 >> 8) & 0xff] ^ Te3[(t0) & 0xff] ^ rk[1]; s2 = - Te0[(t2 >> 24)] ^ - Te1[(t3 >> 16) & 0xff] ^ - Te2[(t0 >> 8) & 0xff] ^ Te3[(t1) & 0xff] ^ rk[2]; + Te0[(t2 >> 24)] ^ + Te1[(t3 >> 16) & 0xff] ^ + Te2[(t0 >> 8) & 0xff] ^ Te3[(t1) & 0xff] ^ rk[2]; s3 = - Te0[(t3 >> 24)] ^ - Te1[(t0 >> 16) & 0xff] ^ - Te2[(t1 >> 8) & 0xff] ^ Te3[(t2) & 0xff] ^ rk[3]; + Te0[(t3 >> 24)] ^ + Te1[(t0 >> 16) & 0xff] ^ + Te2[(t1 >> 8) & 0xff] ^ Te3[(t2) & 0xff] ^ rk[3]; } /* * apply last round and @@ -993,7 +993,7 @@ rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr, void rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr, - const char ct[16], char pt[16]) + const char ct[16], char pt[16]) { uint32_t s0, s1, s2, s3, t0, t1, t2, t3; size_t r; @@ -1013,44 +1013,44 @@ rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr, for (;;) { t0 = - Td0[(s0 >> 24)] ^ - Td1[(s3 >> 16) & 0xff] ^ - Td2[(s2 >> 8) & 0xff] ^ Td3[(s1) & 0xff] ^ rk[4]; + Td0[(s0 >> 24)] ^ + Td1[(s3 >> 16) & 0xff] ^ + Td2[(s2 >> 8) & 0xff] ^ Td3[(s1) & 0xff] ^ rk[4]; t1 = - Td0[(s1 >> 24)] ^ - Td1[(s0 >> 16) & 0xff] ^ - Td2[(s3 >> 8) & 0xff] ^ Td3[(s2) & 0xff] ^ rk[5]; + Td0[(s1 >> 24)] ^ + Td1[(s0 >> 16) & 0xff] ^ + Td2[(s3 >> 8) & 0xff] ^ Td3[(s2) & 0xff] ^ rk[5]; t2 = - Td0[(s2 >> 24)] ^ - Td1[(s1 >> 16) & 0xff] ^ - Td2[(s0 >> 8) & 0xff] ^ Td3[(s3) & 0xff] ^ rk[6]; + Td0[(s2 >> 24)] ^ + Td1[(s1 >> 16) & 0xff] ^ + Td2[(s0 >> 8) & 0xff] ^ Td3[(s3) & 0xff] ^ rk[6]; t3 = - Td0[(s3 >> 24)] ^ - Td1[(s2 >> 16) & 0xff] ^ - Td2[(s1 >> 8) & 0xff] ^ Td3[(s0) & 0xff] ^ rk[7]; + Td0[(s3 >> 24)] ^ + Td1[(s2 >> 16) & 0xff] ^ + Td2[(s1 >> 8) & 0xff] ^ Td3[(s0) & 0xff] ^ rk[7]; rk += 8; if (--r == 0) - { - break; - } + { + break; + } s0 = - Td0[(t0 >> 24)] ^ - Td1[(t3 >> 16) & 0xff] ^ - Td2[(t2 >> 8) & 0xff] ^ Td3[(t1) & 0xff] ^ rk[0]; + Td0[(t0 >> 24)] ^ + Td1[(t3 >> 16) & 0xff] ^ + Td2[(t2 >> 8) & 0xff] ^ Td3[(t1) & 0xff] ^ rk[0]; s1 = - Td0[(t1 >> 24)] ^ - Td1[(t0 >> 16) & 0xff] ^ - Td2[(t3 >> 8) & 0xff] ^ Td3[(t2) & 0xff] ^ rk[1]; + Td0[(t1 >> 24)] ^ + Td1[(t0 >> 16) & 0xff] ^ + Td2[(t3 >> 8) & 0xff] ^ Td3[(t2) & 0xff] ^ rk[1]; s2 = - Td0[(t2 >> 24)] ^ - Td1[(t1 >> 16) & 0xff] ^ - Td2[(t0 >> 8) & 0xff] ^ Td3[(t3) & 0xff] ^ rk[2]; + Td0[(t2 >> 24)] ^ + Td1[(t1 >> 16) & 0xff] ^ + Td2[(t0 >> 8) & 0xff] ^ Td3[(t3) & 0xff] ^ rk[2]; s3 = - Td0[(t3 >> 24)] ^ - Td1[(t2 >> 16) & 0xff] ^ - Td2[(t1 >> 8) & 0xff] ^ Td3[(t0) & 0xff] ^ rk[3]; + Td0[(t3 >> 24)] ^ + Td1[(t2 >> 16) & 0xff] ^ + Td2[(t1 >> 8) & 0xff] ^ Td3[(t0) & 0xff] ^ rk[3]; } /* * apply last round and diff --git a/lib/rijndael-alg-fst.h b/lib/rijndael-alg-fst.h index 7d8e4f1a5..e3f25dc83 100644 --- a/lib/rijndael-alg-fst.h +++ b/lib/rijndael-alg-fst.h @@ -56,12 +56,12 @@ #define RIJNDAEL_MAXNR 14 int rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ], - const char cipherKey[], size_t keyBits); + const char cipherKey[], size_t keyBits); int rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ], - const char cipherKey[], size_t keyBits); + const char cipherKey[], size_t keyBits); void rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr, - const char pt[16], char ct[16]); + const char pt[16], char ct[16]); void rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr, - const char ct[16], char pt[16]); + const char ct[16], char pt[16]); #endif /* __RIJNDAEL_ALG_FST_H */ diff --git a/lib/rijndael-api-fst.c b/lib/rijndael-api-fst.c index b55df797b..28aa4758f 100644 --- a/lib/rijndael-api-fst.c +++ b/lib/rijndael-api-fst.c @@ -73,7 +73,7 @@ rijndael_rc rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction, - size_t keyLen, const char *keyMaterial) + size_t keyLen, const char *keyMaterial) { size_t i; char *keyMat; @@ -116,23 +116,23 @@ rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction, t = *keyMat++; if ((t >= '0') && (t <= '9')) - v = (t - '0') << 4; + v = (t - '0') << 4; else if ((t >= 'a') && (t <= 'f')) - v = (t - 'a' + 10) << 4; + v = (t - 'a' + 10) << 4; else if ((t >= 'A') && (t <= 'F')) - v = (t - 'A' + 10) << 4; + v = (t - 'A' + 10) << 4; else - return RIJNDAEL_BAD_KEY_MAT; + return RIJNDAEL_BAD_KEY_MAT; t = *keyMat++; if ((t >= '0') && (t <= '9')) - v ^= (t - '0'); + v ^= (t - '0'); else if ((t >= 'a') && (t <= 'f')) - v ^= (t - 'a' + 10); + v ^= (t - 'a' + 10); else if ((t >= 'A') && (t <= 'F')) - v ^= (t - 'A' + 10); + v ^= (t - 'A' + 10); else - return RIJNDAEL_BAD_KEY_MAT; + return RIJNDAEL_BAD_KEY_MAT; cipherKey[i] = v; } @@ -150,7 +150,7 @@ rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction, rijndael_rc rijndaelCipherInit (rijndaelCipherInstance *cipher, rijndael_mode mode, - const char *IV) + const char *IV) { if ((mode == RIJNDAEL_MODE_ECB) || (mode == RIJNDAEL_MODE_CBC) || (mode == RIJNDAEL_MODE_CFB1)) @@ -165,31 +165,31 @@ rijndaelCipherInit (rijndaelCipherInstance *cipher, rijndael_mode mode, { int i; for (i = 0; i < RIJNDAEL_MAX_IV_SIZE; i++) - { - int t, j; - - t = IV[2 * i]; - if ((t >= '0') && (t <= '9')) - j = (t - '0') << 4; - else if ((t >= 'a') && (t <= 'f')) - j = (t - 'a' + 10) << 4; - else if ((t >= 'A') && (t <= 'F')) - j = (t - 'A' + 10) << 4; - else - return RIJNDAEL_BAD_CIPHER_INSTANCE; - - t = IV[2 * i + 1]; - if ((t >= '0') && (t <= '9')) - j ^= (t - '0'); - else if ((t >= 'a') && (t <= 'f')) - j ^= (t - 'a' + 10); - else if ((t >= 'A') && (t <= 'F')) - j ^= (t - 'A' + 10); - else - return RIJNDAEL_BAD_CIPHER_INSTANCE; - - cipher->IV[i] = (uint8_t) j; - } + { + int t, j; + + t = IV[2 * i]; + if ((t >= '0') && (t <= '9')) + j = (t - '0') << 4; + else if ((t >= 'a') && (t <= 'f')) + j = (t - 'a' + 10) << 4; + else if ((t >= 'A') && (t <= 'F')) + j = (t - 'A' + 10) << 4; + else + return RIJNDAEL_BAD_CIPHER_INSTANCE; + + t = IV[2 * i + 1]; + if ((t >= '0') && (t <= '9')) + j ^= (t - '0'); + else if ((t >= 'a') && (t <= 'f')) + j ^= (t - 'a' + 10); + else if ((t >= 'A') && (t <= 'F')) + j ^= (t - 'A' + 10); + else + return RIJNDAEL_BAD_CIPHER_INSTANCE; + + cipher->IV[i] = (uint8_t) j; + } } else { @@ -200,9 +200,9 @@ rijndaelCipherInit (rijndaelCipherInstance *cipher, rijndael_mode mode, int rijndaelBlockEncrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, - size_t inputLen, char *outBuffer) + const rijndaelKeyInstance *key, + const char *input, + size_t inputLen, char *outBuffer) { size_t i, k, t, numBlocks; char block[16], *iv; @@ -213,7 +213,7 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher, } if (input == NULL || inputLen <= 0) { - return 0; /* nothing to do */ + return 0; /* nothing to do */ } numBlocks = inputLen / 128; @@ -222,51 +222,51 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher, { case RIJNDAEL_MODE_ECB: for (i = numBlocks; i > 0; i--) - { - rijndaelEncrypt (key->rk, key->Nr, input, outBuffer); - input += 16; - outBuffer += 16; - } + { + rijndaelEncrypt (key->rk, key->Nr, input, outBuffer); + input += 16; + outBuffer += 16; + } break; case RIJNDAEL_MODE_CBC: iv = cipher->IV; for (i = numBlocks; i > 0; i--) - { - ((uint32_t *) block)[0] = ((uint32_t *) input)[0] ^ - ((uint32_t *) iv)[0]; - ((uint32_t *) block)[1] = ((uint32_t *) input)[1] ^ - ((uint32_t *) iv)[1]; - ((uint32_t *) block)[2] = ((uint32_t *) input)[2] ^ - ((uint32_t *) iv)[2]; - ((uint32_t *) block)[3] = ((uint32_t *) input)[3] ^ - ((uint32_t *) iv)[3]; - rijndaelEncrypt (key->rk, key->Nr, block, outBuffer); - memcpy (cipher->IV, outBuffer, 16); - input += 16; - outBuffer += 16; - } + { + ((uint32_t *) block)[0] = ((uint32_t *) input)[0] ^ + ((uint32_t *) iv)[0]; + ((uint32_t *) block)[1] = ((uint32_t *) input)[1] ^ + ((uint32_t *) iv)[1]; + ((uint32_t *) block)[2] = ((uint32_t *) input)[2] ^ + ((uint32_t *) iv)[2]; + ((uint32_t *) block)[3] = ((uint32_t *) input)[3] ^ + ((uint32_t *) iv)[3]; + rijndaelEncrypt (key->rk, key->Nr, block, outBuffer); + memcpy (cipher->IV, outBuffer, 16); + input += 16; + outBuffer += 16; + } break; case RIJNDAEL_MODE_CFB1: iv = cipher->IV; for (i = numBlocks; i > 0; i--) - { - memcpy (outBuffer, input, 16); - for (k = 0; k < 128; k++) - { - rijndaelEncrypt (key->ek, key->Nr, iv, block); - outBuffer[k >> 3] ^= (block[0] & 0x80U) >> (k & 7); - for (t = 0; t < 15; t++) - { - iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7); - } - iv[15] = (iv[15] << 1) | - ((outBuffer[k >> 3] >> (7 - (k & 7))) & 1); - } - outBuffer += 16; - input += 16; - } + { + memcpy (outBuffer, input, 16); + for (k = 0; k < 128; k++) + { + rijndaelEncrypt (key->ek, key->Nr, iv, block); + outBuffer[k >> 3] ^= (block[0] & 0x80U) >> (k & 7); + for (t = 0; t < 15; t++) + { + iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7); + } + iv[15] = (iv[15] << 1) | + ((outBuffer[k >> 3] >> (7 - (k & 7))) & 1); + } + outBuffer += 16; + input += 16; + } break; default: @@ -278,9 +278,9 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher, int rijndaelPadEncrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, - size_t inputOctets, char *outBuffer) + const rijndaelKeyInstance *key, + const char *input, + size_t inputOctets, char *outBuffer) { size_t i, numBlocks, padLen; char block[16], *iv; @@ -291,7 +291,7 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher, } if (input == NULL || inputOctets <= 0) { - return 0; /* nothing to do */ + return 0; /* nothing to do */ } numBlocks = inputOctets / 16; @@ -300,11 +300,11 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher, { case RIJNDAEL_MODE_ECB: for (i = numBlocks; i > 0; i--) - { - rijndaelEncrypt (key->rk, key->Nr, input, outBuffer); - input += 16; - outBuffer += 16; - } + { + rijndaelEncrypt (key->rk, key->Nr, input, outBuffer); + input += 16; + outBuffer += 16; + } padLen = 16 - (inputOctets - 16 * numBlocks); assert (padLen > 0 && padLen <= 16); memcpy (block, input, 16 - padLen); @@ -315,30 +315,30 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher, case RIJNDAEL_MODE_CBC: iv = cipher->IV; for (i = numBlocks; i > 0; i--) - { - ((uint32_t *) block)[0] = ((uint32_t *) input)[0] ^ - ((uint32_t *) iv)[0]; - ((uint32_t *) block)[1] = ((uint32_t *) input)[1] ^ - ((uint32_t *) iv)[1]; - ((uint32_t *) block)[2] = ((uint32_t *) input)[2] ^ - ((uint32_t *) iv)[2]; - ((uint32_t *) block)[3] = ((uint32_t *) input)[3] ^ - ((uint32_t *) iv)[3]; - rijndaelEncrypt (key->rk, key->Nr, block, outBuffer); - memcpy (cipher->IV, outBuffer, 16); - input += 16; - outBuffer += 16; - } + { + ((uint32_t *) block)[0] = ((uint32_t *) input)[0] ^ + ((uint32_t *) iv)[0]; + ((uint32_t *) block)[1] = ((uint32_t *) input)[1] ^ + ((uint32_t *) iv)[1]; + ((uint32_t *) block)[2] = ((uint32_t *) input)[2] ^ + ((uint32_t *) iv)[2]; + ((uint32_t *) block)[3] = ((uint32_t *) input)[3] ^ + ((uint32_t *) iv)[3]; + rijndaelEncrypt (key->rk, key->Nr, block, outBuffer); + memcpy (cipher->IV, outBuffer, 16); + input += 16; + outBuffer += 16; + } padLen = 16 - (inputOctets - 16 * numBlocks); assert (padLen > 0 && padLen <= 16); for (i = 0; i < 16 - padLen; i++) - { - block[i] = input[i] ^ iv[i]; - } + { + block[i] = input[i] ^ iv[i]; + } for (i = 16 - padLen; i < 16; i++) - { - block[i] = (char) padLen ^ iv[i]; - } + { + block[i] = (char) padLen ^ iv[i]; + } rijndaelEncrypt (key->rk, key->Nr, block, outBuffer); memcpy (cipher->IV, outBuffer, 16); break; @@ -352,9 +352,9 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher, int rijndaelBlockDecrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, - size_t inputLen, char *outBuffer) + const rijndaelKeyInstance *key, + const char *input, + size_t inputLen, char *outBuffer) { size_t i, k, t, numBlocks; char block[16], *iv; @@ -368,7 +368,7 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher, } if (input == NULL || inputLen <= 0) { - return 0; /* nothing to do */ + return 0; /* nothing to do */ } numBlocks = inputLen / 128; @@ -377,47 +377,47 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher, { case RIJNDAEL_MODE_ECB: for (i = numBlocks; i > 0; i--) - { - rijndaelDecrypt (key->rk, key->Nr, input, outBuffer); - input += 16; - outBuffer += 16; - } + { + rijndaelDecrypt (key->rk, key->Nr, input, outBuffer); + input += 16; + outBuffer += 16; + } break; case RIJNDAEL_MODE_CBC: iv = cipher->IV; for (i = numBlocks; i > 0; i--) - { - rijndaelDecrypt (key->rk, key->Nr, input, block); - ((uint32_t *) block)[0] ^= ((uint32_t *) iv)[0]; - ((uint32_t *) block)[1] ^= ((uint32_t *) iv)[1]; - ((uint32_t *) block)[2] ^= ((uint32_t *) iv)[2]; - ((uint32_t *) block)[3] ^= ((uint32_t *) iv)[3]; - memcpy (cipher->IV, input, 16); - memcpy (outBuffer, block, 16); - input += 16; - outBuffer += 16; - } + { + rijndaelDecrypt (key->rk, key->Nr, input, block); + ((uint32_t *) block)[0] ^= ((uint32_t *) iv)[0]; + ((uint32_t *) block)[1] ^= ((uint32_t *) iv)[1]; + ((uint32_t *) block)[2] ^= ((uint32_t *) iv)[2]; + ((uint32_t *) block)[3] ^= ((uint32_t *) iv)[3]; + memcpy (cipher->IV, input, 16); + memcpy (outBuffer, block, 16); + input += 16; + outBuffer += 16; + } break; case RIJNDAEL_MODE_CFB1: iv = cipher->IV; for (i = numBlocks; i > 0; i--) - { - memcpy (outBuffer, input, 16); - for (k = 0; k < 128; k++) - { - rijndaelEncrypt (key->ek, key->Nr, iv, block); - for (t = 0; t < 15; t++) - { - iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7); - } - iv[15] = (iv[15] << 1) | ((input[k >> 3] >> (7 - (k & 7))) & 1); - outBuffer[k >> 3] ^= (block[0] & 0x80U) >> (k & 7); - } - outBuffer += 16; - input += 16; - } + { + memcpy (outBuffer, input, 16); + for (k = 0; k < 128; k++) + { + rijndaelEncrypt (key->ek, key->Nr, iv, block); + for (t = 0; t < 15; t++) + { + iv[t] = (iv[t] << 1) | (iv[t + 1] >> 7); + } + iv[15] = (iv[15] << 1) | ((input[k >> 3] >> (7 - (k & 7))) & 1); + outBuffer[k >> 3] ^= (block[0] & 0x80U) >> (k & 7); + } + outBuffer += 16; + input += 16; + } break; default: @@ -429,9 +429,9 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher, int rijndaelPadDecrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, - size_t inputOctets, char *outBuffer) + const rijndaelKeyInstance *key, + const char *input, + size_t inputOctets, char *outBuffer) { size_t i, numBlocks, padLen; char block[16]; @@ -442,7 +442,7 @@ rijndaelPadDecrypt (rijndaelCipherInstance *cipher, } if (input == NULL || inputOctets <= 0) { - return 0; /* nothing to do */ + return 0; /* nothing to do */ } if (inputOctets % 16 != 0) { @@ -456,42 +456,42 @@ rijndaelPadDecrypt (rijndaelCipherInstance *cipher, case RIJNDAEL_MODE_ECB: /* all blocks but last */ for (i = numBlocks - 1; i > 0; i--) - { - rijndaelDecrypt (key->rk, key->Nr, input, outBuffer); - input += 16; - outBuffer += 16; - } + { + rijndaelDecrypt (key->rk, key->Nr, input, outBuffer); + input += 16; + outBuffer += 16; + } /* last block */ rijndaelDecrypt (key->rk, key->Nr, input, block); padLen = block[15]; if (padLen >= 16) - { - return RIJNDAEL_BAD_DATA; - } + { + return RIJNDAEL_BAD_DATA; + } for (i = 16 - padLen; i < 16; i++) - { - if (block[i] != padLen) - { - return RIJNDAEL_BAD_DATA; - } - } + { + if (block[i] != padLen) + { + return RIJNDAEL_BAD_DATA; + } + } memcpy (outBuffer, block, 16 - padLen); break; case RIJNDAEL_MODE_CBC: /* all blocks but last */ for (i = numBlocks - 1; i > 0; i--) - { - rijndaelDecrypt (key->rk, key->Nr, input, block); - ((uint32_t *) block)[0] ^= ((uint32_t *) cipher->IV)[0]; - ((uint32_t *) block)[1] ^= ((uint32_t *) cipher->IV)[1]; - ((uint32_t *) block)[2] ^= ((uint32_t *) cipher->IV)[2]; - ((uint32_t *) block)[3] ^= ((uint32_t *) cipher->IV)[3]; - memcpy (cipher->IV, input, 16); - memcpy (outBuffer, block, 16); - input += 16; - outBuffer += 16; - } + { + rijndaelDecrypt (key->rk, key->Nr, input, block); + ((uint32_t *) block)[0] ^= ((uint32_t *) cipher->IV)[0]; + ((uint32_t *) block)[1] ^= ((uint32_t *) cipher->IV)[1]; + ((uint32_t *) block)[2] ^= ((uint32_t *) cipher->IV)[2]; + ((uint32_t *) block)[3] ^= ((uint32_t *) cipher->IV)[3]; + memcpy (cipher->IV, input, 16); + memcpy (outBuffer, block, 16); + input += 16; + outBuffer += 16; + } /* last block */ rijndaelDecrypt (key->rk, key->Nr, input, block); ((uint32_t *) block)[0] ^= ((uint32_t *) cipher->IV)[0]; @@ -500,16 +500,16 @@ rijndaelPadDecrypt (rijndaelCipherInstance *cipher, ((uint32_t *) block)[3] ^= ((uint32_t *) cipher->IV)[3]; padLen = block[15]; if (padLen <= 0 || padLen > 16) - { - return RIJNDAEL_BAD_DATA; - } + { + return RIJNDAEL_BAD_DATA; + } for (i = 16 - padLen; i < 16; i++) - { - if (block[i] != padLen) - { - return RIJNDAEL_BAD_DATA; - } - } + { + if (block[i] != padLen) + { + return RIJNDAEL_BAD_DATA; + } + } memcpy (outBuffer, block, 16 - padLen); break; diff --git a/lib/rijndael-api-fst.h b/lib/rijndael-api-fst.h index 2e1dfa66a..e0a3c41d8 100644 --- a/lib/rijndael-api-fst.h +++ b/lib/rijndael-api-fst.h @@ -95,15 +95,15 @@ typedef enum typedef enum { - RIJNDAEL_DIR_ENCRYPT = 0, /* Are we encrypting? */ - RIJNDAEL_DIR_DECRYPT = 1 /* Are we decrypting? */ + RIJNDAEL_DIR_ENCRYPT = 0, /* Are we encrypting? */ + RIJNDAEL_DIR_DECRYPT = 1 /* Are we decrypting? */ } rijndael_direction; typedef enum { - RIJNDAEL_MODE_ECB = 1, /* Are we ciphering in ECB mode? */ - RIJNDAEL_MODE_CBC = 2, /* Are we ciphering in CBC mode? */ - RIJNDAEL_MODE_CFB1 = 3 /* Are we ciphering in 1-bit CFB mode? */ + RIJNDAEL_MODE_ECB = 1, /* Are we ciphering in ECB mode? */ + RIJNDAEL_MODE_CBC = 2, /* Are we ciphering in CBC mode? */ + RIJNDAEL_MODE_CFB1 = 3 /* Are we ciphering in 1-bit CFB mode? */ } rijndael_mode; /* The structure for key information */ @@ -125,8 +125,8 @@ typedef struct /* The structure for cipher information */ typedef struct -{ /* changed order of the components */ - rijndael_mode mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ +{ /* changed order of the components */ + rijndael_mode mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ /* A possible Initialization Vector for ciphering */ char IV[RIJNDAEL_MAX_IV_SIZE]; } rijndaelCipherInstance; @@ -138,7 +138,7 @@ typedef struct 128, 192 or 256. Returns 0 on success, or an error code. */ extern rijndael_rc rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction, - size_t keyLen, const char *keyMaterial); + size_t keyLen, const char *keyMaterial); /* Initialize cipher state CIPHER for encryption MODE (e.g., RIJNDAEL_MODE_CBC) with initialization vector IV, a hex string of @@ -146,7 +146,7 @@ rijndaelMakeKey (rijndaelKeyInstance *key, rijndael_direction direction, not need an IV (i.e., RIJNDAEL_MODE_ECB). */ extern rijndael_rc rijndaelCipherInit (rijndaelCipherInstance *cipher, - rijndael_mode mode, const char *IV); + rijndael_mode mode, const char *IV); /* Encrypt data in INPUT, of INPUTLEN/8 bytes length, placing the output in the pre-allocated OUTBUFFER which must hold at least @@ -157,9 +157,9 @@ rijndaelCipherInit (rijndaelCipherInstance *cipher, negative rijndael_rc error code. */ extern int rijndaelBlockEncrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, size_t inputLen, - char *outBuffer); + const rijndaelKeyInstance *key, + const char *input, size_t inputLen, + char *outBuffer); /* Encrypt data in INPUT, of INPUTOCTETS bytes length, placing the output in the pre-allocated OUTBUFFER which must hold at least @@ -172,9 +172,9 @@ rijndaelBlockEncrypt (rijndaelCipherInstance *cipher, negative rijndael_rc error code. */ extern int rijndaelPadEncrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, size_t inputOctets, - char *outBuffer); + const rijndaelKeyInstance *key, + const char *input, size_t inputOctets, + char *outBuffer); /* Decrypt data in INPUT, of INPUTLEN/8 bytes length, placing the output in the pre-allocated OUTBUFFER which must hold at least @@ -185,9 +185,9 @@ rijndaelPadEncrypt (rijndaelCipherInstance *cipher, negative rijndael_rc error code. */ extern int rijndaelBlockDecrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, size_t inputLen, - char *outBuffer); + const rijndaelKeyInstance *key, + const char *input, size_t inputLen, + char *outBuffer); /* Decrypt data in INPUT, of INPUTOCTETS bytes length, placing the output in the pre-allocated OUTBUFFER which must hold at least @@ -200,8 +200,8 @@ rijndaelBlockDecrypt (rijndaelCipherInstance *cipher, negative rijndael_rc error code. */ extern int rijndaelPadDecrypt (rijndaelCipherInstance *cipher, - const rijndaelKeyInstance *key, - const char *input, size_t inputOctets, - char *outBuffer); + const rijndaelKeyInstance *key, + const char *input, size_t inputOctets, + char *outBuffer); #endif /* __RIJNDAEL_API_FST_H */ diff --git a/lib/rmdir.c b/lib/rmdir.c index 1a0698669..d14f50ecf 100644 --- a/lib/rmdir.c +++ b/lib/rmdir.c @@ -60,7 +60,7 @@ rpl_rmdir (char const *dir) struct stat statbuf; if (stat (dir, &statbuf) != 0) - return -1; /* errno already set */ + return -1; /* errno already set */ if (!S_ISDIR (statbuf.st_mode)) { @@ -71,28 +71,28 @@ rpl_rmdir (char const *dir) cpid = fork (); switch (cpid) { - case -1: /* cannot fork */ - return -1; /* errno already set */ + case -1: /* cannot fork */ + return -1; /* errno already set */ - case 0: /* child process */ + case 0: /* child process */ execl ("/bin/rmdir", "rmdir", dir, (char *) 0); _exit (1); - default: /* parent process */ + default: /* parent process */ /* Wait for kid to finish. */ while (wait (&status) != cpid) - /* Do nothing. */ ; + /* Do nothing. */ ; if (status) - { + { - /* /bin/rmdir failed. */ + /* /bin/rmdir failed. */ - errno = EIO; - return -1; - } + errno = EIO; + return -1; + } return 0; } #endif /* !HAVE_RMDIR */ diff --git a/lib/round.c b/lib/round.c index df6232d51..64462f4de 100644 --- a/lib/round.c +++ b/lib/round.c @@ -114,39 +114,39 @@ FLOOR_FREE_ROUND (DOUBLE x) { /* Avoid rounding error for x = 0.5 - 2^(-MANT_DIG-1). */ if (z < L_(0.5)) - z = L_(0.0); + z = L_(0.0); /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ else if (z < TWO_MANT_DIG) - { - /* Add 0.5 to the absolute value. */ - y = z += L_(0.5); - /* Round to the next integer (nearest or up or down, doesn't + { + /* Add 0.5 to the absolute value. */ + y = z += L_(0.5); + /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding error for x = -(0.5 - 2^(-MANT_DIG-1)). */ if (z > - L_(0.5)) - z = L_(0.0); + z = L_(0.0); /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ else if (z > -TWO_MANT_DIG) - { - /* Add 0.5 to the absolute value. */ - y = z -= L_(0.5); - /* Round to the next integer (nearest or up or down, doesn't + { + /* Add 0.5 to the absolute value. */ + y = z -= L_(0.5); + /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; } diff --git a/lib/rpmatch.c b/lib/rpmatch.c index 217e1710a..4d8ed96eb 100644 --- a/lib/rpmatch.c +++ b/lib/rpmatch.c @@ -43,7 +43,7 @@ The resulting string may only be used until the next nl_langinfo call. */ static const char * localized_pattern (const char *english_pattern, nl_item nl_index, - bool posixly_correct) + bool posixly_correct) { const char *translated_pattern; @@ -65,7 +65,7 @@ localized_pattern (const char *english_pattern, nl_item nl_index, translated_pattern = nl_langinfo (nl_index); /* Check against a broken system return value. */ if (translated_pattern != NULL && translated_pattern[0] != '\0') - return translated_pattern; + return translated_pattern; } /* Look in the gnulib message catalog. */ @@ -73,11 +73,11 @@ localized_pattern (const char *english_pattern, nl_item nl_index, if (translated_pattern == english_pattern) { /* The gnulib message catalog provides no translation. - Try the system's message catalog. */ + Try the system's message catalog. */ translated_pattern = nl_langinfo (nl_index); /* Check against a broken system return value. */ if (translated_pattern != NULL && translated_pattern[0] != '\0') - return translated_pattern; + return translated_pattern; /* Fall back to English. */ translated_pattern = english_pattern; } @@ -97,20 +97,20 @@ try (const char *response, const char *pattern, char **lastp, regex_t *re) /* The pattern has changed. */ if (*lastp != NULL) - { - /* Free the old compiled pattern. */ - regfree (re); - free (*lastp); - *lastp = NULL; - } + { + /* Free the old compiled pattern. */ + regfree (re); + free (*lastp); + *lastp = NULL; + } /* Put the PATTERN into safe memory before calling regcomp. - (regcomp may call nl_langinfo, overwriting PATTERN's storage. */ + (regcomp may call nl_langinfo, overwriting PATTERN's storage. */ safe_pattern = strdup (pattern); if (safe_pattern == NULL) - return -1; + return -1; /* Compile the pattern and cache it for future runs. */ if (regcomp (re, safe_pattern, REG_EXTENDED) != 0) - return -1; + return -1; *lastp = safe_pattern; } @@ -168,6 +168,6 @@ rpmatch (const char *response) #else /* Test against "^[yY]" and "^[nN]", hardcoded to avoid requiring regex */ return (*response == 'y' || *response == 'Y' ? 1 - : *response == 'n' || *response == 'N' ? 0 : -1); + : *response == 'n' || *response == 'N' ? 0 : -1); #endif } diff --git a/lib/safe-read.c b/lib/safe-read.c index 0cb1edee8..c29e62217 100644 --- a/lib/safe-read.c +++ b/lib/safe-read.c @@ -66,12 +66,12 @@ safe_rw (int fd, void const *buf, size_t count) ssize_t result = rw (fd, buf, count); if (0 <= result) - return result; + return result; else if (IS_EINTR (errno)) - continue; + continue; else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count) - count = BUGGY_READ_MAXIMUM; + count = BUGGY_READ_MAXIMUM; else - return result; + return result; } } diff --git a/lib/same.c b/lib/same.c index af3a95efb..6b46e8d85 100644 --- a/lib/same.c +++ b/lib/same.c @@ -85,36 +85,36 @@ same_name (const char *source, const char *dest) dest_dirname = dir_name (dest); if (stat (source_dirname, &source_dir_stats)) - { - /* Shouldn't happen. */ - error (1, errno, "%s", source_dirname); - } + { + /* Shouldn't happen. */ + error (1, errno, "%s", source_dirname); + } if (stat (dest_dirname, &dest_dir_stats)) - { - /* Shouldn't happen. */ - error (1, errno, "%s", dest_dirname); - } + { + /* Shouldn't happen. */ + error (1, errno, "%s", dest_dirname); + } same = SAME_INODE (source_dir_stats, dest_dir_stats); #if ! _POSIX_NO_TRUNC && HAVE_PATHCONF && defined _PC_NAME_MAX if (same && ! identical_basenames) - { - long name_max = (errno = 0, pathconf (dest_dirname, _PC_NAME_MAX)); - if (name_max < 0) - { - if (errno) - { - /* Shouldn't happen. */ - error (1, errno, "%s", dest_dirname); - } - same = false; - } - else - same = (name_max <= min_baselen - && memcmp (source_basename, dest_basename, name_max) == 0); - } + { + long name_max = (errno = 0, pathconf (dest_dirname, _PC_NAME_MAX)); + if (name_max < 0) + { + if (errno) + { + /* Shouldn't happen. */ + error (1, errno, "%s", dest_dirname); + } + same = false; + } + else + same = (name_max <= min_baselen + && memcmp (source_basename, dest_basename, name_max) == 0); + } #endif free (source_dirname); diff --git a/lib/savedir.c b/lib/savedir.c index 5e69d386f..455f32028 100644 --- a/lib/savedir.c +++ b/lib/savedir.c @@ -28,7 +28,7 @@ #include "dirent--.h" #ifndef _D_EXACT_NAMLEN -# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name) +# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name) #endif #include @@ -68,31 +68,31 @@ savedirstream (DIR *dirp) errno = 0; dp = readdir (dirp); if (! dp) - break; + break; /* Skip "", ".", and "..". "" is returned by at least one buggy implementation: Solaris 2.4 readdir on NFS file systems. */ entry = dp->d_name; if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0') - { - size_t entry_size = _D_EXACT_NAMLEN (dp) + 1; - if (used + entry_size < used) - xalloc_die (); - if (allocated <= used + entry_size) - { - do - { - if (2 * allocated < allocated) - xalloc_die (); - allocated *= 2; - } - while (allocated <= used + entry_size); - - name_space = xrealloc (name_space, allocated); - } - memcpy (name_space + used, entry, entry_size); - used += entry_size; - } + { + size_t entry_size = _D_EXACT_NAMLEN (dp) + 1; + if (used + entry_size < used) + xalloc_die (); + if (allocated <= used + entry_size) + { + do + { + if (2 * allocated < allocated) + xalloc_die (); + allocated *= 2; + } + while (allocated <= used + entry_size); + + name_space = xrealloc (name_space, allocated); + } + memcpy (name_space + used, entry, entry_size); + used += entry_size; + } } name_space[used] = '\0'; save_errno = errno; diff --git a/lib/savewd.c b/lib/savewd.c index f593f9467..dfb33b7ea 100644 --- a/lib/savewd.c +++ b/lib/savewd.c @@ -45,38 +45,38 @@ savewd_save (struct savewd *wd) case INITIAL_STATE: /* Save the working directory, or prepare to fall back if possible. */ { - int fd = open_safer (".", O_RDONLY); - if (0 <= fd) - { - wd->state = FD_STATE; - wd->val.fd = fd; - break; - } - if (errno != EACCES && errno != ESTALE) - { - wd->state = ERROR_STATE; - wd->val.errnum = errno; - break; - } + int fd = open_safer (".", O_RDONLY); + if (0 <= fd) + { + wd->state = FD_STATE; + wd->val.fd = fd; + break; + } + if (errno != EACCES && errno != ESTALE) + { + wd->state = ERROR_STATE; + wd->val.errnum = errno; + break; + } } wd->state = FORKING_STATE; wd->val.child = -1; /* Fall through. */ case FORKING_STATE: if (wd->val.child < 0) - { - /* "Save" the initial working directory by forking a new - subprocess that will attempt all the work from the chdir - until until the next savewd_restore. */ - wd->val.child = fork (); - if (wd->val.child != 0) - { - if (0 < wd->val.child) - return true; - wd->state = ERROR_STATE; - wd->val.errnum = errno; - } - } + { + /* "Save" the initial working directory by forking a new + subprocess that will attempt all the work from the chdir + until until the next savewd_restore. */ + wd->val.child = fork (); + if (wd->val.child != 0) + { + if (0 < wd->val.child) + return true; + wd->state = ERROR_STATE; + wd->val.errnum = errno; + } + } break; case FD_STATE: @@ -94,7 +94,7 @@ savewd_save (struct savewd *wd) int savewd_chdir (struct savewd *wd, char const *dir, int options, - int open_result[2]) + int open_result[2]) { int fd = -1; int result = 0; @@ -105,50 +105,50 @@ savewd_chdir (struct savewd *wd, char const *dir, int options, || (options & (HAVE_WORKING_O_NOFOLLOW ? SAVEWD_CHDIR_NOFOLLOW : 0))) { fd = open (dir, - (O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK - | (options & SAVEWD_CHDIR_NOFOLLOW ? O_NOFOLLOW : 0))); + (O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK + | (options & SAVEWD_CHDIR_NOFOLLOW ? O_NOFOLLOW : 0))); if (open_result) - { - open_result[0] = fd; - open_result[1] = errno; - } + { + open_result[0] = fd; + open_result[1] = errno; + } if (fd < 0 && (errno != EACCES || (options & SAVEWD_CHDIR_READABLE))) - result = -1; + result = -1; } if (result == 0 && ! (0 <= fd && options & SAVEWD_CHDIR_SKIP_READABLE)) { if (savewd_save (wd)) - { - open_result = NULL; - result = -2; - } + { + open_result = NULL; + result = -2; + } else - { - result = (fd < 0 ? chdir (dir) : fchdir (fd)); - - if (result == 0) - switch (wd->state) - { - case FD_STATE: - wd->state = FD_POST_CHDIR_STATE; - break; - - case ERROR_STATE: - case FD_POST_CHDIR_STATE: - case FINAL_STATE: - break; - - case FORKING_STATE: - assert (wd->val.child == 0); - break; - - default: - assert (false); - } - } + { + result = (fd < 0 ? chdir (dir) : fchdir (fd)); + + if (result == 0) + switch (wd->state) + { + case FD_STATE: + wd->state = FD_POST_CHDIR_STATE; + break; + + case ERROR_STATE: + case FD_POST_CHDIR_STATE: + case FINAL_STATE: + break; + + case FORKING_STATE: + assert (wd->val.child == 0); + break; + + default: + assert (false); + } + } } if (0 <= fd && ! open_result) @@ -169,23 +169,23 @@ savewd_restore (struct savewd *wd, int status) case INITIAL_STATE: case FD_STATE: /* The working directory is the desired directory, so there's no - work to do. */ + work to do. */ break; case FD_POST_CHDIR_STATE: /* Restore the working directory using fchdir. */ if (fchdir (wd->val.fd) == 0) - { - wd->state = FD_STATE; - break; - } + { + wd->state = FD_STATE; + break; + } else - { - int chdir_errno = errno; - close (wd->val.fd); - wd->state = ERROR_STATE; - wd->val.errnum = chdir_errno; - } + { + int chdir_errno = errno; + close (wd->val.fd); + wd->state = ERROR_STATE; + wd->val.errnum = chdir_errno; + } /* Fall through. */ case ERROR_STATE: /* Report an error if asked to restore the working directory. */ @@ -194,21 +194,21 @@ savewd_restore (struct savewd *wd, int status) case FORKING_STATE: /* "Restore" the working directory by waiting for the subprocess - to finish. */ + to finish. */ { - pid_t child = wd->val.child; - if (child == 0) - _exit (status); - if (0 < child) - { - int child_status; - while (waitpid (child, &child_status, 0) < 0) - assert (errno == EINTR); - wd->val.child = -1; - if (! WIFEXITED (child_status)) - raise (WTERMSIG (child_status)); - return WEXITSTATUS (child_status); - } + pid_t child = wd->val.child; + if (child == 0) + _exit (status); + if (0 < child) + { + int child_status; + while (waitpid (child, &child_status, 0) < 0) + assert (errno == EINTR); + wd->val.child = -1; + if (! WIFEXITED (child_status)) + raise (WTERMSIG (child_status)); + return WEXITSTATUS (child_status); + } } break; @@ -262,8 +262,8 @@ savewd_delegating (struct savewd const *wd) int savewd_process_files (int n_files, char **file, - int (*act) (char *, struct savewd *, void *), - void *options) + int (*act) (char *, struct savewd *, void *), + void *options) { int i = 0; int last_relative; @@ -278,18 +278,18 @@ savewd_process_files (int n_files, char **file, for (; i < last_relative; i++) { if (! savewd_delegating (&wd)) - { - int s = act (file[i], &wd, options); - if (exit_status < s) - exit_status = s; - } + { + int s = act (file[i], &wd, options); + if (exit_status < s) + exit_status = s; + } if (! IS_ABSOLUTE_FILE_NAME (file[i + 1])) - { - int r = savewd_restore (&wd, exit_status); - if (exit_status < r) - exit_status = r; - } + { + int r = savewd_restore (&wd, exit_status); + if (exit_status < r) + exit_status = r; + } } savewd_finish (&wd); @@ -298,7 +298,7 @@ savewd_process_files (int n_files, char **file, { int s = act (file[i], &wd, options); if (exit_status < s) - exit_status = s; + exit_status = s; } return exit_status; diff --git a/lib/savewd.h b/lib/savewd.h index 0d293c941..d56476fe0 100644 --- a/lib/savewd.h +++ b/lib/savewd.h @@ -31,29 +31,29 @@ struct savewd enum { /* This object has been created but does not yet represent - the working directory. */ + the working directory. */ INITIAL_STATE, /* val.fd is the original working directory's file descriptor. - It is still the working directory. */ + It is still the working directory. */ FD_STATE, /* Like FD_STATE, but the working directory has changed, so - restoring it will require a fchdir. */ + restoring it will require a fchdir. */ FD_POST_CHDIR_STATE, /* Fork and let the subprocess do the work. val.child is 0 in a - child, negative in a childless parent, and the child process - ID in a parent with a child. */ + child, negative in a childless parent, and the child process + ID in a parent with a child. */ FORKING_STATE, /* A serious problem argues against further efforts. val.errnum - contains the error number (e.g., EIO). */ + contains the error number (e.g., EIO). */ ERROR_STATE, /* savewd_finish has been called, so the application no longer - cares whether the working directory is saved, and there is no - more work to do. */ + cares whether the working directory is saved, and there is no + more work to do. */ FINAL_STATE } state; @@ -106,7 +106,7 @@ enum Return -2 if a subprocess was spun off to do the real work, -1 (setting errno) if unsuccessful, 0 if successful. */ int savewd_chdir (struct savewd *wd, char const *dir, int options, - int open_result[2]); + int open_result[2]); /* Restore the working directory from *WD. STATUS indicates the exit status corresponding to the work done since the last save; this is @@ -142,7 +142,7 @@ void savewd_finish (struct savewd *wd); Return the maximum exit status that any call to ACT returned, or EXIT_SUCCESS (i.e., 0) if no calls were made. */ int savewd_process_files (int n_files, char **file, - int (*act) (char *, struct savewd *, void *), - void *options); + int (*act) (char *, struct savewd *, void *), + void *options); #endif diff --git a/lib/scandir.c b/lib/scandir.c index 54a74d5e0..9435c1b27 100644 --- a/lib/scandir.c +++ b/lib/scandir.c @@ -83,9 +83,9 @@ cancel_handler (void *arg) int SCANDIR (const char *dir, - DIRENT_TYPE ***namelist, - int (*select) (const DIRENT_TYPE *), - int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **)) + DIRENT_TYPE ***namelist, + int (*select) (const DIRENT_TYPE *), + int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **)) { DIR *dp = __opendir (dir); DIRENT_TYPE **v = NULL; @@ -112,43 +112,43 @@ SCANDIR (const char *dir, int use_it = select == NULL; if (! use_it) - { - use_it = select (d); - /* The select function might have changed errno. It was - zero before and it need to be again to make the latter - tests work. */ - __set_errno (0); - } + { + use_it = select (d); + /* The select function might have changed errno. It was + zero before and it need to be again to make the latter + tests work. */ + __set_errno (0); + } if (use_it) - { - DIRENT_TYPE *vnew; - size_t dsize; - - /* Ignore errors from select or readdir */ - __set_errno (0); - - if (__builtin_expect (c.cnt == vsize, 0)) - { - DIRENT_TYPE **new; - if (vsize == 0) - vsize = 10; - else - vsize *= 2; - new = (DIRENT_TYPE **) realloc (v, vsize * sizeof (*v)); - if (new == NULL) - break; - v = new; - c.v = (void *) v; - } - - dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d; - vnew = (DIRENT_TYPE *) malloc (dsize); - if (vnew == NULL) - break; - - v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize); - } + { + DIRENT_TYPE *vnew; + size_t dsize; + + /* Ignore errors from select or readdir */ + __set_errno (0); + + if (__builtin_expect (c.cnt == vsize, 0)) + { + DIRENT_TYPE **new; + if (vsize == 0) + vsize = 10; + else + vsize *= 2; + new = (DIRENT_TYPE **) realloc (v, vsize * sizeof (*v)); + if (new == NULL) + break; + v = new; + c.v = (void *) v; + } + + dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d; + vnew = (DIRENT_TYPE *) malloc (dsize); + if (vnew == NULL) + break; + + v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize); + } } if (__builtin_expect (errno, 0) != 0) @@ -156,7 +156,7 @@ SCANDIR (const char *dir, save = errno; while (c.cnt > 0) - free (v[--c.cnt]); + free (v[--c.cnt]); free (v); c.cnt = -1; } @@ -164,7 +164,7 @@ SCANDIR (const char *dir, { /* Sort the list if we have a comparison function to sort with. */ if (cmp != NULL) - qsort (v, c.cnt, sizeof (*v), (int (*) (const void *, const void *)) cmp); + qsort (v, c.cnt, sizeof (*v), (int (*) (const void *, const void *)) cmp); *namelist = v; } diff --git a/lib/se-context.in.h b/lib/se-context.in.h index 5eb95af22..2c36cc20a 100644 --- a/lib/se-context.in.h +++ b/lib/se-context.in.h @@ -11,16 +11,16 @@ static inline char *context_str (context_t con _UNUSED_PARAMETER_) static inline void context_free (context_t c _UNUSED_PARAMETER_) {} static inline int context_user_set (context_t sc _UNUSED_PARAMETER_, - char const *s _UNUSED_PARAMETER_) + char const *s _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int context_role_set (context_t sc _UNUSED_PARAMETER_, - char const *s _UNUSED_PARAMETER_) + char const *s _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int context_range_set (context_t sc _UNUSED_PARAMETER_, - char const *s _UNUSED_PARAMETER_) + char const *s _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int context_type_set (context_t sc _UNUSED_PARAMETER_, - char const *s _UNUSED_PARAMETER_) + char const *s _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } #endif diff --git a/lib/se-selinux.in.h b/lib/se-selinux.in.h index c09aebd95..3d243aef6 100644 --- a/lib/se-selinux.in.h +++ b/lib/se-selinux.in.h @@ -28,26 +28,26 @@ static inline int getfscreatecon (security_context_t *con _UNUSED_PARAMETER_) static inline int setfscreatecon (security_context_t con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int matchpathcon (char const *file _UNUSED_PARAMETER_, - mode_t m _UNUSED_PARAMETER_, - security_context_t *con _UNUSED_PARAMETER_) + mode_t m _UNUSED_PARAMETER_, + security_context_t *con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int getfilecon (char const *file _UNUSED_PARAMETER_, - security_context_t *con _UNUSED_PARAMETER_) + security_context_t *con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int lgetfilecon (char const *file _UNUSED_PARAMETER_, - security_context_t *con _UNUSED_PARAMETER_) + security_context_t *con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int fgetfilecon (int fd, - security_context_t *con _UNUSED_PARAMETER_) + security_context_t *con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int setfilecon (char const *file _UNUSED_PARAMETER_, - security_context_t con _UNUSED_PARAMETER_) + security_context_t con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int lsetfilecon (char const *file _UNUSED_PARAMETER_, - security_context_t con _UNUSED_PARAMETER_) + security_context_t con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int fsetfilecon (int fd _UNUSED_PARAMETER_, - security_context_t con _UNUSED_PARAMETER_) + security_context_t con _UNUSED_PARAMETER_) { errno = ENOTSUP; return -1; } static inline int security_check_context diff --git a/lib/search.in.h b/lib/search.in.h index 62937c760..aa9e994b4 100644 --- a/lib/search.in.h +++ b/lib/search.in.h @@ -65,18 +65,18 @@ VISIT; If one is found, it is returned. Otherwise, a new element equal to KEY is inserted in the tree and is returned. */ extern void * tsearch (const void *key, void **vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is returned. Otherwise, NULL is returned. */ extern void * tfind (const void *key, void *const *vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)); /* Searches an element in the tree *VROOTP that compares equal to KEY. If one is found, it is removed from the tree, and its parent node is returned. Otherwise, NULL is returned. */ extern void * tdelete (const void *key, void **vrootp, - int (*compar) (const void *, const void *)); + int (*compar) (const void *, const void *)); /* Perform a depth-first, left-to-right traversal of the tree VROOT. The ACTION function is called: @@ -90,7 +90,7 @@ extern void * tdelete (const void *key, void **vrootp, 2. an indicator which visit of the node this is, 3. the level of the node in the tree (0 for the root). */ extern void twalk (const void *vroot, - void (*action) (const void *, VISIT, int)); + void (*action) (const void *, VISIT, int)); # endif #elif defined GNULIB_POSIXCHECK diff --git a/lib/select.c b/lib/select.c index e82bf889f..de4e3b431 100644 --- a/lib/select.c +++ b/lib/select.c @@ -71,10 +71,10 @@ typedef enum _FILE_INFORMATION_CLASS { } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; typedef DWORD (WINAPI *PNtQueryInformationFile) - (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); + (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS); #ifndef PIPE_BUF -#define PIPE_BUF 512 +#define PIPE_BUF 512 #endif #define IsConsoleHandle(h) (((long) (h) & 3) == 3) @@ -98,7 +98,7 @@ IsSocketHandle(HANDLE h) static int win32_poll_handle (HANDLE h, int fd, struct bitset *rbits, struct bitset *wbits, - struct bitset *xbits) + struct bitset *xbits) { BOOL read, write, except; int i, ret; @@ -120,78 +120,78 @@ win32_poll_handle (HANDLE h, int fd, struct bitset *rbits, struct bitset *wbits, case FILE_TYPE_PIPE: if (!once_only) - { - NtQueryInformationFile = (PNtQueryInformationFile) - GetProcAddress (GetModuleHandle ("ntdll.dll"), - "NtQueryInformationFile"); - once_only = TRUE; - } + { + NtQueryInformationFile = (PNtQueryInformationFile) + GetProcAddress (GetModuleHandle ("ntdll.dll"), + "NtQueryInformationFile"); + once_only = TRUE; + } if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0) - { - if (avail) - read = TRUE; - } + { + if (avail) + read = TRUE; + } else - { - /* It was the write-end of the pipe. Check if it is writable. - If NtQueryInformationFile fails, optimistically assume the pipe is - writable. This could happen on Win9x, where NtQueryInformationFile - is not available, or if we inherit a pipe that doesn't permit - FILE_READ_ATTRIBUTES access on the write end (I think this should - not happen since WinXP SP2; WINE seems fine too). Otherwise, - ensure that enough space is available for atomic writes. */ + { + /* It was the write-end of the pipe. Check if it is writable. + If NtQueryInformationFile fails, optimistically assume the pipe is + writable. This could happen on Win9x, where NtQueryInformationFile + is not available, or if we inherit a pipe that doesn't permit + FILE_READ_ATTRIBUTES access on the write end (I think this should + not happen since WinXP SP2; WINE seems fine too). Otherwise, + ensure that enough space is available for atomic writes. */ memset (&iosb, 0, sizeof (iosb)); memset (&fpli, 0, sizeof (fpli)); if (!NtQueryInformationFile || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli), - FilePipeLocalInformation) - || fpli.WriteQuotaAvailable >= PIPE_BUF - || (fpli.OutboundQuota < PIPE_BUF && - fpli.WriteQuotaAvailable == fpli.OutboundQuota)) - write = TRUE; - } + FilePipeLocalInformation) + || fpli.WriteQuotaAvailable >= PIPE_BUF + || (fpli.OutboundQuota < PIPE_BUF && + fpli.WriteQuotaAvailable == fpli.OutboundQuota)) + write = TRUE; + } break; case FILE_TYPE_CHAR: write = TRUE; if (!(rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1))))) - break; + break; ret = WaitForSingleObject (h, 0); if (ret == WAIT_OBJECT_0) { - if (!IsConsoleHandle (h)) - { - read = TRUE; - break; - } - - nbuffer = avail = 0; - bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); - - /* Screen buffers handles are filtered earlier. */ - assert (bRet); - if (nbuffer == 0) - { - except = TRUE; - break; - } - - irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD)); - bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail); - if (!bRet || avail == 0) - { - except = TRUE; - break; - } - - for (i = 0; i < avail; i++) - if (irbuffer[i].EventType == KEY_EVENT) - read = TRUE; - } + if (!IsConsoleHandle (h)) + { + read = TRUE; + break; + } + + nbuffer = avail = 0; + bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); + + /* Screen buffers handles are filtered earlier. */ + assert (bRet); + if (nbuffer == 0) + { + except = TRUE; + break; + } + + irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD)); + bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail); + if (!bRet || avail == 0) + { + except = TRUE; + break; + } + + for (i = 0; i < avail; i++) + if (irbuffer[i].EventType == KEY_EVENT) + read = TRUE; + } break; default: @@ -275,10 +275,10 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, for (i = 0; i < rfds->fd_count; i++) { fd = rfds->fd_array[i]; - h = (HANDLE) _get_osfhandle (fd); - if (IsConsoleHandle (h) - && !GetNumberOfConsoleInputEvents (h, &nbuffer)) - continue; + h = (HANDLE) _get_osfhandle (fd); + if (IsConsoleHandle (h) + && !GetNumberOfConsoleInputEvents (h, &nbuffer)) + continue; rbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); @@ -290,10 +290,10 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, for (i = 0; i < wfds->fd_count; i++) { fd = wfds->fd_array[i]; - h = (HANDLE) _get_osfhandle (fd); - if (IsConsoleHandle (h) - && GetNumberOfConsoleInputEvents (h, &nbuffer)) - continue; + h = (HANDLE) _get_osfhandle (fd); + if (IsConsoleHandle (h) + && GetNumberOfConsoleInputEvents (h, &nbuffer)) + continue; wbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1)); @@ -323,13 +323,13 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, for (i = 0; i < nfds; i++) { if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0) - continue; + continue; h = (HANDLE) _get_osfhandle (i); if (!h) { - errno = EBADF; - return -1; + errno = EBADF; + return -1; } if (IsSocketHandle (h)) @@ -337,37 +337,37 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, int requested = FD_CLOSE; /* See above; socket handles are mapped onto select, but we - need to map descriptors to handles. */ + need to map descriptors to handles. */ if (rbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) - { + { requested |= FD_READ | FD_ACCEPT; - FD_SET ((SOCKET) h, rfds); - FD_SET ((SOCKET) h, &handle_rfds); - } + FD_SET ((SOCKET) h, rfds); + FD_SET ((SOCKET) h, &handle_rfds); + } if (wbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) - { + { requested |= FD_WRITE | FD_CONNECT; - FD_SET ((SOCKET) h, wfds); - FD_SET ((SOCKET) h, &handle_wfds); - } + FD_SET ((SOCKET) h, wfds); + FD_SET ((SOCKET) h, &handle_wfds); + } if (xbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) - { + { requested |= FD_OOB; - FD_SET ((SOCKET) h, xfds); - FD_SET ((SOCKET) h, &handle_xfds); - } + FD_SET ((SOCKET) h, xfds); + FD_SET ((SOCKET) h, &handle_xfds); + } WSAEventSelect ((SOCKET) h, hEvent, requested); - nsock++; + nsock++; } else { handle_array[nhandles++] = h; - /* Poll now. If we get an event, do not wait below. */ + /* Poll now. If we get an event, do not wait below. */ if (wait_timeout != 0 - && win32_poll_handle (h, i, &rbits, &wbits, &xbits)) - wait_timeout = 0; + && win32_poll_handle (h, i, &rbits, &wbits, &xbits)) + wait_timeout = 0; } } @@ -380,12 +380,12 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, no need to call select again. */ rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0); if (rc == 0) - { - /* Restore the fd_sets for the other select we do below. */ + { + /* Restore the fd_sets for the other select we do below. */ memcpy (&handle_rfds, rfds, sizeof (fd_set)); memcpy (&handle_wfds, wfds, sizeof (fd_set)); memcpy (&handle_xfds, xfds, sizeof (fd_set)); - } + } else wait_timeout = 0; } @@ -393,20 +393,20 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, for (;;) { ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE, - wait_timeout, QS_ALLINPUT); + wait_timeout, QS_ALLINPUT); if (ret == WAIT_OBJECT_0 + nhandles) - { + { /* new input of some other kind */ - BOOL bRet; + BOOL bRet; while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0) { TranslateMessage (&msg); DispatchMessage (&msg); } - } + } else - break; + break; } /* If we haven't done it yet, check the status of the sockets. */ @@ -424,13 +424,13 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, for (i = 0; i < nfds; i++) { if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0) - continue; + continue; h = (HANDLE) _get_osfhandle (i); if (h != handle_array[nhandles]) - { - /* Perform handle->descriptor mapping. Don't update rc, as these - results are counted in the return value of Winsock's select. */ + { + /* Perform handle->descriptor mapping. Don't update rc, as these + results are counted in the return value of Winsock's select. */ WSAEventSelect ((SOCKET) h, NULL, 0); if (FD_ISSET (h, &handle_rfds)) FD_SET (i, rfds); @@ -438,7 +438,7 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, FD_SET (i, wfds); if (FD_ISSET (h, &handle_xfds)) FD_SET (i, xfds); - } + } else { /* Not a socket. */ @@ -446,19 +446,19 @@ rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, win32_poll_handle (h, i, &rbits, &wbits, &xbits); if (rbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) { - rc++; - FD_SET (i, rfds); - } + rc++; + FD_SET (i, rfds); + } if (wbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) { - rc++; - FD_SET (i, wfds); - } + rc++; + FD_SET (i, wfds); + } if (xbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) { - rc++; - FD_SET (i, xfds); - } + rc++; + FD_SET (i, xfds); + } } } diff --git a/lib/sendto.c b/lib/sendto.c index 888b0f621..b6cb8b960 100644 --- a/lib/sendto.c +++ b/lib/sendto.c @@ -30,7 +30,7 @@ int rpl_sendto (int fd, const void *buf, int len, int flags, - struct sockaddr *to, int tolen) + struct sockaddr *to, int tolen) { SOCKET sock = FD_TO_SOCKET (fd); int r = sendto (sock, buf, len, flags, to, tolen); diff --git a/lib/set-mode-acl.c b/lib/set-mode-acl.c index ddac4df0e..b444b1272 100644 --- a/lib/set-mode-acl.c +++ b/lib/set-mode-acl.c @@ -79,15 +79,15 @@ qset_acl (char const *name, int desc, mode_t mode) { acl = acl_from_mode (mode); if (!acl) - return -1; + return -1; } else /* FreeBSD, IRIX, Tru64 */ { /* If we were to create the ACL using the functions acl_init(), - acl_create_entry(), acl_set_tag_type(), acl_set_qualifier(), - acl_get_permset(), acl_clear_perm[s](), acl_add_perm(), we - would need to create a qualifier. I don't know how to do this. - So create it using acl_from_text(). */ + acl_create_entry(), acl_set_tag_type(), acl_set_qualifier(), + acl_get_permset(), acl_clear_perm[s](), acl_add_perm(), we + would need to create a qualifier. I don't know how to do this. + So create it using acl_from_text(). */ # if HAVE_ACL_FREE_TEXT /* Tru64 */ char acl_text[] = "u::---,g::---,o::---,"; @@ -107,7 +107,7 @@ qset_acl (char const *name, int desc, mode_t mode) acl = acl_from_text (acl_text); if (!acl) - return -1; + return -1; } if (HAVE_ACL_SET_FD && desc != -1) ret = acl_set_fd (desc, acl); @@ -119,12 +119,12 @@ qset_acl (char const *name, int desc, mode_t mode) acl_free (acl); if (ACL_NOT_WELL_SUPPORTED (errno)) - return chmod_or_fchmod (name, desc, mode); + return chmod_or_fchmod (name, desc, mode); else - { - errno = saved_errno; - return -1; - } + { + errno = saved_errno; + return -1; + } } else acl_free (acl); @@ -135,7 +135,7 @@ qset_acl (char const *name, int desc, mode_t mode) if (mode & (S_ISUID | S_ISGID | S_ISVTX)) { /* We did not call chmod so far, so the special bits have not yet - been set. */ + been set. */ return chmod_or_fchmod (name, desc, mode); } return 0; @@ -150,14 +150,14 @@ qset_acl (char const *name, int desc, mode_t mode) /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS) and acl_get_file (name, ACL_TYPE_DEFAULT) always return NULL / EINVAL. You have to use - acl_get_file (name, ACL_TYPE_EXTENDED) + acl_get_file (name, ACL_TYPE_EXTENDED) or acl_get_fd (open (name, ...)) to retrieve an ACL. On the other hand, - acl_set_file (name, ACL_TYPE_ACCESS, acl) + acl_set_file (name, ACL_TYPE_ACCESS, acl) and acl_set_file (name, ACL_TYPE_DEFAULT, acl) have the same effect as - acl_set_file (name, ACL_TYPE_EXTENDED, acl): + acl_set_file (name, ACL_TYPE_EXTENDED, acl): Each of these calls sets the file's ACL. */ acl_t acl; @@ -174,27 +174,27 @@ qset_acl (char const *name, int desc, mode_t mode) acl = acl_init (0); if (acl) - { - if (HAVE_ACL_SET_FD && desc != -1) - ret = acl_set_fd (desc, acl); - else - ret = acl_set_file (name, ACL_TYPE_EXTENDED, acl); - if (ret != 0) - { - int saved_errno = errno; - - acl_free (acl); - - if (ACL_NOT_WELL_SUPPORTED (saved_errno)) - return chmod_or_fchmod (name, desc, mode); - else - { - errno = saved_errno; - return -1; - } - } - acl_free (acl); - } + { + if (HAVE_ACL_SET_FD && desc != -1) + ret = acl_set_fd (desc, acl); + else + ret = acl_set_file (name, ACL_TYPE_EXTENDED, acl); + if (ret != 0) + { + int saved_errno = errno; + + acl_free (acl); + + if (ACL_NOT_WELL_SUPPORTED (saved_errno)) + return chmod_or_fchmod (name, desc, mode); + else + { + errno = saved_errno; + return -1; + } + } + acl_free (acl); + } } /* Since !MODE_INSIDE_ACL, we have to call chmod explicitly. */ @@ -235,7 +235,7 @@ qset_acl (char const *name, int desc, mode_t mode) if (ret < 0) { if (saved_errno == ENOSYS || saved_errno == EOPNOTSUPP) - return chmod_or_fchmod (name, desc, mode); + return chmod_or_fchmod (name, desc, mode); errno = saved_errno; return -1; } @@ -243,7 +243,7 @@ qset_acl (char const *name, int desc, mode_t mode) if (mode & (S_ISUID | S_ISGID | S_ISVTX)) { /* We did not call chmod so far, so the special bits have not yet - been set. */ + been set. */ return chmod_or_fchmod (name, desc, mode); } return 0; @@ -268,41 +268,41 @@ qset_acl (char const *name, int desc, mode_t mode) for (;;) { - if (desc != -1) - count = facl (desc, ACE_GETACLCNT, 0, NULL); - else - count = acl (name, ACE_GETACLCNT, 0, NULL); - if (count <= 0) - { - convention = -1; - break; - } - entries = (ace_t *) malloc (count * sizeof (ace_t)); - if (entries == NULL) - { - errno = ENOMEM; - return -1; - } - if ((desc != -1 - ? facl (desc, ACE_GETACL, count, entries) - : acl (name, ACE_GETACL, count, entries)) - == count) - { - int i; - - convention = 0; - for (i = 0; i < count; i++) - if (entries[i].a_flags & (ACE_OWNER | ACE_GROUP | ACE_OTHER)) - { - convention = 1; - break; - } - free (entries); - break; - } - /* Huh? The number of ACL entries changed since the last call. - Repeat. */ - free (entries); + if (desc != -1) + count = facl (desc, ACE_GETACLCNT, 0, NULL); + else + count = acl (name, ACE_GETACLCNT, 0, NULL); + if (count <= 0) + { + convention = -1; + break; + } + entries = (ace_t *) malloc (count * sizeof (ace_t)); + if (entries == NULL) + { + errno = ENOMEM; + return -1; + } + if ((desc != -1 + ? facl (desc, ACE_GETACL, count, entries) + : acl (name, ACE_GETACL, count, entries)) + == count) + { + int i; + + convention = 0; + for (i = 0; i < count; i++) + if (entries[i].a_flags & (ACE_OWNER | ACE_GROUP | ACE_OTHER)) + { + convention = 1; + break; + } + free (entries); + break; + } + /* Huh? The number of ACL entries changed since the last call. + Repeat. */ + free (entries); } } @@ -312,58 +312,58 @@ qset_acl (char const *name, int desc, mode_t mode) int ret; if (convention) - { - /* Running on Solaris 10. */ - entries[0].a_type = ALLOW; - entries[0].a_flags = ACE_OWNER; - entries[0].a_who = 0; /* irrelevant */ - entries[0].a_access_mask = (mode >> 6) & 7; - entries[1].a_type = ALLOW; - entries[1].a_flags = ACE_GROUP; - entries[1].a_who = 0; /* irrelevant */ - entries[1].a_access_mask = (mode >> 3) & 7; - entries[2].a_type = ALLOW; - entries[2].a_flags = ACE_OTHER; - entries[2].a_who = 0; - entries[2].a_access_mask = mode & 7; - } + { + /* Running on Solaris 10. */ + entries[0].a_type = ALLOW; + entries[0].a_flags = ACE_OWNER; + entries[0].a_who = 0; /* irrelevant */ + entries[0].a_access_mask = (mode >> 6) & 7; + entries[1].a_type = ALLOW; + entries[1].a_flags = ACE_GROUP; + entries[1].a_who = 0; /* irrelevant */ + entries[1].a_access_mask = (mode >> 3) & 7; + entries[2].a_type = ALLOW; + entries[2].a_flags = ACE_OTHER; + entries[2].a_who = 0; + entries[2].a_access_mask = mode & 7; + } else - { - /* Running on Solaris 10 (newer version) or Solaris 11. */ - entries[0].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - entries[0].a_flags = NEW_ACE_OWNER; - entries[0].a_who = 0; /* irrelevant */ - entries[0].a_access_mask = - (mode & 0400 ? NEW_ACE_READ_DATA : 0) - | (mode & 0200 ? NEW_ACE_WRITE_DATA : 0) - | (mode & 0100 ? NEW_ACE_EXECUTE : 0); - entries[1].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - entries[1].a_flags = NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP; - entries[1].a_who = 0; /* irrelevant */ - entries[1].a_access_mask = - (mode & 0040 ? NEW_ACE_READ_DATA : 0) - | (mode & 0020 ? NEW_ACE_WRITE_DATA : 0) - | (mode & 0010 ? NEW_ACE_EXECUTE : 0); - entries[2].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; - entries[2].a_flags = ACE_EVERYONE; - entries[2].a_who = 0; - entries[2].a_access_mask = - (mode & 0004 ? NEW_ACE_READ_DATA : 0) - | (mode & 0002 ? NEW_ACE_WRITE_DATA : 0) - | (mode & 0001 ? NEW_ACE_EXECUTE : 0); - } + { + /* Running on Solaris 10 (newer version) or Solaris 11. */ + entries[0].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + entries[0].a_flags = NEW_ACE_OWNER; + entries[0].a_who = 0; /* irrelevant */ + entries[0].a_access_mask = + (mode & 0400 ? NEW_ACE_READ_DATA : 0) + | (mode & 0200 ? NEW_ACE_WRITE_DATA : 0) + | (mode & 0100 ? NEW_ACE_EXECUTE : 0); + entries[1].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + entries[1].a_flags = NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP; + entries[1].a_who = 0; /* irrelevant */ + entries[1].a_access_mask = + (mode & 0040 ? NEW_ACE_READ_DATA : 0) + | (mode & 0020 ? NEW_ACE_WRITE_DATA : 0) + | (mode & 0010 ? NEW_ACE_EXECUTE : 0); + entries[2].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE; + entries[2].a_flags = ACE_EVERYONE; + entries[2].a_who = 0; + entries[2].a_access_mask = + (mode & 0004 ? NEW_ACE_READ_DATA : 0) + | (mode & 0002 ? NEW_ACE_WRITE_DATA : 0) + | (mode & 0001 ? NEW_ACE_EXECUTE : 0); + } if (desc != -1) - ret = facl (desc, ACE_SETACL, - sizeof (entries) / sizeof (ace_t), entries); + ret = facl (desc, ACE_SETACL, + sizeof (entries) / sizeof (ace_t), entries); else - ret = acl (name, ACE_SETACL, - sizeof (entries) / sizeof (ace_t), entries); + ret = acl (name, ACE_SETACL, + sizeof (entries) / sizeof (ace_t), entries); if (ret < 0 && errno != EINVAL && errno != ENOTSUP) - { - if (errno == ENOSYS) - return chmod_or_fchmod (name, desc, mode); - return -1; - } + { + if (errno == ENOSYS) + return chmod_or_fchmod (name, desc, mode); + return -1; + } } # endif @@ -387,16 +387,16 @@ qset_acl (char const *name, int desc, mode_t mode) ret = acl (name, SETACL, sizeof (entries) / sizeof (aclent_t), entries); if (ret < 0) { - if (errno == ENOSYS) - return chmod_or_fchmod (name, desc, mode); - return -1; + if (errno == ENOSYS) + return chmod_or_fchmod (name, desc, mode); + return -1; } } if (!MODE_INSIDE_ACL || (mode & (S_ISUID | S_ISGID | S_ISVTX))) { /* We did not call chmod so far, so the special bits have not yet - been set. */ + been set. */ return chmod_or_fchmod (name, desc, mode); } return 0; @@ -433,14 +433,14 @@ qset_acl (char const *name, int desc, mode_t mode) if (ret < 0) { if (errno == ENOSYS || errno == EOPNOTSUPP) - return chmod_or_fchmod (name, desc, mode); + return chmod_or_fchmod (name, desc, mode); return -1; } if (mode & (S_ISUID | S_ISGID | S_ISVTX)) { /* We did not call chmod so far, so the special bits have not yet - been set. */ + been set. */ return chmod_or_fchmod (name, desc, mode); } return 0; @@ -470,13 +470,13 @@ qset_acl (char const *name, int desc, mode_t mode) u.a.o_access = mode & 7; if (desc != -1) - ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, - type, &u.a, u.a.acl_len, mode); + ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, + type, &u.a, u.a.acl_len, mode); else - ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS, - type, &u.a, u.a.acl_len, mode); + ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS, + type, &u.a, u.a.acl_len, mode); if (!(ret < 0 && errno == ENOSYS)) - return ret; + return ret; } else if (type.u64 == ACL_NFS4) { @@ -488,66 +488,66 @@ qset_acl (char const *name, int desc, mode_t mode) u.a.aclEntryN = 0; ace = &u.a.aclEntry[0]; { - ace->flags = ACE4_ID_SPECIAL; - ace->aceWho.special_whoid = ACE4_WHO_OWNER; - ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; - ace->aceFlags = 0; - ace->aceMask = - (mode & 0400 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) - | (mode & 0200 - ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA - | ACE4_ADD_SUBDIRECTORY - : 0) - | (mode & 0100 ? ACE4_EXECUTE : 0); - ace->aceWhoString[0] = '\0'; - ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; - ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; - u.a.aclEntryN++; + ace->flags = ACE4_ID_SPECIAL; + ace->aceWho.special_whoid = ACE4_WHO_OWNER; + ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; + ace->aceFlags = 0; + ace->aceMask = + (mode & 0400 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) + | (mode & 0200 + ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA + | ACE4_ADD_SUBDIRECTORY + : 0) + | (mode & 0100 ? ACE4_EXECUTE : 0); + ace->aceWhoString[0] = '\0'; + ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; + ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; + u.a.aclEntryN++; } { - ace->flags = ACE4_ID_SPECIAL; - ace->aceWho.special_whoid = ACE4_WHO_GROUP; - ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; - ace->aceFlags = 0; - ace->aceMask = - (mode & 0040 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) - | (mode & 0020 - ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA - | ACE4_ADD_SUBDIRECTORY - : 0) - | (mode & 0010 ? ACE4_EXECUTE : 0); - ace->aceWhoString[0] = '\0'; - ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; - ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; - u.a.aclEntryN++; + ace->flags = ACE4_ID_SPECIAL; + ace->aceWho.special_whoid = ACE4_WHO_GROUP; + ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; + ace->aceFlags = 0; + ace->aceMask = + (mode & 0040 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) + | (mode & 0020 + ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA + | ACE4_ADD_SUBDIRECTORY + : 0) + | (mode & 0010 ? ACE4_EXECUTE : 0); + ace->aceWhoString[0] = '\0'; + ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; + ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; + u.a.aclEntryN++; } { - ace->flags = ACE4_ID_SPECIAL; - ace->aceWho.special_whoid = ACE4_WHO_EVERYONE; - ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; - ace->aceFlags = 0; - ace->aceMask = - (mode & 0004 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) - | (mode & 0002 - ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA - | ACE4_ADD_SUBDIRECTORY - : 0) - | (mode & 0001 ? ACE4_EXECUTE : 0); - ace->aceWhoString[0] = '\0'; - ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; - ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; - u.a.aclEntryN++; + ace->flags = ACE4_ID_SPECIAL; + ace->aceWho.special_whoid = ACE4_WHO_EVERYONE; + ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE; + ace->aceFlags = 0; + ace->aceMask = + (mode & 0004 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0) + | (mode & 0002 + ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA + | ACE4_ADD_SUBDIRECTORY + : 0) + | (mode & 0001 ? ACE4_EXECUTE : 0); + ace->aceWhoString[0] = '\0'; + ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace; + ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4]; + u.a.aclEntryN++; } u.a.aclLength = (char *) ace - (char *) &u.a; if (desc != -1) - ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, - type, &u.a, u.a.aclLength, mode); + ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, + type, &u.a, u.a.aclLength, mode); else - ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS, - type, &u.a, u.a.aclLength, mode); + ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS, + type, &u.a, u.a.aclLength, mode); if (!(ret < 0 && errno == ENOSYS)) - return ret; + return ret; } return chmod_or_fchmod (name, desc, mode); diff --git a/lib/setenv.c b/lib/setenv.c index 0df5b21b9..5ad22c5c1 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -39,15 +39,15 @@ #if _LIBC || !HAVE_SETENV #if !_LIBC -# define __environ environ +# define __environ environ #endif #if _LIBC /* This lock protects against simultaneous modifications of `environ'. */ # include __libc_lock_define_initialized (static, envlock) -# define LOCK __libc_lock_lock (envlock) -# define UNLOCK __libc_lock_unlock (envlock) +# define LOCK __libc_lock_lock (envlock) +# define UNLOCK __libc_lock_unlock (envlock) #else # define LOCK # define UNLOCK @@ -66,8 +66,8 @@ __libc_lock_define_initialized (static, envlock) values are from a small set. Outside glibc this will eat up all memory after a while. */ #if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \ - && defined __GNUC__) -# define USE_TSEARCH 1 + && defined __GNUC__) +# define USE_TSEARCH 1 # include typedef int (*compar_fn_t) (const void *, const void *); @@ -76,9 +76,9 @@ typedef int (*compar_fn_t) (const void *, const void *); static void *known_values; # define KNOWN_VALUE(Str) \ - ({ \ - void *value = tfind (Str, &known_values, (compar_fn_t) strcmp); \ - value != NULL ? *(char **) value : NULL; \ + ({ \ + void *value = tfind (Str, &known_values, (compar_fn_t) strcmp); \ + value != NULL ? *(char **) value : NULL; \ }) # define STORE_VALUE(Str) \ tsearch (Str, &known_values, (compar_fn_t) strcmp) @@ -105,7 +105,7 @@ static char **last_environ; free the strings. */ int __add_to_environ (const char *name, const char *value, const char *combined, - int replace) + int replace) { register char **ep; register size_t size; @@ -122,10 +122,10 @@ __add_to_environ (const char *name, const char *value, const char *combined, if (ep != NULL) { for (; *ep != NULL; ++ep) - if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=') - break; - else - ++size; + if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=') + break; + else + ++size; } if (ep == NULL || *ep == NULL) @@ -137,76 +137,76 @@ __add_to_environ (const char *name, const char *value, const char *combined, /* We allocated this space; we can extend it. */ new_environ = - (char **) (last_environ == NULL - ? malloc ((size + 2) * sizeof (char *)) - : realloc (last_environ, (size + 2) * sizeof (char *))); + (char **) (last_environ == NULL + ? malloc ((size + 2) * sizeof (char *)) + : realloc (last_environ, (size + 2) * sizeof (char *))); if (new_environ == NULL) - { - UNLOCK; - return -1; - } + { + UNLOCK; + return -1; + } /* If the whole entry is given add it. */ if (combined != NULL) - /* We must not add the string to the search tree since it belongs - to the user. */ - new_environ[size] = (char *) combined; + /* We must not add the string to the search tree since it belongs + to the user. */ + new_environ[size] = (char *) combined; else - { - /* See whether the value is already known. */ + { + /* See whether the value is already known. */ #ifdef USE_TSEARCH # ifdef _LIBC - new_value = (char *) alloca (namelen + 1 + vallen); - __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), - value, vallen); + new_value = (char *) alloca (namelen + 1 + vallen); + __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), + value, vallen); # else - new_value = (char *) malloca (namelen + 1 + vallen); - if (new_value == NULL) - { - __set_errno (ENOMEM); - UNLOCK; - return -1; - } - memcpy (new_value, name, namelen); - new_value[namelen] = '='; - memcpy (&new_value[namelen + 1], value, vallen); + new_value = (char *) malloca (namelen + 1 + vallen); + if (new_value == NULL) + { + __set_errno (ENOMEM); + UNLOCK; + return -1; + } + memcpy (new_value, name, namelen); + new_value[namelen] = '='; + memcpy (&new_value[namelen + 1], value, vallen); # endif - new_environ[size] = KNOWN_VALUE (new_value); - if (new_environ[size] == NULL) + new_environ[size] = KNOWN_VALUE (new_value); + if (new_environ[size] == NULL) #endif - { - new_environ[size] = (char *) malloc (namelen + 1 + vallen); - if (new_environ[size] == NULL) - { + { + new_environ[size] = (char *) malloc (namelen + 1 + vallen); + if (new_environ[size] == NULL) + { #if defined USE_TSEARCH && !defined _LIBC - freea (new_value); + freea (new_value); #endif - __set_errno (ENOMEM); - UNLOCK; - return -1; - } + __set_errno (ENOMEM); + UNLOCK; + return -1; + } #ifdef USE_TSEARCH - memcpy (new_environ[size], new_value, namelen + 1 + vallen); + memcpy (new_environ[size], new_value, namelen + 1 + vallen); #else - memcpy (new_environ[size], name, namelen); - new_environ[size][namelen] = '='; - memcpy (&new_environ[size][namelen + 1], value, vallen); + memcpy (new_environ[size], name, namelen); + new_environ[size][namelen] = '='; + memcpy (&new_environ[size][namelen + 1], value, vallen); #endif - /* And save the value now. We cannot do this when we remove - the string since then we cannot decide whether it is a - user string or not. */ - STORE_VALUE (new_environ[size]); - } + /* And save the value now. We cannot do this when we remove + the string since then we cannot decide whether it is a + user string or not. */ + STORE_VALUE (new_environ[size]); + } #if defined USE_TSEARCH && !defined _LIBC - freea (new_value); + freea (new_value); #endif - } + } if (__environ != last_environ) - memcpy ((char *) new_environ, (char *) __environ, - size * sizeof (char *)); + memcpy ((char *) new_environ, (char *) __environ, + size * sizeof (char *)); new_environ[size + 1] = NULL; @@ -218,57 +218,57 @@ __add_to_environ (const char *name, const char *value, const char *combined, /* Use the user string if given. */ if (combined != NULL) - np = (char *) combined; + np = (char *) combined; else - { + { #ifdef USE_TSEARCH - char *new_value; + char *new_value; # ifdef _LIBC - new_value = alloca (namelen + 1 + vallen); - __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), - value, vallen); + new_value = alloca (namelen + 1 + vallen); + __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), + value, vallen); # else - new_value = malloca (namelen + 1 + vallen); - if (new_value == NULL) - { - __set_errno (ENOMEM); - UNLOCK; - return -1; - } - memcpy (new_value, name, namelen); - new_value[namelen] = '='; - memcpy (&new_value[namelen + 1], value, vallen); + new_value = malloca (namelen + 1 + vallen); + if (new_value == NULL) + { + __set_errno (ENOMEM); + UNLOCK; + return -1; + } + memcpy (new_value, name, namelen); + new_value[namelen] = '='; + memcpy (&new_value[namelen + 1], value, vallen); # endif - np = KNOWN_VALUE (new_value); - if (np == NULL) + np = KNOWN_VALUE (new_value); + if (np == NULL) #endif - { - np = malloc (namelen + 1 + vallen); - if (np == NULL) - { + { + np = malloc (namelen + 1 + vallen); + if (np == NULL) + { #if defined USE_TSEARCH && !defined _LIBC - freea (new_value); + freea (new_value); #endif - __set_errno (ENOMEM); - UNLOCK; - return -1; - } + __set_errno (ENOMEM); + UNLOCK; + return -1; + } #ifdef USE_TSEARCH - memcpy (np, new_value, namelen + 1 + vallen); + memcpy (np, new_value, namelen + 1 + vallen); #else - memcpy (np, name, namelen); - np[namelen] = '='; - memcpy (&np[namelen + 1], value, vallen); + memcpy (np, name, namelen); + np[namelen] = '='; + memcpy (&np[namelen + 1], value, vallen); #endif - /* And remember the value. */ - STORE_VALUE (np); - } + /* And remember the value. */ + STORE_VALUE (np); + } #if defined USE_TSEARCH && !defined _LIBC - freea (new_value); + freea (new_value); #endif - } + } *ep = np; } diff --git a/lib/sh-quote.c b/lib/sh-quote.c index e349f403e..f59e55fbf 100644 --- a/lib/sh-quote.c +++ b/lib/sh-quote.c @@ -43,7 +43,7 @@ shell_quote_length (const char *string) if (sh_quoting_options == NULL) init_sh_quoting_options (); return quotearg_buffer (NULL, 0, string, strlen (string), - sh_quoting_options); + sh_quoting_options); } /* Copies the quoted string to p and returns the incremented p. @@ -54,7 +54,7 @@ shell_quote_copy (char *p, const char *string) if (sh_quoting_options == NULL) init_sh_quoting_options (); return p + quotearg_buffer (p, (size_t)(-1), string, strlen (string), - sh_quoting_options); + sh_quoting_options); } /* Returns the freshly allocated quoted string. */ @@ -80,24 +80,24 @@ shell_quote_argv (char **argv) length = 0; for (argp = argv; ; ) - { - length += shell_quote_length (*argp) + 1; - argp++; - if (*argp == NULL) - break; - } + { + length += shell_quote_length (*argp) + 1; + argp++; + if (*argp == NULL) + break; + } command = XNMALLOC (length, char); p = command; for (argp = argv; ; ) - { - p = shell_quote_copy (p, *argp); - argp++; - if (*argp == NULL) - break; - *p++ = ' '; - } + { + p = shell_quote_copy (p, *argp); + argp++; + if (*argp == NULL) + break; + *p++ = ' '; + } *p = '\0'; return command; diff --git a/lib/sha1.c b/lib/sha1.c index e72c94d9f..d4c75f914 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -138,43 +138,43 @@ sha1_stream (FILE *stream, void *resblock) while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ + computation function processes the whole buffer so that with the + next round of the loop another block can be read. */ size_t n; sum = 0; /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 64 == 0 + BLOCKSIZE % 64 == 0 */ sha1_process_block (buffer, BLOCKSIZE, &ctx); } @@ -224,15 +224,15 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) ctx->buflen += add; if (ctx->buflen > 64) - { - sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx); + { + sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx); - ctx->buflen &= 63; - /* The regions in the following copy operation cannot overlap. */ - memcpy (ctx->buffer, - &((char *) ctx->buffer)[(left_over + add) & ~63], - ctx->buflen); - } + ctx->buflen &= 63; + /* The regions in the following copy operation cannot overlap. */ + memcpy (ctx->buffer, + &((char *) ctx->buffer)[(left_over + add) & ~63], + ctx->buflen); + } buffer = (const char *) buffer + add; len -= add; @@ -245,19 +245,19 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) # define alignof(type) offsetof (struct { char c; type x; }, x) # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) - while (len > 64) - { - sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *) buffer + 64; - len -= 64; - } + while (len > 64) + { + sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); + buffer = (const char *) buffer + 64; + len -= 64; + } else #endif - { - sha1_process_block (buffer, len & ~63, ctx); - buffer = (const char *) buffer + (len & ~63); - len &= 63; - } + { + sha1_process_block (buffer, len & ~63, ctx); + buffer = (const char *) buffer + (len & ~63); + len &= 63; + } } /* Move remaining bytes in internal buffer. */ @@ -268,11 +268,11 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) memcpy (&((char *) ctx->buffer)[left_over], buffer, len); left_over += len; if (left_over >= 64) - { - sha1_process_block (ctx->buffer, 64, ctx); - left_over -= 64; - memcpy (ctx->buffer, &ctx->buffer[16], left_over); - } + { + sha1_process_block (ctx->buffer, 64, ctx); + left_over -= 64; + memcpy (ctx->buffer, &ctx->buffer[16], left_over); + } ctx->buflen = left_over; } } @@ -318,25 +318,25 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx) #define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n)))) #define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \ - ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \ - , (x[I&0x0f] = rol(tm, 1)) ) + ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \ + , (x[I&0x0f] = rol(tm, 1)) ) #define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \ - + F( B, C, D ) \ - + K \ - + M; \ - B = rol( B, 30 ); \ - } while(0) + + F( B, C, D ) \ + + K \ + + M; \ + B = rol( B, 30 ); \ + } while(0) while (words < endp) { uint32_t tm; int t; for (t = 0; t < 16; t++) - { - x[t] = SWAP (*words); - words++; - } + { + x[t] = SWAP (*words); + words++; + } R( a, b, c, d, e, F1, K1, x[ 0] ); R( e, a, b, c, d, F1, K1, x[ 1] ); diff --git a/lib/sha1.h b/lib/sha1.h index 2beaa66c5..09c57a74e 100644 --- a/lib/sha1.h +++ b/lib/sha1.h @@ -52,14 +52,14 @@ extern void sha1_init_ctx (struct sha1_ctx *ctx); starting at BUFFER. It is necessary that LEN is a multiple of 64!!! */ extern void sha1_process_block (const void *buffer, size_t len, - struct sha1_ctx *ctx); + struct sha1_ctx *ctx); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes starting at BUFFER. It is NOT required that LEN is a multiple of 64. */ extern void sha1_process_bytes (const void *buffer, size_t len, - struct sha1_ctx *ctx); + struct sha1_ctx *ctx); /* Process the remaining bytes in the buffer and put result from CTX in first 20 bytes following RESBUF. The result is always in little diff --git a/lib/sha256.c b/lib/sha256.c index 4bc8ac378..2d3b78e37 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -139,9 +139,9 @@ sha256_conclude_ctx (struct sha256_ctx *ctx) Use set_uint32 rather than a simple assignment, to avoid risk of unaligned access. */ set_uint32 ((char *) &ctx->buffer[size - 2], - SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29))); + SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29))); set_uint32 ((char *) &ctx->buffer[size - 1], - SWAP (ctx->total[0] << 3)); + SWAP (ctx->total[0] << 3)); memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes); @@ -183,43 +183,43 @@ sha256_stream (FILE *stream, void *resblock) while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ + computation function processes the whole buffer so that with the + next round of the loop another block can be read. */ size_t n; sum = 0; /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 64 == 0 + BLOCKSIZE % 64 == 0 */ sha256_process_block (buffer, BLOCKSIZE, &ctx); } @@ -254,43 +254,43 @@ sha224_stream (FILE *stream, void *resblock) while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ + computation function processes the whole buffer so that with the + next round of the loop another block can be read. */ size_t n; sum = 0; /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 64 == 0 + BLOCKSIZE % 64 == 0 */ sha256_process_block (buffer, BLOCKSIZE, &ctx); } @@ -355,15 +355,15 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) ctx->buflen += add; if (ctx->buflen > 64) - { - sha256_process_block (ctx->buffer, ctx->buflen & ~63, ctx); + { + sha256_process_block (ctx->buffer, ctx->buflen & ~63, ctx); - ctx->buflen &= 63; - /* The regions in the following copy operation cannot overlap. */ - memcpy (ctx->buffer, - &((char *) ctx->buffer)[(left_over + add) & ~63], - ctx->buflen); - } + ctx->buflen &= 63; + /* The regions in the following copy operation cannot overlap. */ + memcpy (ctx->buffer, + &((char *) ctx->buffer)[(left_over + add) & ~63], + ctx->buflen); + } buffer = (const char *) buffer + add; len -= add; @@ -376,19 +376,19 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) # define alignof(type) offsetof (struct { char c; type x; }, x) # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) if (UNALIGNED_P (buffer)) - while (len > 64) - { - sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); - buffer = (const char *) buffer + 64; - len -= 64; - } + while (len > 64) + { + sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); + buffer = (const char *) buffer + 64; + len -= 64; + } else #endif - { - sha256_process_block (buffer, len & ~63, ctx); - buffer = (const char *) buffer + (len & ~63); - len &= 63; - } + { + sha256_process_block (buffer, len & ~63, ctx); + buffer = (const char *) buffer + (len & ~63); + len &= 63; + } } /* Move remaining bytes in internal buffer. */ @@ -399,11 +399,11 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) memcpy (&((char *) ctx->buffer)[left_over], buffer, len); left_over += len; if (left_over >= 64) - { - sha256_process_block (ctx->buffer, 64, ctx); - left_over -= 64; - memcpy (ctx->buffer, &ctx->buffer[16], left_over); - } + { + sha256_process_block (ctx->buffer, 64, ctx); + left_over -= 64; + memcpy (ctx->buffer, &ctx->buffer[16], left_over); + } ctx->buflen = left_over; } } @@ -469,16 +469,16 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) #define SS1(x) (rol(x,26)^rol(x,21)^rol(x,7)) #define M(I) ( tm = S1(x[(I-2)&0x0f]) + x[(I-7)&0x0f] \ - + S0(x[(I-15)&0x0f]) + x[I&0x0f] \ - , x[I&0x0f] = tm ) + + S0(x[(I-15)&0x0f]) + x[I&0x0f] \ + , x[I&0x0f] = tm ) #define R(A,B,C,D,E,F,G,H,K,M) do { t0 = SS0(A) + F2(A,B,C); \ t1 = H + SS1(E) \ + F1(E,F,G) \ - + K \ - + M; \ - D += t1; H = t0 + t1; \ - } while(0) + + K \ + + M; \ + D += t1; H = t0 + t1; \ + } while(0) while (words < endp) { @@ -487,10 +487,10 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) int t; /* FIXME: see sha1.c for a better implementation. */ for (t = 0; t < 16; t++) - { - x[t] = SWAP (*words); - words++; - } + { + x[t] = SWAP (*words); + words++; + } R( a, b, c, d, e, f, g, h, K( 0), x[ 0] ); R( h, a, b, c, d, e, f, g, K( 1), x[ 1] ); diff --git a/lib/sha256.h b/lib/sha256.h index 6a9aed41a..3c26fbfd4 100644 --- a/lib/sha256.h +++ b/lib/sha256.h @@ -47,14 +47,14 @@ extern void sha224_init_ctx (struct sha256_ctx *ctx); starting at BUFFER. It is necessary that LEN is a multiple of 64!!! */ extern void sha256_process_block (const void *buffer, size_t len, - struct sha256_ctx *ctx); + struct sha256_ctx *ctx); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes starting at BUFFER. It is NOT required that LEN is a multiple of 64. */ extern void sha256_process_bytes (const void *buffer, size_t len, - struct sha256_ctx *ctx); + struct sha256_ctx *ctx); /* Process the remaining bytes in the buffer and put result from CTX in first 32 (28) bytes following RESBUF. The result is always in little diff --git a/lib/sha512.c b/lib/sha512.c index becafaee8..ade9156d2 100644 --- a/lib/sha512.c +++ b/lib/sha512.c @@ -36,14 +36,14 @@ # define SWAP(n) (n) #else # define SWAP(n) \ - u64or (u64or (u64or (u64shl (n, 56), \ - u64shl (u64and (n, u64lo (0x0000ff00)), 40)), \ - u64or (u64shl (u64and (n, u64lo (0x00ff0000)), 24), \ - u64shl (u64and (n, u64lo (0xff000000)), 8))), \ - u64or (u64or (u64and (u64shr (n, 8), u64lo (0xff000000)), \ - u64and (u64shr (n, 24), u64lo (0x00ff0000))), \ - u64or (u64and (u64shr (n, 40), u64lo (0x0000ff00)), \ - u64shr (n, 56)))) + u64or (u64or (u64or (u64shl (n, 56), \ + u64shl (u64and (n, u64lo (0x0000ff00)), 40)), \ + u64or (u64shl (u64and (n, u64lo (0x00ff0000)), 24), \ + u64shl (u64and (n, u64lo (0xff000000)), 8))), \ + u64or (u64or (u64and (u64shr (n, 8), u64lo (0xff000000)), \ + u64and (u64shr (n, 24), u64lo (0x00ff0000))), \ + u64or (u64and (u64shr (n, 40), u64lo (0x0000ff00)), \ + u64shr (n, 56)))) #endif #define BLOCKSIZE 32768 @@ -146,10 +146,10 @@ sha512_conclude_ctx (struct sha512_ctx *ctx) Use set_uint64 rather than a simple assignment, to avoid risk of unaligned access. */ set_uint64 ((char *) &ctx->buffer[size - 2], - SWAP (u64or (u64shl (ctx->total[1], 3), - u64shr (ctx->total[0], 61)))); + SWAP (u64or (u64shl (ctx->total[1], 3), + u64shr (ctx->total[0], 61)))); set_uint64 ((char *) &ctx->buffer[size - 1], - SWAP (u64shl (ctx->total[0], 3))); + SWAP (u64shl (ctx->total[0], 3))); memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 8 - bytes); @@ -191,43 +191,43 @@ sha512_stream (FILE *stream, void *resblock) while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ + computation function processes the whole buffer so that with the + next round of the loop another block can be read. */ size_t n; sum = 0; /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 128 == 0 + BLOCKSIZE % 128 == 0 */ sha512_process_block (buffer, BLOCKSIZE, &ctx); } @@ -262,43 +262,43 @@ sha384_stream (FILE *stream, void *resblock) while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ + computation function processes the whole buffer so that with the + next round of the loop another block can be read. */ size_t n; sum = 0; /* Read block. Take care for partial reads. */ while (1) - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - - sum += n; - - if (sum == BLOCKSIZE) - break; - - if (n == 0) - { - /* Check for the error flag IFF N == 0, so that we don't - exit the loop after a partial read due to e.g., EAGAIN - or EWOULDBLOCK. */ - if (ferror (stream)) - { - free (buffer); - return 1; - } - goto process_partial_block; - } - - /* We've read at least one byte, so ignore errors. But always - check for EOF, since feof may be true even though N > 0. - Otherwise, we could end up calling fread after EOF. */ - if (feof (stream)) - goto process_partial_block; - } + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + + if (sum == BLOCKSIZE) + break; + + if (n == 0) + { + /* Check for the error flag IFF N == 0, so that we don't + exit the loop after a partial read due to e.g., EAGAIN + or EWOULDBLOCK. */ + if (ferror (stream)) + { + free (buffer); + return 1; + } + goto process_partial_block; + } + + /* We've read at least one byte, so ignore errors. But always + check for EOF, since feof may be true even though N > 0. + Otherwise, we could end up calling fread after EOF. */ + if (feof (stream)) + goto process_partial_block; + } /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 128 == 0 + BLOCKSIZE % 128 == 0 */ sha512_process_block (buffer, BLOCKSIZE, &ctx); } @@ -363,15 +363,15 @@ sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) ctx->buflen += add; if (ctx->buflen > 128) - { - sha512_process_block (ctx->buffer, ctx->buflen & ~127, ctx); + { + sha512_process_block (ctx->buffer, ctx->buflen & ~127, ctx); - ctx->buflen &= 127; - /* The regions in the following copy operation cannot overlap. */ - memcpy (ctx->buffer, - &((char *) ctx->buffer)[(left_over + add) & ~127], - ctx->buflen); - } + ctx->buflen &= 127; + /* The regions in the following copy operation cannot overlap. */ + memcpy (ctx->buffer, + &((char *) ctx->buffer)[(left_over + add) & ~127], + ctx->buflen); + } buffer = (const char *) buffer + add; len -= add; @@ -384,19 +384,19 @@ sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) # define alignof(type) offsetof (struct { char c; type x; }, x) # define UNALIGNED_P(p) (((size_t) p) % alignof (u64) != 0) if (UNALIGNED_P (buffer)) - while (len > 128) - { - sha512_process_block (memcpy (ctx->buffer, buffer, 128), 128, ctx); - buffer = (const char *) buffer + 128; - len -= 128; - } + while (len > 128) + { + sha512_process_block (memcpy (ctx->buffer, buffer, 128), 128, ctx); + buffer = (const char *) buffer + 128; + len -= 128; + } else #endif - { - sha512_process_block (buffer, len & ~127, ctx); - buffer = (const char *) buffer + (len & ~127); - len &= 127; - } + { + sha512_process_block (buffer, len & ~127, ctx); + buffer = (const char *) buffer + (len & ~127); + len &= 127; + } } /* Move remaining bytes in internal buffer. */ @@ -407,11 +407,11 @@ sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) memcpy (&((char *) ctx->buffer)[left_over], buffer, len); left_over += len; if (left_over >= 128) - { - sha512_process_block (ctx->buffer, 128, ctx); - left_over -= 128; - memcpy (ctx->buffer, &ctx->buffer[16], left_over); - } + { + sha512_process_block (ctx->buffer, 128, ctx); + left_over -= 128; + memcpy (ctx->buffer, &ctx->buffer[16], left_over); + } ctx->buflen = left_over; } } @@ -498,22 +498,22 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) #define SS0(x) u64xor (u64rol (x, 36), u64xor (u64rol (x, 30), u64rol (x, 25))) #define SS1(x) u64xor (u64rol(x, 50), u64xor (u64rol (x, 46), u64rol (x, 23))) -#define M(I) (x[(I) & 15] \ - = u64plus (x[(I) & 15], \ - u64plus (S1 (x[((I) - 2) & 15]), \ - u64plus (x[((I) - 7) & 15], \ - S0 (x[((I) - 15) & 15]))))) - -#define R(A, B, C, D, E, F, G, H, K, M) \ - do \ - { \ - u64 t0 = u64plus (SS0 (A), F2 (A, B, C)); \ - u64 t1 = \ - u64plus (H, u64plus (SS1 (E), \ - u64plus (F1 (E, F, G), u64plus (K, M)))); \ - D = u64plus (D, t1); \ - H = u64plus (t0, t1); \ - } \ +#define M(I) (x[(I) & 15] \ + = u64plus (x[(I) & 15], \ + u64plus (S1 (x[((I) - 2) & 15]), \ + u64plus (x[((I) - 7) & 15], \ + S0 (x[((I) - 15) & 15]))))) + +#define R(A, B, C, D, E, F, G, H, K, M) \ + do \ + { \ + u64 t0 = u64plus (SS0 (A), F2 (A, B, C)); \ + u64 t1 = \ + u64plus (H, u64plus (SS1 (E), \ + u64plus (F1 (E, F, G), u64plus (K, M)))); \ + D = u64plus (D, t1); \ + H = u64plus (t0, t1); \ + } \ while (0) while (words < endp) @@ -521,10 +521,10 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) int t; /* FIXME: see sha1.c for a better implementation. */ for (t = 0; t < 16; t++) - { - x[t] = SWAP (*words); - words++; - } + { + x[t] = SWAP (*words); + words++; + } R( a, b, c, d, e, f, g, h, K( 0), x[ 0] ); R( h, a, b, c, d, e, f, g, K( 1), x[ 1] ); diff --git a/lib/sha512.h b/lib/sha512.h index 11ac2706f..1f031d4b3 100644 --- a/lib/sha512.h +++ b/lib/sha512.h @@ -48,14 +48,14 @@ extern void sha384_init_ctx (struct sha512_ctx *ctx); starting at BUFFER. It is necessary that LEN is a multiple of 128!!! */ extern void sha512_process_block (const void *buffer, size_t len, - struct sha512_ctx *ctx); + struct sha512_ctx *ctx); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes starting at BUFFER. It is NOT required that LEN is a multiple of 128. */ extern void sha512_process_bytes (const void *buffer, size_t len, - struct sha512_ctx *ctx); + struct sha512_ctx *ctx); /* Process the remaining bytes in the buffer and put result from CTX in first 64 (48) bytes following RESBUF. The result is always in little diff --git a/lib/sig2str.c b/lib/sig2str.c index 9252b2866..0c979d652 100644 --- a/lib/sig2str.c +++ b/lib/sig2str.c @@ -131,7 +131,7 @@ static struct numname { int num; char const name[8]; } numname_table[] = /* Unix Version 7. */ #ifdef SIGIOT - NUMNAME (IOT), /* Older name for ABRT. */ + NUMNAME (IOT), /* Older name for ABRT. */ #endif #ifdef SIGEMT NUMNAME (EMT), @@ -215,16 +215,16 @@ static struct numname { int num; char const name[8]; } numname_table[] = /* Older AIX versions. */ #ifdef SIGALRM1 - NUMNAME (ALRM1), /* unknown; taken from Bash 2.05 */ + NUMNAME (ALRM1), /* unknown; taken from Bash 2.05 */ #endif #ifdef SIGKAP - NUMNAME (KAP), /* Older name for SIGGRANT. */ + NUMNAME (KAP), /* Older name for SIGGRANT. */ #endif #ifdef SIGVIRT - NUMNAME (VIRT), /* unknown; taken from Bash 2.05 */ + NUMNAME (VIRT), /* unknown; taken from Bash 2.05 */ #endif #ifdef SIGWINDOW - NUMNAME (WINDOW), /* Older name for SIGWINCH. */ + NUMNAME (WINDOW), /* Older name for SIGWINCH. */ #endif /* BeOS */ @@ -263,32 +263,32 @@ str2signum (char const *signame) char *endp; long int n = strtol (signame, &endp, 10); if (! *endp && n <= SIGNUM_BOUND) - return n; + return n; } else { unsigned int i; for (i = 0; i < NUMNAME_ENTRIES; i++) - if (strcmp (numname_table[i].name, signame) == 0) - return numname_table[i].num; + if (strcmp (numname_table[i].name, signame) == 0) + return numname_table[i].num; { - char *endp; - int rtmin = SIGRTMIN; - int rtmax = SIGRTMAX; - - if (0 < rtmin && strncmp (signame, "RTMIN", 5) == 0) - { - long int n = strtol (signame + 5, &endp, 10); - if (! *endp && 0 <= n && n <= rtmax - rtmin) - return rtmin + n; - } - else if (0 < rtmax && strncmp (signame, "RTMAX", 5) == 0) - { - long int n = strtol (signame + 5, &endp, 10); - if (! *endp && rtmin - rtmax <= n && n <= 0) - return rtmax + n; - } + char *endp; + int rtmin = SIGRTMIN; + int rtmax = SIGRTMAX; + + if (0 < rtmin && strncmp (signame, "RTMIN", 5) == 0) + { + long int n = strtol (signame + 5, &endp, 10); + if (! *endp && 0 <= n && n <= rtmax - rtmin) + return rtmin + n; + } + else if (0 < rtmax && strncmp (signame, "RTMAX", 5) == 0) + { + long int n = strtol (signame + 5, &endp, 10); + if (! *endp && rtmin - rtmax <= n && n <= 0) + return rtmax + n; + } } } @@ -316,8 +316,8 @@ sig2str (int signum, char *signame) for (i = 0; i < NUMNAME_ENTRIES; i++) if (numname_table[i].num == signum) { - strcpy (signame, numname_table[i].name); - return 0; + strcpy (signame, numname_table[i].name); + return 0; } { @@ -329,13 +329,13 @@ sig2str (int signum, char *signame) if (signum <= rtmin + (rtmax - rtmin) / 2) { - int delta = signum - rtmin; - sprintf (signame, delta ? "RTMIN+%d" : "RTMIN", delta); + int delta = signum - rtmin; + sprintf (signame, delta ? "RTMIN+%d" : "RTMIN", delta); } else { - int delta = rtmax - signum; - sprintf (signame, delta ? "RTMAX-%d" : "RTMAX", delta); + int delta = rtmax - signum; + sprintf (signame, delta ? "RTMAX-%d" : "RTMAX", delta); } return 0; diff --git a/lib/sigaction.c b/lib/sigaction.c index 5fcd3ed9a..c05459edb 100644 --- a/lib/sigaction.c +++ b/lib/sigaction.c @@ -91,7 +91,7 @@ sigaction_handler (int sig) { /* Unexpected situation; be careful to avoid recursive abort. */ if (sig == SIGABRT) - signal (SIGABRT, SIG_DFL); + signal (SIGABRT, SIG_DFL); abort (); } diff --git a/lib/sigpipe-die.c b/lib/sigpipe-die.c index bb3c8b00e..4790b9471 100644 --- a/lib/sigpipe-die.c +++ b/lib/sigpipe-die.c @@ -34,7 +34,7 @@ void sigpipe_die (void) { error (exit_failure, 0, "%s", - _("error writing to a closed pipe or socket")); + _("error writing to a closed pipe or socket")); /* Ensure that this function really does not return. */ abort (); @@ -68,15 +68,15 @@ install_sigpipe_die_handler (void (*prepare_die) (void)) sigemptyset (&action.sa_mask); if (sigaction (SIGPIPE, &action, NULL) >= 0) { - /* Unblock the signal (just in case). This is needed because if the - signal was blocked in the parent process, it is also blocked in - this process: the mask of blocked signals is inherited across - fork/exec (except for SIGCHLD). */ - sigset_t sigpipe_set; - - sigemptyset (&sigpipe_set); - sigaddset (&sigpipe_set, SIGPIPE); - sigprocmask (SIG_UNBLOCK, &sigpipe_set, NULL); + /* Unblock the signal (just in case). This is needed because if the + signal was blocked in the parent process, it is also blocked in + this process: the mask of blocked signals is inherited across + fork/exec (except for SIGCHLD). */ + sigset_t sigpipe_set; + + sigemptyset (&sigpipe_set); + sigaddset (&sigpipe_set, SIGPIPE); + sigprocmask (SIG_UNBLOCK, &sigpipe_set, NULL); } } } diff --git a/lib/sigprocmask.c b/lib/sigprocmask.c index 7b486a2b0..cd4362b45 100644 --- a/lib/sigprocmask.c +++ b/lib/sigprocmask.c @@ -72,9 +72,9 @@ ext_signal (int sig, handler_t handler) { case SIGPIPE: { - handler_t old_handler = SIGPIPE_handler; - SIGPIPE_handler = handler; - return old_handler; + handler_t old_handler = SIGPIPE_handler; + SIGPIPE_handler = handler; + return old_handler; } default: /* System defined signal */ return signal (sig, handler); @@ -90,7 +90,7 @@ sigismember (const sigset_t *set, int sig) { #ifdef SIGABRT_COMPAT if (sig == SIGABRT_COMPAT) - sig = SIGABRT; + sig = SIGABRT; #endif return (*set >> sig) & 1; @@ -113,7 +113,7 @@ sigaddset (sigset_t *set, int sig) { #ifdef SIGABRT_COMPAT if (sig == SIGABRT_COMPAT) - sig = SIGABRT; + sig = SIGABRT; #endif *set |= 1U << sig; @@ -133,7 +133,7 @@ sigdelset (sigset_t *set, int sig) { #ifdef SIGABRT_COMPAT if (sig == SIGABRT_COMPAT) - sig = SIGABRT; + sig = SIGABRT; #endif *set &= ~(1U << sig); @@ -204,60 +204,60 @@ sigprocmask (int operation, const sigset_t *set, sigset_t *old_set) 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; - } + { + 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; - } - } + { + 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); - } + { + 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; } @@ -274,26 +274,26 @@ rpl_signal (int sig, handler_t handler) { #ifdef SIGABRT_COMPAT if (sig == SIGABRT_COMPAT) - sig = SIGABRT; + 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; - } + { + /* 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); + return signal (sig, handler); } else { @@ -312,15 +312,15 @@ rpl_raise (int sig) { case SIGPIPE: if (blocked_set & (1U << sig)) - pending_array[sig] = 1; + pending_array[sig] = 1; else - { - handler_t handler = SIGPIPE_handler; - if (handler == SIG_DFL) - exit (128 + SIGPIPE); - else if (handler != SIG_IGN) - (*handler) (sig); - } + { + handler_t handler = SIGPIPE_handler; + if (handler == SIG_DFL) + exit (128 + SIGPIPE); + else if (handler != SIG_IGN) + (*handler) (sig); + } return 0; default: /* System defined signal */ return raise (sig); diff --git a/lib/sincosl.c b/lib/sincosl.c index 1de04569e..71c897b94 100644 --- a/lib/sincosl.c +++ b/lib/sincosl.c @@ -25,7 +25,7 @@ static const long double sin_c[] = { #define ONE sin_c[0] - 1.00000000000000000000000000000000000E+00L, /* 3fff0000000000000000000000000000 */ + 1.00000000000000000000000000000000000E+00L, /* 3fff0000000000000000000000000000 */ /* cos x ~ ONE + x^2 ( SCOS1 + SCOS2 * x^2 + ... + SCOS4 * x^6 + SCOS5 * x^8 ) x in <0,1/256> */ @@ -34,11 +34,11 @@ static const long double sin_c[] = { #define SCOS3 sin_c[3] #define SCOS4 sin_c[4] #define SCOS5 sin_c[5] - -5.00000000000000000000000000000000000E-01L, /* bffe0000000000000000000000000000 */ - 4.16666666666666666666666666556146073E-02L, /* 3ffa5555555555555555555555395023 */ - -1.38888888888888888888309442601939728E-03L, /* bff56c16c16c16c16c16a566e42c0375 */ - 2.48015873015862382987049502531095061E-05L, /* 3fefa01a01a019ee02dcf7da2d6d5444 */ - -2.75573112601362126593516899592158083E-07L, /* bfe927e4f5dce637cb0b54908754bde0 */ + -5.00000000000000000000000000000000000E-01L, /* bffe0000000000000000000000000000 */ + 4.16666666666666666666666666556146073E-02L, /* 3ffa5555555555555555555555395023 */ + -1.38888888888888888888309442601939728E-03L, /* bff56c16c16c16c16c16a566e42c0375 */ + 2.48015873015862382987049502531095061E-05L, /* 3fefa01a01a019ee02dcf7da2d6d5444 */ + -2.75573112601362126593516899592158083E-07L, /* bfe927e4f5dce637cb0b54908754bde0 */ /* sin x ~ ONE * x + x^3 ( SIN1 + SIN2 * x^2 + ... + SIN7 * x^12 + SIN8 * x^14 ) x in <0,0.1484375> */ @@ -50,14 +50,14 @@ static const long double sin_c[] = { #define SIN6 sin_c[11] #define SIN7 sin_c[12] #define SIN8 sin_c[13] - -1.66666666666666666666666666666666538e-01L, /* bffc5555555555555555555555555550 */ - 8.33333333333333333333333333307532934e-03L, /* 3ff811111111111111111111110e7340 */ - -1.98412698412698412698412534478712057e-04L, /* bff2a01a01a01a01a01a019e7a626296 */ - 2.75573192239858906520896496653095890e-06L, /* 3fec71de3a556c7338fa38527474b8f5 */ - -2.50521083854417116999224301266655662e-08L, /* bfe5ae64567f544e16c7de65c2ea551f */ - 1.60590438367608957516841576404938118e-10L, /* 3fde6124613a811480538a9a41957115 */ - -7.64716343504264506714019494041582610e-13L, /* bfd6ae7f3d5aef30c7bc660b060ef365 */ - 2.81068754939739570236322404393398135e-15L, /* 3fce9510115aabf87aceb2022a9a9180 */ + -1.66666666666666666666666666666666538e-01L, /* bffc5555555555555555555555555550 */ + 8.33333333333333333333333333307532934e-03L, /* 3ff811111111111111111111110e7340 */ + -1.98412698412698412698412534478712057e-04L, /* bff2a01a01a01a01a01a019e7a626296 */ + 2.75573192239858906520896496653095890e-06L, /* 3fec71de3a556c7338fa38527474b8f5 */ + -2.50521083854417116999224301266655662e-08L, /* bfe5ae64567f544e16c7de65c2ea551f */ + 1.60590438367608957516841576404938118e-10L, /* 3fde6124613a811480538a9a41957115 */ + -7.64716343504264506714019494041582610e-13L, /* bfd6ae7f3d5aef30c7bc660b060ef365 */ + 2.81068754939739570236322404393398135e-15L, /* 3fce9510115aabf87aceb2022a9a9180 */ /* sin x ~ ONE * x + x^3 ( SSIN1 + SSIN2 * x^2 + ... + SSIN4 * x^6 + SSIN5 * x^8 ) x in <0,1/256> */ @@ -66,11 +66,11 @@ static const long double sin_c[] = { #define SSIN3 sin_c[16] #define SSIN4 sin_c[17] #define SSIN5 sin_c[18] - -1.66666666666666666666666666666666659E-01L, /* bffc5555555555555555555555555555 */ - 8.33333333333333333333333333146298442E-03L, /* 3ff81111111111111111111110fe195d */ - -1.98412698412698412697726277416810661E-04L, /* bff2a01a01a01a01a019e7121e080d88 */ - 2.75573192239848624174178393552189149E-06L, /* 3fec71de3a556c640c6aaa51aa02ab41 */ - -2.50521016467996193495359189395805639E-08L, /* bfe5ae644ee90c47dc71839de75b2787 */ + -1.66666666666666666666666666666666659E-01L, /* bffc5555555555555555555555555555 */ + 8.33333333333333333333333333146298442E-03L, /* 3ff81111111111111111111110fe195d */ + -1.98412698412698412697726277416810661E-04L, /* bff2a01a01a01a01a019e7121e080d88 */ + 2.75573192239848624174178393552189149E-06L, /* 3fec71de3a556c640c6aaa51aa02ab41 */ + -2.50521016467996193495359189395805639E-08L, /* bfe5ae644ee90c47dc71839de75b2787 */ }; static const long double cos_c[] = { @@ -84,14 +84,14 @@ static const long double cos_c[] = { #define COS6 cos_c[5] #define COS7 cos_c[6] #define COS8 cos_c[7] - -4.99999999999999999999999999999999759E-01L, /* bffdfffffffffffffffffffffffffffb */ - 4.16666666666666666666666666651287795E-02L, /* 3ffa5555555555555555555555516f30 */ - -1.38888888888888888888888742314300284E-03L, /* bff56c16c16c16c16c16c16a463dfd0d */ - 2.48015873015873015867694002851118210E-05L, /* 3fefa01a01a01a01a0195cebe6f3d3a5 */ - -2.75573192239858811636614709689300351E-07L, /* bfe927e4fb7789f5aa8142a22044b51f */ - 2.08767569877762248667431926878073669E-09L, /* 3fe21eed8eff881d1e9262d7adff4373 */ - -1.14707451049343817400420280514614892E-11L, /* bfda9397496922a9601ed3d4ca48944b */ - 4.77810092804389587579843296923533297E-14L, /* 3fd2ae5f8197cbcdcaf7c3fb4523414c */ + -4.99999999999999999999999999999999759E-01L, /* bffdfffffffffffffffffffffffffffb */ + 4.16666666666666666666666666651287795E-02L, /* 3ffa5555555555555555555555516f30 */ + -1.38888888888888888888888742314300284E-03L, /* bff56c16c16c16c16c16c16a463dfd0d */ + 2.48015873015873015867694002851118210E-05L, /* 3fefa01a01a01a01a0195cebe6f3d3a5 */ + -2.75573192239858811636614709689300351E-07L, /* bfe927e4fb7789f5aa8142a22044b51f */ + 2.08767569877762248667431926878073669E-09L, /* 3fe21eed8eff881d1e9262d7adff4373 */ + -1.14707451049343817400420280514614892E-11L, /* bfda9397496922a9601ed3d4ca48944b */ + 4.77810092804389587579843296923533297E-14L, /* 3fd2ae5f8197cbcdcaf7c3fb4523414c */ }; @@ -114,23 +114,23 @@ kernel_sinl (long double x, long double y, int iy) sign = -1; } - if (x < 0.1484375L) /* |x| < 0.1484375 */ + if (x < 0.1484375L) /* |x| < 0.1484375 */ { /* Argument is small enough to approximate it by a Chebyshev polynomial of degree 17. */ - if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2^-57 */ - if (!((int) x)) - return x; /* generate inexact */ + if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2^-57 */ + if (!((int) x)) + return x; /* generate inexact */ z = x * x; return x + (x * (z * (SIN1 + z * (SIN2 + z * (SIN3 + z * (SIN4 + - z * (SIN5 + - z * - (SIN6 + - z * - (SIN7 + - z * - SIN8))))))))); + z * (SIN5 + + z * + (SIN6 + + z * + (SIN7 + + z * + SIN8))))))))); } else { @@ -144,24 +144,24 @@ kernel_sinl (long double x, long double y, int iy) index = (int) (x * 128L + 0.5L); h = index / 128.0L; if (iy) - l = y - (h - x); + l = y - (h - x); else - l = x - h; + l = x - h; z = l * l; sin_l = - l * (ONE + - z * (SSIN1 + - z * (SSIN2 + z * (SSIN3 + z * (SSIN4 + z * SSIN5))))); + l * (ONE + + z * (SSIN1 + + z * (SSIN2 + z * (SSIN3 + z * (SSIN4 + z * SSIN5))))); cos_l_m1 = - z * (SCOS1 + z * (SCOS2 + z * (SCOS3 + z * (SCOS4 + z * SCOS5)))); + z * (SCOS1 + z * (SCOS2 + z * (SCOS3 + z * (SCOS4 + z * SCOS5)))); index *= 4; z = - sincosl_table[index + SINCOSL_SIN_HI] + - (sincosl_table[index + SINCOSL_SIN_LO] + - (sincosl_table[index + SINCOSL_SIN_HI] * cos_l_m1) + - (sincosl_table[index + SINCOSL_COS_HI] * sin_l)); + sincosl_table[index + SINCOSL_SIN_HI] + + (sincosl_table[index + SINCOSL_SIN_LO] + + (sincosl_table[index + SINCOSL_SIN_HI] * cos_l_m1) + + (sincosl_table[index + SINCOSL_COS_HI] * sin_l)); return z * sign; } } @@ -175,21 +175,21 @@ kernel_cosl (long double x, long double y) if (x < 0) x = -x; - if (x < 0.1484375L) /* |x| < 0.1484375 */ + if (x < 0.1484375L) /* |x| < 0.1484375 */ { /* Argument is small enough to approximate it by a Chebyshev polynomial of degree 16. */ - if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2^-57 */ - if (!((int) x)) - return ONE; /* generate inexact */ + if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2^-57 */ + if (!((int) x)) + return ONE; /* generate inexact */ z = x * x; return ONE + (z * (COS1 + z * (COS2 + z * (COS3 + z * (COS4 + - z * (COS5 + - z * (COS6 + - z * - (COS7 + - z * - COS8)))))))); + z * (COS5 + + z * (COS6 + + z * + (COS7 + + z * + COS8)))))))); } else { @@ -205,11 +205,11 @@ kernel_cosl (long double x, long double y) l = y - (h - x); z = l * l; sin_l = - l * (ONE + - z * (SSIN1 + - z * (SSIN2 + z * (SSIN3 + z * (SSIN4 + z * SSIN5))))); + l * (ONE + + z * (SSIN1 + + z * (SSIN2 + z * (SSIN3 + z * (SSIN4 + z * SSIN5))))); cos_l_m1 = - z * (SCOS1 + z * (SCOS2 + z * (SCOS3 + z * (SCOS4 + z * SCOS5)))); + z * (SCOS1 + z * (SCOS2 + z * (SCOS3 + z * (SCOS4 + z * SCOS5)))); index *= 4; z = sincosl_table [index + SINCOSL_COS_HI] @@ -233,665 +233,665 @@ static const long double sincosl_table[] = { /* x = 1.48437500000000000000000000000000000e-01L 3ffc3000000000000000000000000000 */ /* cos(x) = 0.fd2f5320e1b790209b4dda2f98f79caaa7b873aff1014b0fbc5243766d03cb006bc837c4358 */ - 9.89003367927322909016887196069562069e-01L, /* 3ffefa5ea641c36f2041369bb45f31ef */ - 2.15663692029265697782289400027743703e-35L, /* 3f8bcaaa7b873aff1014b0fbc5243767 */ + 9.89003367927322909016887196069562069e-01L, /* 3ffefa5ea641c36f2041369bb45f31ef */ + 2.15663692029265697782289400027743703e-35L, /* 3f8bcaaa7b873aff1014b0fbc5243767 */ /* sin(x) = 0.25dc50bc95711d0d9787d108fd438cf5959ee0bfb7a1e36e8b1a112968f356657420e9cc9ea */ - 1.47892995873409608580026675734609314e-01L, /* 3ffc2ee285e4ab88e86cbc3e8847ea1c */ - 9.74950446464233268291647449768590886e-36L, /* 3f8a9eb2b3dc17f6f43c6dd16342252d */ + 1.47892995873409608580026675734609314e-01L, /* 3ffc2ee285e4ab88e86cbc3e8847ea1c */ + 9.74950446464233268291647449768590886e-36L, /* 3f8a9eb2b3dc17f6f43c6dd16342252d */ /* x = 1.56250000000000000000000000000000000e-01 3ffc4000000000000000000000000000 */ /* cos(x) = 0.fce1a053e621438b6d60c76e8c45bf0a9dc71aa16f922acc10e95144ec796a249813c9cb649 */ - 9.87817783816471944100503034363211317e-01L, /* 3ffef9c340a7cc428716dac18edd188b */ - 4.74271307836705897892468107620526395e-35L, /* 3f8cf854ee38d50b7c915660874a8a27 */ + 9.87817783816471944100503034363211317e-01L, /* 3ffef9c340a7cc428716dac18edd188b */ + 4.74271307836705897892468107620526395e-35L, /* 3f8cf854ee38d50b7c915660874a8a27 */ /* sin(x) = 0.27d66258bacd96a3eb335b365c87d59438c5142bb56a489e9b8db9d36234ffdebb6bdc22d8e */ - 1.55614992773556041209920643203516258e-01L, /* 3ffc3eb312c5d66cb51f599ad9b2e43f */ - -7.83989563419287980121718050629497270e-36L, /* bf8a4d78e75d7a8952b6ec2c8e48c594 */ + 1.55614992773556041209920643203516258e-01L, /* 3ffc3eb312c5d66cb51f599ad9b2e43f */ + -7.83989563419287980121718050629497270e-36L, /* bf8a4d78e75d7a8952b6ec2c8e48c594 */ /* x = 1.64062500000000000000000000000000000e-01 3ffc5000000000000000000000000000 */ /* cos(x) = 0.fc8ffa01ba6807417e05962b0d9fdf1fddb0cc4c07d22e19e08019bffa50a6c7acdb40307a3 */ - 9.86571908399497588757337407495308409e-01L, /* 3ffef91ff40374d00e82fc0b2c561b40 */ - -2.47327949936985362476252401212720725e-35L, /* bf8c070112799d9fc16e8f30fbff3200 */ + 9.86571908399497588757337407495308409e-01L, /* 3ffef91ff40374d00e82fc0b2c561b40 */ + -2.47327949936985362476252401212720725e-35L, /* bf8c070112799d9fc16e8f30fbff3200 */ /* sin(x) = 0.29cfd49b8be4f665276cab01cbf0426934906c3dd105473b226e410b1450f62e53ff7c6cce1 */ - 1.63327491736612850846866172454354370e-01L, /* 3ffc4e7ea4dc5f27b3293b65580e5f82 */ - 1.81380344301155485770367902300754350e-36L, /* 3f88349a48361ee882a39d913720858a */ + 1.63327491736612850846866172454354370e-01L, /* 3ffc4e7ea4dc5f27b3293b65580e5f82 */ + 1.81380344301155485770367902300754350e-36L, /* 3f88349a48361ee882a39d913720858a */ /* x = 1.71875000000000000000000000000000000e-01 3ffc6000000000000000000000000000 */ /* cos(x) = 0.fc3a6170f767ac735d63d99a9d439e1db5e59d3ef153a4265d5855850ed82b536bf361b80e3 */ - 9.85265817718213816204294709759578994e-01L, /* 3ffef874c2e1eecf58e6bac7b3353a87 */ - 2.26568029505818066141517497778527952e-35L, /* 3f8be1db5e59d3ef153a4265d5855851 */ + 9.85265817718213816204294709759578994e-01L, /* 3ffef874c2e1eecf58e6bac7b3353a87 */ + 2.26568029505818066141517497778527952e-35L, /* 3f8be1db5e59d3ef153a4265d5855851 */ /* sin(x) = 0.2bc89f9f424de5485de7ce03b2514952b9faf5648c3244d4736feb95dbb9da49f3b58a9253b */ - 1.71030022031395019281347969239834331e-01L, /* 3ffc5e44fcfa126f2a42ef3e701d928a */ - 7.01395875187487608875416030203241317e-36L, /* 3f8a2a573f5eac9186489a8e6dfd72bb */ + 1.71030022031395019281347969239834331e-01L, /* 3ffc5e44fcfa126f2a42ef3e701d928a */ + 7.01395875187487608875416030203241317e-36L, /* 3f8a2a573f5eac9186489a8e6dfd72bb */ /* x = 1.79687500000000000000000000000000000e-01 3ffc7000000000000000000000000000 */ /* cos(x) = 0.fbe0d7f7fef11e70aa43b8abf4f6a457cea20c8f3f676b47781f9821bbe9ce04b3c7b981c0b */ - 9.83899591489663972178309351416487245e-01L, /* 3ffef7c1afeffde23ce154877157e9ed */ - 2.73414318948066207810486330723761265e-35L, /* 3f8c22be75106479fb3b5a3bc0fcc10e */ + 9.83899591489663972178309351416487245e-01L, /* 3ffef7c1afeffde23ce154877157e9ed */ + 2.73414318948066207810486330723761265e-35L, /* 3f8c22be75106479fb3b5a3bc0fcc10e */ /* sin(x) = 0.2dc0bb80b49a97ffb34e8dd1f8db9df7af47ed2dcf58b12c8e7827e048cae929da02c04ecac */ - 1.78722113535153659375356241864180724e-01L, /* 3ffc6e05dc05a4d4bffd9a746e8fc6dd */ - -1.52906926517265103202547561260594148e-36L, /* bf8804285c09691853a769b8c3ec0fdc */ + 1.78722113535153659375356241864180724e-01L, /* 3ffc6e05dc05a4d4bffd9a746e8fc6dd */ + -1.52906926517265103202547561260594148e-36L, /* bf8804285c09691853a769b8c3ec0fdc */ /* x = 1.87500000000000000000000000000000000e-01 3ffc8000000000000000000000000000 */ /* cos(x) = 0.fb835efcf670dd2ce6fe7924697eea13ea358867e9cdb3899b783f4f9f43aa5626e8b67b3bc */ - 9.82473313101255257487327683243622495e-01L, /* 3ffef706bdf9ece1ba59cdfcf248d2fe */ - -1.64924358891557584625463868014230342e-35L, /* bf8b5ec15ca779816324c766487c0b06 */ + 9.82473313101255257487327683243622495e-01L, /* 3ffef706bdf9ece1ba59cdfcf248d2fe */ + -1.64924358891557584625463868014230342e-35L, /* bf8b5ec15ca779816324c766487c0b06 */ /* sin(x) = 0.2fb8205f75e56a2b56a1c4792f856258769af396e0189ef72c05e4df59a6b00e4b44a6ea515 */ - 1.86403296762269884552379983103205261e-01L, /* 3ffc7dc102fbaf2b515ab50e23c97c2b */ - 1.76460304806826780010586715975331753e-36L, /* 3f882c3b4d79cb700c4f7b9602f26fad */ + 1.86403296762269884552379983103205261e-01L, /* 3ffc7dc102fbaf2b515ab50e23c97c2b */ + 1.76460304806826780010586715975331753e-36L, /* 3f882c3b4d79cb700c4f7b9602f26fad */ /* x = 1.95312500000000000000000000000000000e-01 3ffc9000000000000000000000000000 */ /* cos(x) = 0.fb21f7f5c156696b00ac1fe28ac5fd76674a92b4df80d9c8a46c684399005deccc41386257c */ - 9.80987069605669190469329896435309665e-01L, /* 3ffef643efeb82acd2d601583fc5158c */ - -1.90899259410096419886996331536278461e-36L, /* bf8844cc5ab6a5903f931badc9cbde34 */ + 9.80987069605669190469329896435309665e-01L, /* 3ffef643efeb82acd2d601583fc5158c */ + -1.90899259410096419886996331536278461e-36L, /* bf8844cc5ab6a5903f931badc9cbde34 */ /* sin(x) = 0.31aec65df552876f82ece9a2356713246eba6799983d7011b0b3698d6e1da919c15d57c30c1 */ - 1.94073102892909791156055200214145404e-01L, /* 3ffc8d7632efaa943b7c17674d11ab39 */ - -9.67304741051998267208945242944928999e-36L, /* bf8a9b7228b30cccf851fdc9e992ce52 */ + 1.94073102892909791156055200214145404e-01L, /* 3ffc8d7632efaa943b7c17674d11ab39 */ + -9.67304741051998267208945242944928999e-36L, /* bf8a9b7228b30cccf851fdc9e992ce52 */ /* x = 2.03125000000000000000000000000000000e-01 3ffca000000000000000000000000000 */ /* cos(x) = 0.fabca467fb3cb8f1d069f01d8ea33ade5bfd68296ecd1cc9f7b7609bbcf3676e726c3301334 */ - 9.79440951715548359998530954502987493e-01L, /* 3ffef57948cff67971e3a0d3e03b1d46 */ - 4.42878056591560757066844797290067990e-35L, /* 3f8cd6f2dfeb414b7668e64fbdbb04de */ + 9.79440951715548359998530954502987493e-01L, /* 3ffef57948cff67971e3a0d3e03b1d46 */ + 4.42878056591560757066844797290067990e-35L, /* 3f8cd6f2dfeb414b7668e64fbdbb04de */ /* sin(x) = 0.33a4a5a19d86246710f602c44df4fa513f4639ce938477aeeabb82e8e0a7ed583a188879fd4 */ - 2.01731063801638804725038151164000971e-01L, /* 3ffc9d252d0cec31233887b016226fa8 */ - -4.27513434754966978435151290617384120e-36L, /* bf896bb02e718c5b1ee21445511f45c8 */ + 2.01731063801638804725038151164000971e-01L, /* 3ffc9d252d0cec31233887b016226fa8 */ + -4.27513434754966978435151290617384120e-36L, /* bf896bb02e718c5b1ee21445511f45c8 */ /* x = 2.10937500000000000000000000000000000e-01 3ffcb000000000000000000000000000 */ /* cos(x) = 0.fa5365e8f1d3ca27be1db5d76ae64d983d7470a4ab0f4ccf65a2b8c67a380df949953a09bc1 */ - 9.77835053797959793331971572944454549e-01L, /* 3ffef4a6cbd1e3a7944f7c3b6baed5cd */ - -3.79207422905180416937210853779192702e-35L, /* bf8c933e145c7adaa7859984d2ea39cc */ + 9.77835053797959793331971572944454549e-01L, /* 3ffef4a6cbd1e3a7944f7c3b6baed5cd */ + -3.79207422905180416937210853779192702e-35L, /* bf8c933e145c7adaa7859984d2ea39cc */ /* sin(x) = 0.3599b652f40ec999df12a0a4c8561de159c98d4e54555de518b97f48886f715d8df5f4f093e */ - 2.09376712085993643711890752724881652e-01L, /* 3ffcaccdb297a0764ccef895052642b1 */ - -1.59470287344329449965314638482515925e-36L, /* bf880f531b3958d5d5510d73a3405bbc */ + 2.09376712085993643711890752724881652e-01L, /* 3ffcaccdb297a0764ccef895052642b1 */ + -1.59470287344329449965314638482515925e-36L, /* bf880f531b3958d5d5510d73a3405bbc */ /* x = 2.18750000000000000000000000000000000e-01 3ffcc000000000000000000000000000 */ /* cos(x) = 0.f9e63e1d9e8b6f6f2e296bae5b5ed9c11fd7fa2fe11e09fc7bde901abed24b6365e72f7db4e */ - 9.76169473868635276723989035435135534e-01L, /* 3ffef3cc7c3b3d16dede5c52d75cb6be */ - -2.87727974249481583047944860626985460e-35L, /* bf8c31f701402e80f70fb01c210b7f2a */ + 9.76169473868635276723989035435135534e-01L, /* 3ffef3cc7c3b3d16dede5c52d75cb6be */ + -2.87727974249481583047944860626985460e-35L, /* bf8c31f701402e80f70fb01c210b7f2a */ /* sin(x) = 0.378df09db8c332ce0d2b53d865582e4526ea336c768f68c32b496c6d11c1cd241bb9f1da523 */ - 2.17009581095010156760578095826055396e-01L, /* 3ffcbc6f84edc6199670695a9ec32ac1 */ - 1.07356488794216831812829549198201194e-35L, /* 3f8ac8a4dd466d8ed1ed1865692d8da2 */ + 2.17009581095010156760578095826055396e-01L, /* 3ffcbc6f84edc6199670695a9ec32ac1 */ + 1.07356488794216831812829549198201194e-35L, /* 3f8ac8a4dd466d8ed1ed1865692d8da2 */ /* x = 2.26562500000000000000000000000000000e-01 3ffcd000000000000000000000000000 */ /* cos(x) = 0.f9752eba9fff6b98842beadab054a932fb0f8d5b875ae63d6b2288d09b148921aeb6e52f61b */ - 9.74444313585988980349711056045434344e-01L, /* 3ffef2ea5d753ffed7310857d5b560a9 */ - 3.09947905955053419304514538592548333e-35L, /* 3f8c4997d87c6adc3ad731eb59144685 */ + 9.74444313585988980349711056045434344e-01L, /* 3ffef2ea5d753ffed7310857d5b560a9 */ + 3.09947905955053419304514538592548333e-35L, /* 3f8c4997d87c6adc3ad731eb59144685 */ /* sin(x) = 0.39814cb10513453cb97b21bc1ca6a337b150c21a675ab85503bc09a436a10ab1473934e20c8 */ - 2.24629204957705292350428549796424820e-01L, /* 3ffccc0a6588289a29e5cbd90de0e535 */ - 2.42061510849297469844695751870058679e-36L, /* 3f889bd8a8610d33ad5c2a81de04d21b */ + 2.24629204957705292350428549796424820e-01L, /* 3ffccc0a6588289a29e5cbd90de0e535 */ + 2.42061510849297469844695751870058679e-36L, /* 3f889bd8a8610d33ad5c2a81de04d21b */ /* x = 2.34375000000000000000000000000000000e-01 3ffce000000000000000000000000000 */ /* cos(x) = 0.f90039843324f9b940416c1984b6cbed1fc733d97354d4265788a86150493ce657cae032674 */ - 9.72659678244912752670913058267565260e-01L, /* 3ffef20073086649f3728082d833096e */ - -3.91759231819314904966076958560252735e-35L, /* bf8ca09701c6613465595ecd43babcf5 */ + 9.72659678244912752670913058267565260e-01L, /* 3ffef20073086649f3728082d833096e */ + -3.91759231819314904966076958560252735e-35L, /* bf8ca09701c6613465595ecd43babcf5 */ /* sin(x) = 0.3b73c2bf6b4b9f668ef9499c81f0d965087f1753fa64b086e58cb8470515c18c1412f8c2e02 */ - 2.32235118611511462413930877746235872e-01L, /* 3ffcdb9e15fb5a5cfb3477ca4ce40f87 */ - -4.96930483364191020075024624332928910e-36L, /* bf89a6bde03a2b0166d3de469cd1ee3f */ + 2.32235118611511462413930877746235872e-01L, /* 3ffcdb9e15fb5a5cfb3477ca4ce40f87 */ + -4.96930483364191020075024624332928910e-36L, /* bf89a6bde03a2b0166d3de469cd1ee3f */ /* x = 2.42187500000000000000000000000000000e-01 3ffcf000000000000000000000000000 */ /* cos(x) = 0.f887604e2c39dbb20e4ec5825059a789ffc95b275ad9954078ba8a28d3fcfe9cc2c1d49697b */ - 9.70815676770349462947490545785046027e-01L, /* 3ffef10ec09c5873b7641c9d8b04a0b3 */ - 2.97458820972393859125277682021202860e-35L, /* 3f8c3c4ffe4ad93ad6ccaa03c5d45147 */ + 9.70815676770349462947490545785046027e-01L, /* 3ffef10ec09c5873b7641c9d8b04a0b3 */ + 2.97458820972393859125277682021202860e-35L, /* 3f8c3c4ffe4ad93ad6ccaa03c5d45147 */ /* sin(x) = 0.3d654aff15cb457a0fca854698aba33039a8a40626609204472d9d40309b626eccc6dff0ffa */ - 2.39826857830661564441369251810886574e-01L, /* 3ffceb2a57f8ae5a2bd07e542a34c55d */ - 2.39867036569896287240938444445071448e-36L, /* 3f88981cd45203133049022396cea018 */ + 2.39826857830661564441369251810886574e-01L, /* 3ffceb2a57f8ae5a2bd07e542a34c55d */ + 2.39867036569896287240938444445071448e-36L, /* 3f88981cd45203133049022396cea018 */ /* x = 2.50000000000000000000000000000000000e-01 3ffd0000000000000000000000000000 */ /* cos(x) = 0.f80aa4fbef750ba783d33cb95f94f8a41426dbe79edc4a023ef9ec13c944551c0795b84fee1 */ - 9.68912421710644784144595449494189205e-01L, /* 3ffef01549f7deea174f07a67972bf2a */ - -5.53634706113461989398873287749326500e-36L, /* bf89d6faf649061848ed7f704184fb0e */ + 9.68912421710644784144595449494189205e-01L, /* 3ffef01549f7deea174f07a67972bf2a */ + -5.53634706113461989398873287749326500e-36L, /* bf89d6faf649061848ed7f704184fb0e */ /* sin(x) = 0.3f55dda9e62aed7513bd7b8e6a3d1635dd5676648d7db525898d7086af9330f03c7f285442a */ - 2.47403959254522929596848704849389203e-01L, /* 3ffcfaaeed4f31576ba89debdc7351e9 */ - -7.36487001108599532943597115275811618e-36L, /* bf8a39445531336e50495b4ece51ef2a */ + 2.47403959254522929596848704849389203e-01L, /* 3ffcfaaeed4f31576ba89debdc7351e9 */ + -7.36487001108599532943597115275811618e-36L, /* bf8a39445531336e50495b4ece51ef2a */ /* x = 2.57812500000000000000000000000000000e-01 3ffd0800000000000000000000000000 */ /* cos(x) = 0.f78a098069792daabc9ee42591b7c5a68cb1ab822aeb446b3311b4ba5371b8970e2c1547ad7 */ - 9.66950029230677822008341623610531503e-01L, /* 3ffeef141300d2f25b55793dc84b2370 */ - -4.38972214432792412062088059990480514e-35L, /* bf8cd2cb9a72a3eea8a5dca667725a2d */ + 9.66950029230677822008341623610531503e-01L, /* 3ffeef141300d2f25b55793dc84b2370 */ + -4.38972214432792412062088059990480514e-35L, /* bf8cd2cb9a72a3eea8a5dca667725a2d */ /* sin(x) = 0.414572fd94556e6473d620271388dd47c0ba050cdb5270112e3e370e8c4705ae006426fb5d5 */ - 2.54965960415878467487556574864872628e-01L, /* 3ffd0515cbf65155b991cf58809c4e23 */ - 2.20280377918534721005071688328074154e-35L, /* 3f8bd47c0ba050cdb5270112e3e370e9 */ + 2.54965960415878467487556574864872628e-01L, /* 3ffd0515cbf65155b991cf58809c4e23 */ + 2.20280377918534721005071688328074154e-35L, /* 3f8bd47c0ba050cdb5270112e3e370e9 */ /* x = 2.65625000000000000000000000000000000e-01 3ffd1000000000000000000000000000 */ /* cos(x) = 0.f7058fde0788dfc805b8fe88789e4f4253e3c50afe8b22f41159620ab5940ff7df9557c0d1f */ - 9.64928619104771009581074665315748371e-01L, /* 3ffeee0b1fbc0f11bf900b71fd10f13d */ - -3.66685832670820775002475545602761113e-35L, /* bf8c85ed60e1d7a80ba6e85f7534efaa */ + 9.64928619104771009581074665315748371e-01L, /* 3ffeee0b1fbc0f11bf900b71fd10f13d */ + -3.66685832670820775002475545602761113e-35L, /* bf8c85ed60e1d7a80ba6e85f7534efaa */ /* sin(x) = 0.4334033bcd90d6604f5f36c1d4b84451a87150438275b77470b50e5b968fa7962b5ffb379b7 */ - 2.62512399769153281450949626395692931e-01L, /* 3ffd0cd00cef364359813d7cdb0752e1 */ - 3.24923677072031064673177178571821843e-36L, /* 3f89146a1c5410e09d6ddd1c2d4396e6 */ + 2.62512399769153281450949626395692931e-01L, /* 3ffd0cd00cef364359813d7cdb0752e1 */ + 3.24923677072031064673177178571821843e-36L, /* 3f89146a1c5410e09d6ddd1c2d4396e6 */ /* x = 2.73437500000000000000000000000000000e-01 3ffd1800000000000000000000000000 */ /* cos(x) = 0.f67d3a26af7d07aa4bd6d42af8c0067fefb96d5b46c031eff53627f215ea3242edc3f2e13eb */ - 9.62848314709379699899701093480214365e-01L, /* 3ffeecfa744d5efa0f5497ada855f180 */ - 4.88986966383343450799422013051821394e-36L, /* 3f899ffbee5b56d1b00c7bfd4d89fc85 */ + 9.62848314709379699899701093480214365e-01L, /* 3ffeecfa744d5efa0f5497ada855f180 */ + 4.88986966383343450799422013051821394e-36L, /* 3f899ffbee5b56d1b00c7bfd4d89fc85 */ /* sin(x) = 0.452186aa5377ab20bbf2524f52e3a06a969f47166ab88cf88c111ad12c55941021ef3317a1a */ - 2.70042816718585031552755063618827102e-01L, /* 3ffd14861aa94ddeac82efc9493d4b8f */ - -2.37608892440611310321138680065803162e-35L, /* bf8bf956960b8e99547730773eee52ed */ + 2.70042816718585031552755063618827102e-01L, /* 3ffd14861aa94ddeac82efc9493d4b8f */ + -2.37608892440611310321138680065803162e-35L, /* bf8bf956960b8e99547730773eee52ed */ /* x = 2.81250000000000000000000000000000000e-01 3ffd2000000000000000000000000000 */ /* cos(x) = 0.f5f10a7bb77d3dfa0c1da8b57842783280d01ce3c0f82bae3b9d623c168d2e7c29977994451 */ - 9.60709243015561903066659350581313472e-01L, /* 3ffeebe214f76efa7bf4183b516af085 */ - -5.87011558231583960712013351601221840e-36L, /* bf89f35fcbf8c70fc1f5147118a770fa */ + 9.60709243015561903066659350581313472e-01L, /* 3ffeebe214f76efa7bf4183b516af085 */ + -5.87011558231583960712013351601221840e-36L, /* bf89f35fcbf8c70fc1f5147118a770fa */ /* sin(x) = 0.470df5931ae1d946076fe0dcff47fe31bb2ede618ebc607821f8462b639e1f4298b5ae87fd3 */ - 2.77556751646336325922023446828128568e-01L, /* 3ffd1c37d64c6b8765181dbf8373fd20 */ - -1.35848595468998128214344668770082997e-36L, /* bf87ce44d1219e71439f87de07b9d49c */ + 2.77556751646336325922023446828128568e-01L, /* 3ffd1c37d64c6b8765181dbf8373fd20 */ + -1.35848595468998128214344668770082997e-36L, /* bf87ce44d1219e71439f87de07b9d49c */ /* x = 2.89062500000000000000000000000000000e-01 3ffd2800000000000000000000000000 */ /* cos(x) = 0.f561030ddd7a78960ea9f4a32c6521554995667f5547bafee9ec48b3155cdb0f7fd00509713 */ - 9.58511534581228627301969408154919822e-01L, /* 3ffeeac2061bbaf4f12c1d53e94658ca */ - 2.50770779371636481145735089393154404e-35L, /* 3f8c0aaa4cab33faaa3dd7f74f624599 */ + 9.58511534581228627301969408154919822e-01L, /* 3ffeeac2061bbaf4f12c1d53e94658ca */ + 2.50770779371636481145735089393154404e-35L, /* 3f8c0aaa4cab33faaa3dd7f74f624599 */ /* sin(x) = 0.48f948446abcd6b0f7fccb100e7a1b26eccad880b0d24b59948c7cdd49514d44b933e6985c2 */ - 2.85053745940547424587763033323252561e-01L, /* 3ffd23e52111aaf35ac3dff32c4039e8 */ - 2.04269325885902918802700123680403749e-35L, /* 3f8bb26eccad880b0d24b59948c7cdd5 */ + 2.85053745940547424587763033323252561e-01L, /* 3ffd23e52111aaf35ac3dff32c4039e8 */ + 2.04269325885902918802700123680403749e-35L, /* 3f8bb26eccad880b0d24b59948c7cdd5 */ /* x = 2.96875000000000000000000000000000000e-01 3ffd3000000000000000000000000000 */ /* cos(x) = 0.f4cd261d3e6c15bb369c8758630d2ac00b7ace2a51c0631bfeb39ed158ba924cc91e259c195 */ - 9.56255323543175296975599942263028361e-01L, /* 3ffee99a4c3a7cd82b766d390eb0c61a */ - 3.21616572190865997051103645135837207e-35L, /* 3f8c56005bd671528e0318dff59cf68b */ + 9.56255323543175296975599942263028361e-01L, /* 3ffee99a4c3a7cd82b766d390eb0c61a */ + 3.21616572190865997051103645135837207e-35L, /* 3f8c56005bd671528e0318dff59cf68b */ /* sin(x) = 0.4ae37710fad27c8aa9c4cf96c03519b9ce07dc08a1471775499f05c29f86190aaebaeb9716e */ - 2.92533342023327543624702326493913423e-01L, /* 3ffd2b8ddc43eb49f22aa7133e5b00d4 */ - 1.93539408668704450308003687950685128e-35L, /* 3f8b9b9ce07dc08a1471775499f05c2a */ + 2.92533342023327543624702326493913423e-01L, /* 3ffd2b8ddc43eb49f22aa7133e5b00d4 */ + 1.93539408668704450308003687950685128e-35L, /* 3f8b9b9ce07dc08a1471775499f05c2a */ /* x = 3.04687500000000000000000000000000000e-01 3ffd3800000000000000000000000000 */ /* cos(x) = 0.f43575f94d4f6b272f5fb76b14d2a64ab52df1ee8ddf7c651034e5b2889305a9ea9015d758a */ - 9.53940747608894733981324795987611623e-01L, /* 3ffee86aebf29a9ed64e5ebf6ed629a5 */ - 2.88075689052478602008395972924657164e-35L, /* 3f8c3255a96f8f746efbe32881a72d94 */ + 9.53940747608894733981324795987611623e-01L, /* 3ffee86aebf29a9ed64e5ebf6ed629a5 */ + 2.88075689052478602008395972924657164e-35L, /* 3f8c3255a96f8f746efbe32881a72d94 */ /* sin(x) = 0.4ccc7a50127e1de0cb6b40c302c651f7bded4f9e7702b0471ae0288d091a37391950907202f */ - 2.99995083378683051163248282011699944e-01L, /* 3ffd3331e94049f877832dad030c0b19 */ - 1.35174265535697850139283361475571050e-35L, /* 3f8b1f7bded4f9e7702b0471ae0288d1 */ + 2.99995083378683051163248282011699944e-01L, /* 3ffd3331e94049f877832dad030c0b19 */ + 1.35174265535697850139283361475571050e-35L, /* 3f8b1f7bded4f9e7702b0471ae0288d1 */ /* x = 3.12500000000000000000000000000000000e-01 3ffd4000000000000000000000000000 */ /* cos(x) = 0.f399f500c9e9fd37ae9957263dab8877102beb569f101ee4495350868e5847d181d50d3cca2 */ - 9.51567948048172202145488217364270962e-01L, /* 3ffee733ea0193d3fa6f5d32ae4c7b57 */ - 6.36842628598115658308749288799884606e-36L, /* 3f8a0ee2057d6ad3e203dc892a6a10d2 */ + 9.51567948048172202145488217364270962e-01L, /* 3ffee733ea0193d3fa6f5d32ae4c7b57 */ + 6.36842628598115658308749288799884606e-36L, /* 3f8a0ee2057d6ad3e203dc892a6a10d2 */ /* sin(x) = 0.4eb44a5da74f600207aaa090f0734e288603ffadb3eb2542a46977b105f8547128036dcf7f0 */ - 3.07438514580380850670502958201982091e-01L, /* 3ffd3ad129769d3d80081eaa8243c1cd */ - 1.06515172423204645839241099453417152e-35L, /* 3f8ac510c07ff5b67d64a8548d2ef621 */ + 3.07438514580380850670502958201982091e-01L, /* 3ffd3ad129769d3d80081eaa8243c1cd */ + 1.06515172423204645839241099453417152e-35L, /* 3f8ac510c07ff5b67d64a8548d2ef621 */ /* x = 3.20312500000000000000000000000000000e-01 3ffd4800000000000000000000000000 */ /* cos(x) = 0.f2faa5a1b74e82fd61fa05f9177380e8e69b7b15a945e8e5ae1124bf3d12b0617e03af4fab5 */ - 9.49137069684463027665847421762105623e-01L, /* 3ffee5f54b436e9d05fac3f40bf22ee7 */ - 6.84433965991637152250309190468859701e-37L, /* 3f86d1cd36f62b528bd1cb5c22497e7a */ + 9.49137069684463027665847421762105623e-01L, /* 3ffee5f54b436e9d05fac3f40bf22ee7 */ + 6.84433965991637152250309190468859701e-37L, /* 3f86d1cd36f62b528bd1cb5c22497e7a */ /* sin(x) = 0.509adf9a7b9a5a0f638a8fa3a60a199418859f18b37169a644fdb986c21ecb00133853bc35b */ - 3.14863181319745250865036315126939016e-01L, /* 3ffd426b7e69ee69683d8e2a3e8e9828 */ - 1.92431240212432926993057705062834160e-35L, /* 3f8b99418859f18b37169a644fdb986c */ + 3.14863181319745250865036315126939016e-01L, /* 3ffd426b7e69ee69683d8e2a3e8e9828 */ + 1.92431240212432926993057705062834160e-35L, /* 3f8b99418859f18b37169a644fdb986c */ /* x = 3.28125000000000000000000000000000000e-01 3ffd5000000000000000000000000000 */ /* cos(x) = 0.f2578a595224dd2e6bfa2eb2f99cc674f5ea6f479eae2eb580186897ae3f893df1113ca06b8 */ - 9.46648260886053321846099507295532976e-01L, /* 3ffee4af14b2a449ba5cd7f45d65f33a */ - -4.32906339663000890941529420498824645e-35L, /* bf8ccc5850ac85c30a8e8a53ff3cbb43 */ + 9.46648260886053321846099507295532976e-01L, /* 3ffee4af14b2a449ba5cd7f45d65f33a */ + -4.32906339663000890941529420498824645e-35L, /* bf8ccc5850ac85c30a8e8a53ff3cbb43 */ /* sin(x) = 0.5280326c3cf481823ba6bb08eac82c2093f2bce3c4eb4ee3dec7df41c92c8a4226098616075 */ - 3.22268630433386625687745919893188031e-01L, /* 3ffd4a00c9b0f3d20608ee9aec23ab21 */ - -1.49505897804759263483853908335500228e-35L, /* bf8b3df6c0d431c3b14b11c213820be3 */ + 3.22268630433386625687745919893188031e-01L, /* 3ffd4a00c9b0f3d20608ee9aec23ab21 */ + -1.49505897804759263483853908335500228e-35L, /* bf8b3df6c0d431c3b14b11c213820be3 */ /* x = 3.35937500000000000000000000000000000e-01 3ffd5800000000000000000000000000 */ /* cos(x) = 0.f1b0a5b406b526d886c55feadc8d0dcc8eb9ae2ac707051771b48e05b25b000009660bdb3e3 */ - 9.44101673557004345630017691253124860e-01L, /* 3ffee3614b680d6a4db10d8abfd5b91a */ - 1.03812535240120229609822461172145584e-35L, /* 3f8ab991d735c558e0e0a2ee3691c0b6 */ + 9.44101673557004345630017691253124860e-01L, /* 3ffee3614b680d6a4db10d8abfd5b91a */ + 1.03812535240120229609822461172145584e-35L, /* 3f8ab991d735c558e0e0a2ee3691c0b6 */ /* sin(x) = 0.54643b3da29de9b357155eef0f332fb3e66c83bf4dddd9491c5eb8e103ccd92d6175220ed51 */ - 3.29654409930860171914317725126463176e-01L, /* 3ffd5190ecf68a77a6cd5c557bbc3ccd */ - -1.22606996784743214973082192294232854e-35L, /* bf8b04c19937c40b22226b6e3a1471f0 */ + 3.29654409930860171914317725126463176e-01L, /* 3ffd5190ecf68a77a6cd5c557bbc3ccd */ + -1.22606996784743214973082192294232854e-35L, /* bf8b04c19937c40b22226b6e3a1471f0 */ /* x = 3.43750000000000000000000000000000000e-01 3ffd6000000000000000000000000000 */ /* cos(x) = 0.f105fa4d66b607a67d44e042725204435142ac8ad54dfb0907a4f6b56b06d98ee60f19e557a */ - 9.41497463127881068644511236053670815e-01L, /* 3ffee20bf49acd6c0f4cfa89c084e4a4 */ - 3.20709366603165602071590241054884900e-36L, /* 3f8910d450ab22b5537ec241e93dad5b */ + 9.41497463127881068644511236053670815e-01L, /* 3ffee20bf49acd6c0f4cfa89c084e4a4 */ + 3.20709366603165602071590241054884900e-36L, /* 3f8910d450ab22b5537ec241e93dad5b */ /* sin(x) = 0.5646f27e8bd65cbe3a5d61ff06572290ee826d9674a00246b05ae26753cdfc90d9ce81a7d02 */ - 3.37020069022253076261281754173810024e-01L, /* 3ffd591bc9fa2f5972f8e97587fc195d */ - -2.21435756148839473677777545049890664e-35L, /* bf8bd6f117d92698b5ffdb94fa51d98b */ + 3.37020069022253076261281754173810024e-01L, /* 3ffd591bc9fa2f5972f8e97587fc195d */ + -2.21435756148839473677777545049890664e-35L, /* bf8bd6f117d92698b5ffdb94fa51d98b */ /* x = 3.51562500000000000000000000000000000e-01 3ffd6800000000000000000000000000 */ /* cos(x) = 0.f0578ad01ede707fa39c09dc6b984afef74f3dc8d0efb0f4c5a6b13771145b3e0446fe33887 */ - 9.38835788546265488632578305984712554e-01L, /* 3ffee0af15a03dbce0ff473813b8d731 */ - -3.98758068773974031348585072752245458e-35L, /* bf8ca808458611b978827859d2ca7644 */ + 9.38835788546265488632578305984712554e-01L, /* 3ffee0af15a03dbce0ff473813b8d731 */ + -3.98758068773974031348585072752245458e-35L, /* bf8ca808458611b978827859d2ca7644 */ /* sin(x) = 0.582850a41e1dd46c7f602ea244cdbbbfcdfa8f3189be794dda427ce090b5f85164f1f80ac13 */ - 3.44365158145698408207172046472223747e-01L, /* 3ffd60a14290787751b1fd80ba891337 */ - -3.19791885005480924937758467594051927e-36L, /* bf89100c815c339d9061ac896f60c7dc */ + 3.44365158145698408207172046472223747e-01L, /* 3ffd60a14290787751b1fd80ba891337 */ + -3.19791885005480924937758467594051927e-36L, /* bf89100c815c339d9061ac896f60c7dc */ /* x = 3.59375000000000000000000000000000000e-01 3ffd7000000000000000000000000000 */ /* cos(x) = 0.efa559f5ec3aec3a4eb03319278a2d41fcf9189462261125fe6147b078f1daa0b06750a1654 */ - 9.36116812267055290294237411019508588e-01L, /* 3ffedf4ab3ebd875d8749d6066324f14 */ - 3.40481591236710658435409862439032162e-35L, /* 3f8c6a0fe7c8c4a31130892ff30a3d84 */ + 9.36116812267055290294237411019508588e-01L, /* 3ffedf4ab3ebd875d8749d6066324f14 */ + 3.40481591236710658435409862439032162e-35L, /* 3f8c6a0fe7c8c4a31130892ff30a3d84 */ /* sin(x) = 0.5a084e28e35fda2776dfdbbb5531d74ced2b5d17c0b1afc4647529d50c295e36d8ceec126c1 */ - 3.51689228994814059222584896955547016e-01L, /* 3ffd682138a38d7f689ddb7f6eed54c7 */ - 1.75293433418270210567525412802083294e-35L, /* 3f8b74ced2b5d17c0b1afc4647529d51 */ + 3.51689228994814059222584896955547016e-01L, /* 3ffd682138a38d7f689ddb7f6eed54c7 */ + 1.75293433418270210567525412802083294e-35L, /* 3f8b74ced2b5d17c0b1afc4647529d51 */ /* x = 3.67187500000000000000000000000000000e-01 3ffd7800000000000000000000000000 */ /* cos(x) = 0.eeef6a879146af0bf9b95ea2ea0ac0d3e2e4d7e15d93f48cbd41bf8e4fded40bef69e19eafa */ - 9.33340700242548435655299229469995527e-01L, /* 3ffeddded50f228d5e17f372bd45d416 */ - -4.75255707251679831124800898831382223e-35L, /* bf8cf960e8d940f513605b9a15f2038e */ + 9.33340700242548435655299229469995527e-01L, /* 3ffeddded50f228d5e17f372bd45d416 */ + -4.75255707251679831124800898831382223e-35L, /* bf8cf960e8d940f513605b9a15f2038e */ /* sin(x) = 0.5be6e38ce8095542bc14ee9da0d36483e6734bcab2e07624188af5653f114eeb46738fa899d */ - 3.58991834546065053677710299152868941e-01L, /* 3ffd6f9b8e33a025550af053ba76834e */ - -2.06772389262723368139416970257112089e-35L, /* bf8bb7c198cb4354d1f89dbe7750a9ac */ + 3.58991834546065053677710299152868941e-01L, /* 3ffd6f9b8e33a025550af053ba76834e */ + -2.06772389262723368139416970257112089e-35L, /* bf8bb7c198cb4354d1f89dbe7750a9ac */ /* x = 3.75000000000000000000000000000000000e-01 3ffd8000000000000000000000000000 */ /* cos(x) = 0.ee35bf5ccac89052cd91ddb734d3a47e262e3b609db604e217053803be0091e76daf28a89b7 */ - 9.30507621912314291149476792229555481e-01L, /* 3ffedc6b7eb9959120a59b23bb6e69a7 */ - 2.74541088551732982573335285685416092e-35L, /* 3f8c23f13171db04edb02710b829c01e */ + 9.30507621912314291149476792229555481e-01L, /* 3ffedc6b7eb9959120a59b23bb6e69a7 */ + 2.74541088551732982573335285685416092e-35L, /* 3f8c23f13171db04edb02710b829c01e */ /* sin(x) = 0.5dc40955d9084f48a94675a2498de5d851320ff5528a6afb3f2e24de240fce6cbed1ba0ccd6 */ - 3.66272529086047561372909351716264177e-01L, /* 3ffd7710255764213d22a519d6892638 */ - -1.96768433534936592675897818253108989e-35L, /* bf8ba27aecdf00aad759504c0d1db21e */ + 3.66272529086047561372909351716264177e-01L, /* 3ffd7710255764213d22a519d6892638 */ + -1.96768433534936592675897818253108989e-35L, /* bf8ba27aecdf00aad759504c0d1db21e */ /* x = 3.82812500000000000000000000000000000e-01 3ffd8800000000000000000000000000 */ /* cos(x) = 0.ed785b5c44741b4493c56bcb9d338a151c6f6b85d8f8aca658b28572c162b199680eb9304da */ - 9.27617750192851909628030798799961350e-01L, /* 3ffedaf0b6b888e83689278ad7973a67 */ - 7.58520371916345756281201167126854712e-36L, /* 3f8a42a38ded70bb1f1594cb1650ae58 */ + 9.27617750192851909628030798799961350e-01L, /* 3ffedaf0b6b888e83689278ad7973a67 */ + 7.58520371916345756281201167126854712e-36L, /* 3f8a42a38ded70bb1f1594cb1650ae58 */ /* sin(x) = 0.5f9fb80f21b53649c432540a50e22c53057ff42ae0fdf1307760dc0093f99c8efeb2fbd7073 */ - 3.73530868238692946416839752660848112e-01L, /* 3ffd7e7ee03c86d4d92710c950294389 */ - -1.48023494778986556048879113411517128e-35L, /* bf8b3acfa800bd51f020ecf889f23ff7 */ + 3.73530868238692946416839752660848112e-01L, /* 3ffd7e7ee03c86d4d92710c950294389 */ + -1.48023494778986556048879113411517128e-35L, /* bf8b3acfa800bd51f020ecf889f23ff7 */ /* x = 3.90625000000000000000000000000000000e-01 3ffd9000000000000000000000000000 */ /* cos(x) = 0.ecb7417b8d4ee3fec37aba4073aa48f1f14666006fb431d9671303c8100d10190ec8179c41d */ - 9.24671261467036098502113014560138771e-01L, /* 3ffed96e82f71a9dc7fd86f57480e755 */ - -4.14187124860031825108649347251175815e-35L, /* bf8cb87075cccffc825e7134c767e1bf */ + 9.24671261467036098502113014560138771e-01L, /* 3ffed96e82f71a9dc7fd86f57480e755 */ + -4.14187124860031825108649347251175815e-35L, /* bf8cb87075cccffc825e7134c767e1bf */ /* sin(x) = 0.6179e84a09a5258a40e9b5face03e525f8b5753cd0105d93fe6298010c3458e84d75fe420e9 */ - 3.80766408992390192057200703388896675e-01L, /* 3ffd85e7a1282694962903a6d7eb3810 */ - -2.02009541175208636336924533372496107e-35L, /* bf8bada074a8ac32fefa26c019d67fef */ + 3.80766408992390192057200703388896675e-01L, /* 3ffd85e7a1282694962903a6d7eb3810 */ + -2.02009541175208636336924533372496107e-35L, /* bf8bada074a8ac32fefa26c019d67fef */ /* x = 3.98437500000000000000000000000000000e-01 3ffd9800000000000000000000000000 */ /* cos(x) = 0.ebf274bf0bda4f62447e56a093626798d3013b5942b1abfd155aacc9dc5c6d0806a20d6b9c1 */ - 9.21668335573351918175411368202712714e-01L, /* 3ffed7e4e97e17b49ec488fcad4126c5 */ - -1.83587995433957622948710263541479322e-35L, /* bf8b8672cfec4a6bd4e5402eaa553362 */ + 9.21668335573351918175411368202712714e-01L, /* 3ffed7e4e97e17b49ec488fcad4126c5 */ + -1.83587995433957622948710263541479322e-35L, /* bf8b8672cfec4a6bd4e5402eaa553362 */ /* sin(x) = 0.6352929dd264bd44a02ea766325d8aa8bd9695fc8def3caefba5b94c9a3c873f7b2d3776ead */ - 3.87978709727025046051079690813741960e-01L, /* 3ffd8d4a4a774992f51280ba9d98c976 */ - 8.01904783870935075844443278617586301e-36L, /* 3f8a5517b2d2bf91bde795df74b72993 */ + 3.87978709727025046051079690813741960e-01L, /* 3ffd8d4a4a774992f51280ba9d98c976 */ + 8.01904783870935075844443278617586301e-36L, /* 3f8a5517b2d2bf91bde795df74b72993 */ /* x = 4.06250000000000000000000000000000000e-01 3ffda000000000000000000000000000 */ /* cos(x) = 0.eb29f839f201fd13b93796827916a78f15c85230a4e8ea4b21558265a14367e1abb4c30695a */ - 9.18609155794918267837824977718549863e-01L, /* 3ffed653f073e403fa27726f2d04f22d */ - 2.97608282778274433460057745798409849e-35L, /* 3f8c3c78ae429185274752590aac132d */ + 9.18609155794918267837824977718549863e-01L, /* 3ffed653f073e403fa27726f2d04f22d */ + 2.97608282778274433460057745798409849e-35L, /* 3f8c3c78ae429185274752590aac132d */ /* sin(x) = 0.6529afa7d51b129631ec197c0a840a11d7dc5368b0a47956feb285caa8371c4637ef17ef01b */ - 3.95167330240934236244832640419653657e-01L, /* 3ffd94a6be9f546c4a58c7b065f02a10 */ - 7.57560031388312550940040194042627704e-36L, /* 3f8a423afb8a6d16148f2adfd650b955 */ + 3.95167330240934236244832640419653657e-01L, /* 3ffd94a6be9f546c4a58c7b065f02a10 */ + 7.57560031388312550940040194042627704e-36L, /* 3f8a423afb8a6d16148f2adfd650b955 */ /* x = 4.14062500000000000000000000000000000e-01 3ffda800000000000000000000000000 */ /* cos(x) = 0.ea5dcf0e30cf03e6976ef0b1ec26515fba47383855c3b4055a99b5e86824b2cd1a691fdca7b */ - 9.15493908848301228563917732180221882e-01L, /* 3ffed4bb9e1c619e07cd2edde163d84d */ - -3.50775517955306954815090901168305659e-35L, /* bf8c75022dc63e3d51e25fd52b3250bd */ + 9.15493908848301228563917732180221882e-01L, /* 3ffed4bb9e1c619e07cd2edde163d84d */ + -3.50775517955306954815090901168305659e-35L, /* bf8c75022dc63e3d51e25fd52b3250bd */ /* sin(x) = 0.66ff380ba0144109e39a320b0a3fa5fd65ea0585bcbf9b1a769a9b0334576c658139e1a1cbe */ - 4.02331831777773111217105598880982387e-01L, /* 3ffd9bfce02e805104278e68c82c28ff */ - -1.95678722882848174723569916504871563e-35L, /* bf8ba029a15fa7a434064e5896564fcd */ + 4.02331831777773111217105598880982387e-01L, /* 3ffd9bfce02e805104278e68c82c28ff */ + -1.95678722882848174723569916504871563e-35L, /* bf8ba029a15fa7a434064e5896564fcd */ /* x = 4.21875000000000000000000000000000000e-01 3ffdb000000000000000000000000000 */ /* cos(x) = 0.e98dfc6c6be031e60dd3089cbdd18a75b1f6b2c1e97f79225202f03dbea45b07a5ec4efc062 */ - 9.12322784872117846492029542047341734e-01L, /* 3ffed31bf8d8d7c063cc1ba611397ba3 */ - 7.86903886556373674267948132178845568e-36L, /* 3f8a4eb63ed6583d2fef244a405e07b8 */ + 9.12322784872117846492029542047341734e-01L, /* 3ffed31bf8d8d7c063cc1ba611397ba3 */ + 7.86903886556373674267948132178845568e-36L, /* 3f8a4eb63ed6583d2fef244a405e07b8 */ /* sin(x) = 0.68d32473143327973bc712bcc4ccddc47630d755850c0655243b205934dc49ffed8eb76adcb */ - 4.09471777053295066122694027011452236e-01L, /* 3ffda34c91cc50cc9e5cef1c4af31333 */ - 2.23945241468457597921655785729821354e-35L, /* 3f8bdc47630d755850c0655243b20593 */ + 4.09471777053295066122694027011452236e-01L, /* 3ffda34c91cc50cc9e5cef1c4af31333 */ + 2.23945241468457597921655785729821354e-35L, /* 3f8bdc47630d755850c0655243b20593 */ /* x = 4.29687500000000000000000000000000000e-01 3ffdb800000000000000000000000000 */ /* cos(x) = 0.e8ba8393eca7821aa563d83491b6101189b3b101c3677f73d7bad7c10f9ee02b7ab4009739a */ - 9.09095977415431051650381735684476417e-01L, /* 3ffed1750727d94f04354ac7b069236c */ - 1.20886014028444155733776025085677953e-35L, /* 3f8b01189b3b101c3677f73d7bad7c11 */ + 9.09095977415431051650381735684476417e-01L, /* 3ffed1750727d94f04354ac7b069236c */ + 1.20886014028444155733776025085677953e-35L, /* 3f8b01189b3b101c3677f73d7bad7c11 */ /* sin(x) = 0.6aa56d8e8249db4eb60a761fe3f9e559be456b9e13349ca99b0bfb787f22b95db3b70179615 */ - 4.16586730282041119259112448831069657e-01L, /* 3ffdaa95b63a09276d3ad829d87f8fe8 */ - -2.00488106831998813675438269796963612e-35L, /* bf8baa641ba9461eccb635664f404878 */ + 4.16586730282041119259112448831069657e-01L, /* 3ffdaa95b63a09276d3ad829d87f8fe8 */ + -2.00488106831998813675438269796963612e-35L, /* bf8baa641ba9461eccb635664f404878 */ /* x = 4.37500000000000000000000000000000000e-01 3ffdc000000000000000000000000000 */ /* cos(x) = 0.e7e367d2956cfb16b6aa11e5419cd0057f5c132a6455bf064297e6a76fe2b72bb630d6d50ff */ - 9.05813683425936420744516660652700258e-01L, /* 3ffecfc6cfa52ad9f62d6d5423ca833a */ - -3.60950307605941169775676563004467163e-35L, /* bf8c7fd4051f66acdd5207cdeb40cac5 */ + 9.05813683425936420744516660652700258e-01L, /* 3ffecfc6cfa52ad9f62d6d5423ca833a */ + -3.60950307605941169775676563004467163e-35L, /* bf8c7fd4051f66acdd5207cdeb40cac5 */ /* sin(x) = 0.6c760c14c8585a51dbd34660ae6c52ac7036a0b40887a0b63724f8b4414348c3063a637f457 */ - 4.23676257203938010361683988031102480e-01L, /* 3ffdb1d83053216169476f4d1982b9b1 */ - 1.40484456388654470329473096579312595e-35L, /* 3f8b2ac7036a0b40887a0b63724f8b44 */ + 4.23676257203938010361683988031102480e-01L, /* 3ffdb1d83053216169476f4d1982b9b1 */ + 1.40484456388654470329473096579312595e-35L, /* 3f8b2ac7036a0b40887a0b63724f8b44 */ /* x = 4.45312500000000000000000000000000000e-01 3ffdc800000000000000000000000000 */ /* cos(x) = 0.e708ac84d4172a3e2737662213429e14021074d7e702e77d72a8f1101a7e70410df8273e9aa */ - 9.02476103237941504925183272675895999e-01L, /* 3ffece115909a82e547c4e6ecc442685 */ - 2.26282899501344419018306295680210602e-35L, /* 3f8be14021074d7e702e77d72a8f1102 */ + 9.02476103237941504925183272675895999e-01L, /* 3ffece115909a82e547c4e6ecc442685 */ + 2.26282899501344419018306295680210602e-35L, /* 3f8be14021074d7e702e77d72a8f1102 */ /* sin(x) = 0.6e44f8c36eb10a1c752d093c00f4d47ba446ac4c215d26b0316442f168459e677d06e7249e3 */ - 4.30739925110803197216321517850849190e-01L, /* 3ffdb913e30dbac42871d4b424f003d3 */ - 1.54096780001629398850891218396761548e-35L, /* 3f8b47ba446ac4c215d26b0316442f17 */ + 4.30739925110803197216321517850849190e-01L, /* 3ffdb913e30dbac42871d4b424f003d3 */ + 1.54096780001629398850891218396761548e-35L, /* 3f8b47ba446ac4c215d26b0316442f17 */ /* x = 4.53125000000000000000000000000000000e-01 3ffdd000000000000000000000000000 */ /* cos(x) = 0.e62a551594b970a770b15d41d4c0e483e47aca550111df6966f9e7ac3a94ae49e6a71eb031e */ - 8.99083440560138456216544929209379307e-01L, /* 3ffecc54aa2b2972e14ee162ba83a982 */ - -2.06772615490904370666670275154751976e-35L, /* bf8bb7c1b8535aafeee209699061853c */ + 8.99083440560138456216544929209379307e-01L, /* 3ffecc54aa2b2972e14ee162ba83a982 */ + -2.06772615490904370666670275154751976e-35L, /* bf8bb7c1b8535aafeee209699061853c */ /* sin(x) = 0.70122c5ec5028c8cff33abf4fd340ccc382e038379b09cf04f9a52692b10b72586060cbb001 */ - 4.37777302872755132861618974702796680e-01L, /* 3ffdc048b17b140a3233fcceafd3f4d0 */ - 9.62794364503442612477117426033922467e-36L, /* 3f8a998705c0706f36139e09f34a4d25 */ + 4.37777302872755132861618974702796680e-01L, /* 3ffdc048b17b140a3233fcceafd3f4d0 */ + 9.62794364503442612477117426033922467e-36L, /* 3f8a998705c0706f36139e09f34a4d25 */ /* x = 4.60937500000000000000000000000000000e-01 3ffdd800000000000000000000000000 */ /* cos(x) = 0.e54864fe33e8575cabf5bd0e5cf1b1a8bc7c0d5f61702450fa6b6539735820dd2603ae355d5 */ - 8.95635902463170698900570000446256350e-01L, /* 3ffeca90c9fc67d0aeb957eb7a1cb9e3 */ - 3.73593741659866883088620495542311808e-35L, /* 3f8c8d45e3e06afb0b812287d35b29cc */ + 8.95635902463170698900570000446256350e-01L, /* 3ffeca90c9fc67d0aeb957eb7a1cb9e3 */ + 3.73593741659866883088620495542311808e-35L, /* 3f8c8d45e3e06afb0b812287d35b29cc */ /* sin(x) = 0.71dd9fb1ff4677853acb970a9f6729c6e3aac247b1c57cea66c77413f1f98e8b9e98e49d851 */ - 4.44787960964527211433056012529525211e-01L, /* 3ffdc7767ec7fd19de14eb2e5c2a7d9d */ - -1.67187936511493678007508371613954899e-35L, /* bf8b6391c553db84e3a831599388bec1 */ + 4.44787960964527211433056012529525211e-01L, /* 3ffdc7767ec7fd19de14eb2e5c2a7d9d */ + -1.67187936511493678007508371613954899e-35L, /* bf8b6391c553db84e3a831599388bec1 */ /* x = 4.68750000000000000000000000000000000e-01 3ffde000000000000000000000000000 */ /* cos(x) = 0.e462dfc670d421ab3d1a15901228f146a0547011202bf5ab01f914431859aef577966bc4fa4 */ - 8.92133699366994404723900253723788575e-01L, /* 3ffec8c5bf8ce1a843567a342b202452 */ - -1.10771937602567314732693079264692504e-35L, /* bf8ad72bf571fddbfa814a9fc0dd779d */ + 8.92133699366994404723900253723788575e-01L, /* 3ffec8c5bf8ce1a843567a342b202452 */ + -1.10771937602567314732693079264692504e-35L, /* bf8ad72bf571fddbfa814a9fc0dd779d */ /* sin(x) = 0.73a74b8f52947b681baf6928eb3fb021769bf4779bad0e3aa9b1cdb75ec60aad9fc63ff19d5 */ - 4.51771471491683776581688750134062870e-01L, /* 3ffdce9d2e3d4a51eda06ebda4a3acff */ - -1.19387223016472295893794387275284505e-35L, /* bf8afbd12c81710c8a5e38aac9c64914 */ + 4.51771471491683776581688750134062870e-01L, /* 3ffdce9d2e3d4a51eda06ebda4a3acff */ + -1.19387223016472295893794387275284505e-35L, /* bf8afbd12c81710c8a5e38aac9c64914 */ /* x = 4.76562500000000000000000000000000000e-01 3ffde800000000000000000000000000 */ /* cos(x) = 0.e379c9045f29d517c4808aa497c2057b2b3d109e76c0dc302d4d0698b36e3f0bdbf33d8e952 */ - 8.88577045028035543317609023116020980e-01L, /* 3ffec6f39208be53aa2f890115492f84 */ - 4.12354278954664731443813655177022170e-36L, /* 3f895ecacf44279db0370c0b5341a62d */ + 8.88577045028035543317609023116020980e-01L, /* 3ffec6f39208be53aa2f890115492f84 */ + 4.12354278954664731443813655177022170e-36L, /* 3f895ecacf44279db0370c0b5341a62d */ /* sin(x) = 0.756f28d011d98528a44a75fc29c779bd734ecdfb582fdb74b68a4c4c4be54cfd0b2d3ad292f */ - 4.58727408216736592377295028972874773e-01L, /* 3ffdd5bca340476614a29129d7f0a71e */ - -4.70946994194182908929251719575431779e-36L, /* bf8990a32c4c8129f40922d25d6ceced */ + 4.58727408216736592377295028972874773e-01L, /* 3ffdd5bca340476614a29129d7f0a71e */ + -4.70946994194182908929251719575431779e-36L, /* bf8990a32c4c8129f40922d25d6ceced */ /* x = 4.84375000000000000000000000000000000e-01 3ffdf000000000000000000000000000 */ /* cos(x) = 0.e28d245c58baef72225e232abc003c4366acd9eb4fc2808c2ab7fe7676cf512ac7f945ae5fb */ - 8.84966156526143291697296536966647926e-01L, /* 3ffec51a48b8b175dee444bc46557800 */ - 4.53370570288325630442037826313462165e-35L, /* 3f8ce21b3566cf5a7e14046155bff3b4 */ + 8.84966156526143291697296536966647926e-01L, /* 3ffec51a48b8b175dee444bc46557800 */ + 4.53370570288325630442037826313462165e-35L, /* 3f8ce21b3566cf5a7e14046155bff3b4 */ /* sin(x) = 0.77353054ca72690d4c6e171fd99e6b39fa8e1ede5f052fd2964534c75340970a3a9cd3c5c32 */ - 4.65655346585160182681199512507546779e-01L, /* 3ffddcd4c15329c9a43531b85c7f667a */ - -1.56282598978971872478619772155305961e-35L, /* bf8b4c60571e121a0fad02d69bacb38b */ + 4.65655346585160182681199512507546779e-01L, /* 3ffddcd4c15329c9a43531b85c7f667a */ + -1.56282598978971872478619772155305961e-35L, /* bf8b4c60571e121a0fad02d69bacb38b */ /* x = 4.92187500000000000000000000000000000e-01 3ffdf800000000000000000000000000 */ /* cos(x) = 0.e19cf580eeec046aa1422fa74807ecefb2a1911c94e7b5f20a00f70022d940193691e5bd790 */ - 8.81301254251340599140161908298100173e-01L, /* 3ffec339eb01ddd808d542845f4e9010 */ - -1.43419192312116687783945619009629445e-35L, /* bf8b3104d5e6ee36b184a0df5ff08ffe */ + 8.81301254251340599140161908298100173e-01L, /* 3ffec339eb01ddd808d542845f4e9010 */ + -1.43419192312116687783945619009629445e-35L, /* bf8b3104d5e6ee36b184a0df5ff08ffe */ /* sin(x) = 0.78f95b0560a9a3bd6df7bd981dc38c61224d08bc20631ea932e605e53b579e9e0767dfcbbcb */ - 4.72554863751304451146551317808516942e-01L, /* 3ffde3e56c1582a68ef5b7def660770e */ - 9.31324774957768018850224267625371204e-36L, /* 3f8a8c2449a117840c63d5265cc0bca7 */ + 4.72554863751304451146551317808516942e-01L, /* 3ffde3e56c1582a68ef5b7def660770e */ + 9.31324774957768018850224267625371204e-36L, /* 3f8a8c2449a117840c63d5265cc0bca7 */ /* x = 5.00000000000000000000000000000000000e-01 3ffe0000000000000000000000000000 */ /* cos(x) = 0.e0a94032dbea7cedbddd9da2fafad98556566b3a89f43eabd72350af3e8b19e801204d8fe2e */ - 8.77582561890372716116281582603829681e-01L, /* 3ffec1528065b7d4f9db7bbb3b45f5f6 */ - -2.89484960181363924855192538540698851e-35L, /* bf8c33d54d4ca62bb05e0aa146e57a86 */ + 8.77582561890372716116281582603829681e-01L, /* 3ffec1528065b7d4f9db7bbb3b45f5f6 */ + -2.89484960181363924855192538540698851e-35L, /* bf8c33d54d4ca62bb05e0aa146e57a86 */ /* sin(x) = 0.7abba1d12c17bfa1d92f0d93f60ded9992f45b4fcaf13cd58b303693d2a0db47db35ae8a3a9 */ - 4.79425538604203000273287935215571402e-01L, /* 3ffdeaee8744b05efe8764bc364fd838 */ - -1.38426977616718318950175848639381926e-35L, /* bf8b2666d0ba4b0350ec32a74cfc96c3 */ + 4.79425538604203000273287935215571402e-01L, /* 3ffdeaee8744b05efe8764bc364fd838 */ + -1.38426977616718318950175848639381926e-35L, /* bf8b2666d0ba4b0350ec32a74cfc96c3 */ /* x = 5.07812500000000000000000000000000000e-01 3ffe0400000000000000000000000000 */ /* cos(x) = 0.dfb20840f3a9b36f7ae2c515342890b5ec583b8366cc2b55029e95094d31112383f2553498b */ - 8.73810306413054508282556837071377159e-01L, /* 3ffebf641081e75366def5c58a2a6851 */ - 1.25716864497849302237218128599994785e-35L, /* 3f8b0b5ec583b8366cc2b55029e95095 */ + 8.73810306413054508282556837071377159e-01L, /* 3ffebf641081e75366def5c58a2a6851 */ + 1.25716864497849302237218128599994785e-35L, /* 3f8b0b5ec583b8366cc2b55029e95095 */ /* sin(x) = 0.7c7bfdaf13e5ed17212f8a7525bfb113aba6c0741b5362bb8d59282a850b63716bca0c910f0 */ - 4.86266951793275574311011306895834993e-01L, /* 3ffdf1eff6bc4f97b45c84be29d496ff */ - -1.12269393250914752644352376448094271e-35L, /* bf8add8a8b27f17c9593a88e54dafaaf */ + 4.86266951793275574311011306895834993e-01L, /* 3ffdf1eff6bc4f97b45c84be29d496ff */ + -1.12269393250914752644352376448094271e-35L, /* bf8add8a8b27f17c9593a88e54dafaaf */ /* x = 5.15625000000000000000000000000000000e-01 3ffe0800000000000000000000000000 */ /* cos(x) = 0.deb7518814a7a931bbcc88c109cd41c50bf8bb48f20ae8c36628d1d3d57574f7dc58f27d91c */ - 8.69984718058417388828915599901466243e-01L, /* 3ffebd6ea310294f526377991182139b */ - -4.68168638300575626782741319792183837e-35L, /* bf8cf1d7a03a25b86fa8b9e4ceb97161 */ + 8.69984718058417388828915599901466243e-01L, /* 3ffebd6ea310294f526377991182139b */ + -4.68168638300575626782741319792183837e-35L, /* bf8cf1d7a03a25b86fa8b9e4ceb97161 */ /* sin(x) = 0.7e3a679daaf25c676542bcb4028d0964172961c921823a4ef0c3a9070d886dbd073f6283699 */ - 4.93078685753923057265136552753487121e-01L, /* 3ffdf8e99e76abc9719d950af2d00a34 */ - 7.06498693112535056352301101088624950e-36L, /* 3f8a2c82e52c3924304749de187520e2 */ + 4.93078685753923057265136552753487121e-01L, /* 3ffdf8e99e76abc9719d950af2d00a34 */ + 7.06498693112535056352301101088624950e-36L, /* 3f8a2c82e52c3924304749de187520e2 */ /* x = 5.23437500000000000000000000000000000e-01 3ffe0c00000000000000000000000000 */ /* cos(x) = 0.ddb91ff318799172bd2452d0a3889f5169c64a0094bcf0b8aa7dcf0d7640a2eba68955a80be */ - 8.66106030320656714696616831654267220e-01L, /* 3ffebb723fe630f322e57a48a5a14711 */ - 2.35610597588322493119667003904687628e-35L, /* 3f8bf5169c64a0094bcf0b8aa7dcf0d7 */ + 8.66106030320656714696616831654267220e-01L, /* 3ffebb723fe630f322e57a48a5a14711 */ + 2.35610597588322493119667003904687628e-35L, /* 3f8bf5169c64a0094bcf0b8aa7dcf0d7 */ /* sin(x) = 0.7ff6d8a34bd5e8fa54c97482db5159df1f24e8038419c0b448b9eea8939b5d4dfcf40900257 */ - 4.99860324733013463819556536946425724e-01L, /* 3ffdffdb628d2f57a3e95325d20b6d45 */ - 1.94636052312235297538564591686645139e-35L, /* 3f8b9df1f24e8038419c0b448b9eea89 */ + 4.99860324733013463819556536946425724e-01L, /* 3ffdffdb628d2f57a3e95325d20b6d45 */ + 1.94636052312235297538564591686645139e-35L, /* 3f8b9df1f24e8038419c0b448b9eea89 */ /* x = 5.31250000000000000000000000000000000e-01 3ffe1000000000000000000000000000 */ /* cos(x) = 0.dcb7777ac420705168f31e3eb780ce9c939ecada62843b54522f5407eb7f21e556059fcd734 */ - 8.62174479934880504367162510253324274e-01L, /* 3ffeb96eeef58840e0a2d1e63c7d6f02 */ - -3.71556818317533582234562471835771823e-35L, /* bf8c8b1b6309a92cebde255d6e855fc1 */ + 8.62174479934880504367162510253324274e-01L, /* 3ffeb96eeef58840e0a2d1e63c7d6f02 */ + -3.71556818317533582234562471835771823e-35L, /* bf8c8b1b6309a92cebde255d6e855fc1 */ /* sin(x) = 0.81b149ce34caa5a4e650f8d09fd4d6aa74206c32ca951a93074c83b2d294d25dbb0f7fdfad2 */ - 5.06611454814257367642296000893867192e-01L, /* 3ffe0362939c69954b49cca1f1a13faa */ - -3.10963699824274155702706043065967062e-35L, /* bf8c4aac5efc9e69ab572b67c59be269 */ + 5.06611454814257367642296000893867192e-01L, /* 3ffe0362939c69954b49cca1f1a13faa */ + -3.10963699824274155702706043065967062e-35L, /* bf8c4aac5efc9e69ab572b67c59be269 */ /* x = 5.39062500000000000000000000000000000e-01 3ffe1400000000000000000000000000 */ /* cos(x) = 0.dbb25c25b8260c14f6e7bc98ec991b70c65335198b0ab628bad20cc7b229d4dd62183cfa055 */ - 8.58190306862660347046629564970494649e-01L, /* 3ffeb764b84b704c1829edcf7931d932 */ - 2.06439574601190798155563653000684861e-35L, /* 3f8bb70c65335198b0ab628bad20cc7b */ + 8.58190306862660347046629564970494649e-01L, /* 3ffeb764b84b704c1829edcf7931d932 */ + 2.06439574601190798155563653000684861e-35L, /* 3f8bb70c65335198b0ab628bad20cc7b */ /* sin(x) = 0.8369b434a372da7eb5c8a71fe36ce1e0b2b493f6f5cb2e38bcaec2a556b3678c401940d1c3c */ - 5.13331663943471218288801270215706878e-01L, /* 3ffe06d3686946e5b4fd6b914e3fc6da */ - -2.26614796466671970772244932848067224e-35L, /* bf8be1f4d4b6c090a34d1c743513d5ab */ + 5.13331663943471218288801270215706878e-01L, /* 3ffe06d3686946e5b4fd6b914e3fc6da */ + -2.26614796466671970772244932848067224e-35L, /* bf8be1f4d4b6c090a34d1c743513d5ab */ /* x = 5.46875000000000000000000000000000000e-01 3ffe1800000000000000000000000000 */ /* cos(x) = 0.daa9d20860827063fde51c09e855e9932e1b17143e7244fd267a899d41ae1f3bc6a0ec42e27 */ - 8.54153754277385385143451785105103176e-01L, /* 3ffeb553a410c104e0c7fbca3813d0ac */ - -1.68707534013095152873222061722573172e-35L, /* bf8b66cd1e4e8ebc18dbb02d9857662c */ + 8.54153754277385385143451785105103176e-01L, /* 3ffeb553a410c104e0c7fbca3813d0ac */ + -1.68707534013095152873222061722573172e-35L, /* bf8b66cd1e4e8ebc18dbb02d9857662c */ /* sin(x) = 0.852010f4f0800521378bd8dd614753d080c2e9e0775ffc609947b9132f5357404f464f06a58 */ - 5.20020541953727004760213699874674730e-01L, /* 3ffe0a4021e9e1000a426f17b1bac28f */ - -3.32415021330884924833711842866896734e-35L, /* bf8c617bf9e8b0fc45001cfb35c23767 */ + 5.20020541953727004760213699874674730e-01L, /* 3ffe0a4021e9e1000a426f17b1bac28f */ + -3.32415021330884924833711842866896734e-35L, /* bf8c617bf9e8b0fc45001cfb35c23767 */ /* x = 5.54687500000000000000000000000000000e-01 3ffe1c00000000000000000000000000 */ /* cos(x) = 0.d99ddd44e44a43d4d4a3a3ed95204106fd54d78e8c7684545c0da0b7c2c72be7a89b7c182ad */ - 8.50065068549420263957072899177793617e-01L, /* 3ffeb33bba89c89487a9a94747db2a41 */ - -4.73753917078785974356016104842568442e-35L, /* bf8cf7c81559438b9c4bdd5d1f92fa42 */ + 8.50065068549420263957072899177793617e-01L, /* 3ffeb33bba89c89487a9a94747db2a41 */ + -4.73753917078785974356016104842568442e-35L, /* bf8cf7c81559438b9c4bdd5d1f92fa42 */ /* sin(x) = 0.86d45935ab396cb4e421e822dee54f3562dfcefeaa782184c23401d231f5ad981a1cc195b18 */ - 5.26677680590386730710789410624833901e-01L, /* 3ffe0da8b26b5672d969c843d045bdcb */ - -3.67066148195515214077582496518566735e-35L, /* bf8c8654e901880aac3ef3d9ee5ff16e */ + 5.26677680590386730710789410624833901e-01L, /* 3ffe0da8b26b5672d969c843d045bdcb */ + -3.67066148195515214077582496518566735e-35L, /* bf8c8654e901880aac3ef3d9ee5ff16e */ /* x = 5.62500000000000000000000000000000000e-01 3ffe2000000000000000000000000000 */ /* cos(x) = 0.d88e820b1526311dd561efbc0c1a9a5375eb26f65d246c5744b13ca26a7e0fd42556da843c8 */ - 8.45924499231067954459723078597493262e-01L, /* 3ffeb11d04162a4c623baac3df781835 */ - 1.98054947141989878179164342925274053e-35L, /* 3f8ba5375eb26f65d246c5744b13ca27 */ + 8.45924499231067954459723078597493262e-01L, /* 3ffeb11d04162a4c623baac3df781835 */ + 1.98054947141989878179164342925274053e-35L, /* 3f8ba5375eb26f65d246c5744b13ca27 */ /* sin(x) = 0.88868625b4e1dbb2313310133022527200c143a5cb16637cb7daf8ade82459ff2e98511f40f */ - 5.33302673536020173329131103308161529e-01L, /* 3ffe110d0c4b69c3b764626620266045 */ - -3.42715291319551615996993795226755157e-35L, /* bf8c6c6ff9f5e2d1a74ce41a41283a91 */ + 5.33302673536020173329131103308161529e-01L, /* 3ffe110d0c4b69c3b764626620266045 */ + -3.42715291319551615996993795226755157e-35L, /* bf8c6c6ff9f5e2d1a74ce41a41283a91 */ /* x = 5.70312500000000000000000000000000000e-01 3ffe2400000000000000000000000000 */ /* cos(x) = 0.d77bc4985e93a607c9d868b906bbc6bbe3a04258814acb0358468b826fc91bd4d814827f65e */ - 8.41732299041338366963111794309701085e-01L, /* 3ffeaef78930bd274c0f93b0d1720d78 */ - -4.30821936750410026005408345400225948e-35L, /* bf8cca20e2fded3bf5a9a7e53dcba3ed */ + 8.41732299041338366963111794309701085e-01L, /* 3ffeaef78930bd274c0f93b0d1720d78 */ + -4.30821936750410026005408345400225948e-35L, /* bf8cca20e2fded3bf5a9a7e53dcba3ed */ /* sin(x) = 0.8a3690fc5bfc11bf9535e2739a8512f448a41251514bbed7fc18d530f9b4650fcbb2861b0aa */ - 5.39895116435204405041660709903993340e-01L, /* 3ffe146d21f8b7f8237f2a6bc4e7350a */ - 1.42595803521626714477253741404712093e-35L, /* 3f8b2f448a41251514bbed7fc18d5310 */ + 5.39895116435204405041660709903993340e-01L, /* 3ffe146d21f8b7f8237f2a6bc4e7350a */ + 1.42595803521626714477253741404712093e-35L, /* 3f8b2f448a41251514bbed7fc18d5310 */ /* x = 5.78125000000000000000000000000000000e-01 3ffe2800000000000000000000000000 */ /* cos(x) = 0.d665a937b4ef2b1f6d51bad6d988a4419c1d7051faf31a9efa151d7631117efac03713f950a */ - 8.37488723850523685315353348917240617e-01L, /* 3ffeaccb526f69de563edaa375adb311 */ - 2.72761997872084533045777718677326179e-35L, /* 3f8c220ce0eb828fd798d4f7d0a8ebb2 */ + 8.37488723850523685315353348917240617e-01L, /* 3ffeaccb526f69de563edaa375adb311 */ + 2.72761997872084533045777718677326179e-35L, /* 3f8c220ce0eb828fd798d4f7d0a8ebb2 */ /* sin(x) = 0.8be472f9776d809af2b88171243d63d66dfceeeb739cc894e023fbc165a0e3f26ff729c5d57 */ - 5.46454606919203564403349553749411001e-01L, /* 3ffe17c8e5f2eedb0135e57102e2487b */ - -2.11870230730160315420936523771864858e-35L, /* bf8bc29920311148c63376b1fdc043ea */ + 5.46454606919203564403349553749411001e-01L, /* 3ffe17c8e5f2eedb0135e57102e2487b */ + -2.11870230730160315420936523771864858e-35L, /* bf8bc29920311148c63376b1fdc043ea */ /* x = 5.85937500000000000000000000000000000e-01 3ffe2c00000000000000000000000000 */ /* cos(x) = 0.d54c3441844897fc8f853f0655f1ba695eba9fbfd7439dbb1171d862d9d9146ca5136f825ac */ - 8.33194032664581363070224042208032321e-01L, /* 3ffeaa98688308912ff91f0a7e0cabe3 */ - 4.39440050052045486567668031751259899e-35L, /* 3f8cd34af5d4fdfeba1cedd88b8ec317 */ + 8.33194032664581363070224042208032321e-01L, /* 3ffeaa98688308912ff91f0a7e0cabe3 */ + 4.39440050052045486567668031751259899e-35L, /* 3f8cd34af5d4fdfeba1cedd88b8ec317 */ /* sin(x) = 0.8d902565817ee7839bce3cd128060119492cd36d42d82ada30d7f8bde91324808377ddbf5d4 */ - 5.52980744630527369849695082681623667e-01L, /* 3ffe1b204acb02fdcf07379c79a2500c */ - 8.26624790417342895897164123189984127e-37L, /* 3f8719492cd36d42d82ada30d7f8bde9 */ + 5.52980744630527369849695082681623667e-01L, /* 3ffe1b204acb02fdcf07379c79a2500c */ + 8.26624790417342895897164123189984127e-37L, /* 3f8719492cd36d42d82ada30d7f8bde9 */ /* x = 5.93750000000000000000000000000000000e-01 3ffe3000000000000000000000000000 */ /* cos(x) = 0.d42f6a1b9f0168cdf031c2f63c8d9304d86f8d34cb1d5fccb68ca0f2241427fc18d1fd5bbdf */ - 8.28848487609325734810171790119116638e-01L, /* 3ffea85ed4373e02d19be06385ec791b */ - 1.43082508100496581719048175506239770e-35L, /* 3f8b304d86f8d34cb1d5fccb68ca0f22 */ + 8.28848487609325734810171790119116638e-01L, /* 3ffea85ed4373e02d19be06385ec791b */ + 1.43082508100496581719048175506239770e-35L, /* 3f8b304d86f8d34cb1d5fccb68ca0f22 */ /* sin(x) = 0.8f39a191b2ba6122a3fa4f41d5a3ffd421417d46f19a22230a14f7fcc8fce5c75b4b28b29d1 */ - 5.59473131247366877384844006003116688e-01L, /* 3ffe1e7343236574c24547f49e83ab48 */ - -1.28922620524163922306886952100992796e-37L, /* bf845ef5f415c8732eeee7af584019b8 */ + 5.59473131247366877384844006003116688e-01L, /* 3ffe1e7343236574c24547f49e83ab48 */ + -1.28922620524163922306886952100992796e-37L, /* bf845ef5f415c8732eeee7af584019b8 */ /* x = 6.01562500000000000000000000000000000e-01 3ffe3400000000000000000000000000 */ /* cos(x) = 0.d30f4f392c357ab0661c5fa8a7d9b26627846fef214b1d19a22379ff9eddba087cf410eb097 */ - 8.24452353914429207485643598212356053e-01L, /* 3ffea61e9e72586af560cc38bf514fb3 */ - 3.79160239225080026987031418939026741e-35L, /* 3f8c93313c237f790a58e8cd111bcffd */ + 8.24452353914429207485643598212356053e-01L, /* 3ffea61e9e72586af560cc38bf514fb3 */ + 3.79160239225080026987031418939026741e-35L, /* 3f8c93313c237f790a58e8cd111bcffd */ /* sin(x) = 0.90e0e0d81ca678796cc92c8ea8c2815bc72ca78abe571bfa8576aacc571e096a33237e0e830 */ - 5.65931370507905990773159095689276114e-01L, /* 3ffe21c1c1b0394cf0f2d992591d5185 */ - 1.02202775968053982310991962521535027e-36L, /* 3f875bc72ca78abe571bfa8576aacc57 */ + 5.65931370507905990773159095689276114e-01L, /* 3ffe21c1c1b0394cf0f2d992591d5185 */ + 1.02202775968053982310991962521535027e-36L, /* 3f875bc72ca78abe571bfa8576aacc57 */ /* x = 6.09375000000000000000000000000000000e-01 3ffe3800000000000000000000000000 */ /* cos(x) = 0.d1ebe81a95ee752e48a26bcd32d6e922d7eb44b8ad2232f6930795e84b56317269b9dd1dfa6 */ - 8.20005899897234008255550633876556043e-01L, /* 3ffea3d7d0352bdcea5c9144d79a65ae */ - -1.72008811955230823416724332297991247e-35L, /* bf8b6dd2814bb4752ddcd096cf86a17b */ + 8.20005899897234008255550633876556043e-01L, /* 3ffea3d7d0352bdcea5c9144d79a65ae */ + -1.72008811955230823416724332297991247e-35L, /* bf8b6dd2814bb4752ddcd096cf86a17b */ /* sin(x) = 0.9285dc9bc45dd9ea3d02457bcce59c4175aab6ff7929a8d287195525fdace200dba032874fb */ - 5.72355068234507240384953706824503608e-01L, /* 3ffe250bb93788bbb3d47a048af799cb */ - 2.12572273479933123944580199464514529e-35L, /* 3f8bc4175aab6ff7929a8d2871955260 */ + 5.72355068234507240384953706824503608e-01L, /* 3ffe250bb93788bbb3d47a048af799cb */ + 2.12572273479933123944580199464514529e-35L, /* 3f8bc4175aab6ff7929a8d2871955260 */ /* x = 6.17187500000000000000000000000000000e-01 3ffe3c00000000000000000000000000 */ /* cos(x) = 0.d0c5394d772228195e25736c03574707de0af1ca344b13bd3914bfe27518e9e426f5deff1e1 */ - 8.15509396946375476876345384201386217e-01L, /* 3ffea18a729aee445032bc4ae6d806af */ - -4.28589138410712954051679139949341961e-35L, /* bf8cc7c10fa871ae5da76216375a00ec */ + 8.15509396946375476876345384201386217e-01L, /* 3ffea18a729aee445032bc4ae6d806af */ + -4.28589138410712954051679139949341961e-35L, /* bf8cc7c10fa871ae5da76216375a00ec */ /* sin(x) = 0.94288e48bd0335fc41c4cbd2920497a8f5d1d8185c99fa0081f90c27e2a53ffdd208a0dbe69 */ - 5.78743832357770354521111378581385347e-01L, /* 3ffe28511c917a066bf8838997a52409 */ - 1.77998063432551282609698670002456093e-35L, /* 3f8b7a8f5d1d8185c99fa0081f90c27e */ + 5.78743832357770354521111378581385347e-01L, /* 3ffe28511c917a066bf8838997a52409 */ + 1.77998063432551282609698670002456093e-35L, /* 3f8b7a8f5d1d8185c99fa0081f90c27e */ /* x = 6.25000000000000000000000000000000000e-01 3ffe4000000000000000000000000000 */ /* cos(x) = 0.cf9b476c897c25c5bfe750dd3f308eaf7bcc1ed00179a256870f4200445043dcdb1974b5878 */ - 8.10963119505217902189534803941080724e-01L, /* 3ffe9f368ed912f84b8b7fcea1ba7e61 */ - 1.10481292856794436426051402418804358e-35L, /* 3f8ad5ef7983da002f344ad0e1e84009 */ + 8.10963119505217902189534803941080724e-01L, /* 3ffe9f368ed912f84b8b7fcea1ba7e61 */ + 1.10481292856794436426051402418804358e-35L, /* 3f8ad5ef7983da002f344ad0e1e84009 */ /* sin(x) = 0.95c8ef544210ec0b91c49bd2aa09e8515fa61a156ebb10f5f8c232a6445b61ebf3c2ec268f9 */ - 5.85097272940462154805399314150080459e-01L, /* 3ffe2b91dea88421d817238937a55414 */ - -1.78164576278056195136525335403380464e-35L, /* bf8b7aea059e5ea9144ef0a073dcd59c */ + 5.85097272940462154805399314150080459e-01L, /* 3ffe2b91dea88421d817238937a55414 */ + -1.78164576278056195136525335403380464e-35L, /* bf8b7aea059e5ea9144ef0a073dcd59c */ /* x = 6.32812500000000000000000000000000000e-01 3ffe4400000000000000000000000000 */ /* cos(x) = 0.ce6e171f92f2e27f32225327ec440ddaefae248413efc0e58ceee1ae369aabe73f88c87ed1a */ - 8.06367345055103913698795406077297399e-01L, /* 3ffe9cdc2e3f25e5c4fe6444a64fd888 */ - 1.04235088143133625463876245029180850e-35L, /* 3f8abb5df5c490827df81cb19ddc35c7 */ + 8.06367345055103913698795406077297399e-01L, /* 3ffe9cdc2e3f25e5c4fe6444a64fd888 */ + 1.04235088143133625463876245029180850e-35L, /* 3f8abb5df5c490827df81cb19ddc35c7 */ /* sin(x) = 0.9766f93cd18413a6aafc1cfc6fc28abb6817bf94ce349901ae3f48c3215d3eb60acc5f78903 */ - 5.91415002201316315087000225758031236e-01L, /* 3ffe2ecdf279a308274d55f839f8df85 */ - 8.07390238063560077355762466502569603e-36L, /* 3f8a576d02f7f299c6932035c7e91864 */ + 5.91415002201316315087000225758031236e-01L, /* 3ffe2ecdf279a308274d55f839f8df85 */ + 8.07390238063560077355762466502569603e-36L, /* 3f8a576d02f7f299c6932035c7e91864 */ /* x = 6.40625000000000000000000000000000000e-01 3ffe4800000000000000000000000000 */ /* cos(x) = 0.cd3dad1b5328a2e459f993f4f5108819faccbc4eeba9604e81c7adad51cc8a2561631a06826 */ - 8.01722354098418450607492605652964208e-01L, /* 3ffe9a7b5a36a65145c8b3f327e9ea21 */ - 6.09487851305233089325627939458963741e-36L, /* 3f8a033f599789dd752c09d038f5b5aa */ + 8.01722354098418450607492605652964208e-01L, /* 3ffe9a7b5a36a65145c8b3f327e9ea21 */ + 6.09487851305233089325627939458963741e-36L, /* 3f8a033f599789dd752c09d038f5b5aa */ /* sin(x) = 0.9902a58a45e27bed68412b426b675ed503f54d14c8172e0d373f42cadf04daf67319a7f94be */ - 5.97696634538701531238647618967334337e-01L, /* 3ffe32054b148bc4f7dad0825684d6cf */ - -2.49527608940873714527427941350461554e-35L, /* bf8c0957e0559759bf468f964605e9a9 */ + 5.97696634538701531238647618967334337e-01L, /* 3ffe32054b148bc4f7dad0825684d6cf */ + -2.49527608940873714527427941350461554e-35L, /* bf8c0957e0559759bf468f964605e9a9 */ /* x = 6.48437500000000000000000000000000000e-01 3ffe4c00000000000000000000000000 */ /* cos(x) = 0.cc0a0e21709883a3ff00911e11a07ee3bd7ea2b04e081be99be0264791170761ae64b8b744a */ - 7.97028430141468342004642741431945296e-01L, /* 3ffe98141c42e1310747fe01223c2341 */ - -8.35364432831812599727083251866305534e-37L, /* bf871c42815d4fb1f7e416641fd9b86f */ + 7.97028430141468342004642741431945296e-01L, /* 3ffe98141c42e1310747fe01223c2341 */ + -8.35364432831812599727083251866305534e-37L, /* bf871c42815d4fb1f7e416641fd9b86f */ /* sin(x) = 0.9a9bedcdf01b38d993f3d7820781de292033ead73b89e28f39313dbe3a6e463f845b5fa8490 */ - 6.03941786554156657267270287527367726e-01L, /* 3ffe3537db9be03671b327e7af040f04 */ - -2.54578992328947177770363936132309779e-35L, /* bf8c0eb6fe60a94623b0eb863676120e */ + 6.03941786554156657267270287527367726e-01L, /* 3ffe3537db9be03671b327e7af040f04 */ + -2.54578992328947177770363936132309779e-35L, /* bf8c0eb6fe60a94623b0eb863676120e */ /* x = 6.56250000000000000000000000000000000e-01 3ffe5000000000000000000000000000 */ /* cos(x) = 0.cad33f00658fe5e8204bbc0f3a66a0e6a773f87987a780b243d7be83b3db1448ca0e0e62787 */ - 7.92285859677178543141501323781709399e-01L, /* 3ffe95a67e00cb1fcbd04097781e74cd */ - 2.47519558228473167879248891673807645e-35L, /* 3f8c07353b9fc3cc3d3c05921ebdf41e */ + 7.92285859677178543141501323781709399e-01L, /* 3ffe95a67e00cb1fcbd04097781e74cd */ + 2.47519558228473167879248891673807645e-35L, /* 3f8c07353b9fc3cc3d3c05921ebdf41e */ /* sin(x) = 0.9c32cba2b14156ef05256c4f857991ca6a547cd7ceb1ac8a8e62a282bd7b9183648a462bd04 */ - 6.10150077075791371273742393566183220e-01L, /* 3ffe386597456282adde0a4ad89f0af3 */ - 1.33842237929938963780969418369150532e-35L, /* 3f8b1ca6a547cd7ceb1ac8a8e62a282c */ + 6.10150077075791371273742393566183220e-01L, /* 3ffe386597456282adde0a4ad89f0af3 */ + 1.33842237929938963780969418369150532e-35L, /* 3f8b1ca6a547cd7ceb1ac8a8e62a282c */ /* x = 6.64062500000000000000000000000000000e-01 3ffe5400000000000000000000000000 */ /* cos(x) = 0.c99944936cf48c8911ff93fe64b3ddb7981e414bdaf6aae1203577de44878c62bc3bc9cf7b9 */ - 7.87494932167606083931328295965533034e-01L, /* 3ffe93328926d9e9191223ff27fcc968 */ - -2.57915385618070637156514241185180920e-35L, /* bf8c12433f0df5a1284aa8f6fe54410e */ + 7.87494932167606083931328295965533034e-01L, /* 3ffe93328926d9e9191223ff27fcc968 */ + -2.57915385618070637156514241185180920e-35L, /* bf8c12433f0df5a1284aa8f6fe54410e */ /* sin(x) = 0.9dc738ad14204e689ac582d0f85826590feece34886cfefe2e08cf2bb8488d55424dc9d3525 */ - 6.16321127181550943005700433761731837e-01L, /* 3ffe3b8e715a28409cd1358b05a1f0b0 */ - 2.88497530050197716298085892460478666e-35L, /* 3f8c32c87f7671a44367f7f17046795e */ + 6.16321127181550943005700433761731837e-01L, /* 3ffe3b8e715a28409cd1358b05a1f0b0 */ + 2.88497530050197716298085892460478666e-35L, /* 3f8c32c87f7671a44367f7f17046795e */ /* x = 6.71875000000000000000000000000000000e-01 3ffe5800000000000000000000000000 */ /* cos(x) = 0.c85c23c26ed7b6f014ef546c47929682122876bfbf157de0aff3c4247d820c746e32cd4174f */ - 7.82655940026272796930787447428139026e-01L, /* 3ffe90b84784ddaf6de029dea8d88f25 */ - 1.69332045679237919427807771288506254e-35L, /* 3f8b682122876bfbf157de0aff3c4248 */ + 7.82655940026272796930787447428139026e-01L, /* 3ffe90b84784ddaf6de029dea8d88f25 */ + 1.69332045679237919427807771288506254e-35L, /* 3f8b682122876bfbf157de0aff3c4248 */ /* sin(x) = 0.9f592e9b66a9cf906a3c7aa3c10199849040c45ec3f0a747597311038101780c5f266059dbf */ - 6.22454560222343683041926705090443330e-01L, /* 3ffe3eb25d36cd539f20d478f5478203 */ - 1.91974786921147072717621236192269859e-35L, /* 3f8b9849040c45ec3f0a747597311038 */ + 6.22454560222343683041926705090443330e-01L, /* 3ffe3eb25d36cd539f20d478f5478203 */ + 1.91974786921147072717621236192269859e-35L, /* 3f8b9849040c45ec3f0a747597311038 */ /* x = 6.79687500000000000000000000000000000e-01 3ffe5c00000000000000000000000000 */ /* cos(x) = 0.c71be181ecd6875ce2da5615a03cca207d9adcb9dfb0a1d6c40a4f0056437f1a59ccddd06ee */ - 7.77769178600317903122203513685412863e-01L, /* 3ffe8e37c303d9ad0eb9c5b4ac2b407a */ - -4.05296033424632846931240580239929672e-35L, /* bf8caefc13291a31027af149dfad87fd */ + 7.77769178600317903122203513685412863e-01L, /* 3ffe8e37c303d9ad0eb9c5b4ac2b407a */ + -4.05296033424632846931240580239929672e-35L, /* bf8caefc13291a31027af149dfad87fd */ /* sin(x) = 0.a0e8a725d33c828c11fa50fd9e9a15ffecfad43f3e534358076b9b0f6865694842b1e8c67dc */ - 6.28550001845029662028004327939032867e-01L, /* 3ffe41d14e4ba679051823f4a1fb3d34 */ - 1.65507421184028099672784511397428852e-35L, /* 3f8b5ffecfad43f3e534358076b9b0f7 */ + 6.28550001845029662028004327939032867e-01L, /* 3ffe41d14e4ba679051823f4a1fb3d34 */ + 1.65507421184028099672784511397428852e-35L, /* 3f8b5ffecfad43f3e534358076b9b0f7 */ /* x = 6.87500000000000000000000000000000000e-01 3ffe6000000000000000000000000000 */ /* cos(x) = 0.c5d882d2ee48030c7c07d28e981e34804f82ed4cf93655d2365389b716de6ad44676a1cc5da */ - 7.72834946152471544810851845913425178e-01L, /* 3ffe8bb105a5dc900618f80fa51d303c */ - 3.94975229341211664237241534741146939e-35L, /* 3f8ca4027c176a67c9b2ae91b29c4db9 */ + 7.72834946152471544810851845913425178e-01L, /* 3ffe8bb105a5dc900618f80fa51d303c */ + 3.94975229341211664237241534741146939e-35L, /* 3f8ca4027c176a67c9b2ae91b29c4db9 */ /* sin(x) = 0.a2759c0e79c35582527c32b55f5405c182c66160cb1d9eb7bb0b7cdf4ad66f317bda4332914 */ - 6.34607080015269296850309914203671436e-01L, /* 3ffe44eb381cf386ab04a4f8656abea8 */ - 4.33025916939968369326060156455927002e-36L, /* 3f897060b1985832c767adeec2df37d3 */ + 6.34607080015269296850309914203671436e-01L, /* 3ffe44eb381cf386ab04a4f8656abea8 */ + 4.33025916939968369326060156455927002e-36L, /* 3f897060b1985832c767adeec2df37d3 */ /* x = 6.95312500000000000000000000000000000e-01 3ffe6400000000000000000000000000 */ /* cos(x) = 0.c4920cc2ec38fb891b38827db08884fc66371ac4c2052ca8885b981bbcfd3bb7b093ee31515 */ - 7.67853543842850365879920759114193964e-01L, /* 3ffe89241985d871f712367104fb6111 */ - 3.75100035267325597157244776081706979e-36L, /* 3f893f198dc6b130814b2a2216e606ef */ + 7.67853543842850365879920759114193964e-01L, /* 3ffe89241985d871f712367104fb6111 */ + 3.75100035267325597157244776081706979e-36L, /* 3f893f198dc6b130814b2a2216e606ef */ /* sin(x) = 0.a400072188acf49cd6b173825e038346f105e1301afe642bcc364cea455e21e506e3e927ed8 */ - 6.40625425040230409188409779413961021e-01L, /* 3ffe48000e431159e939ad62e704bc07 */ - 2.46542747294664049615806500747173281e-36L, /* 3f88a37882f0980d7f3215e61b267523 */ + 6.40625425040230409188409779413961021e-01L, /* 3ffe48000e431159e939ad62e704bc07 */ + 2.46542747294664049615806500747173281e-36L, /* 3f88a37882f0980d7f3215e61b267523 */ /* x = 7.03125000000000000000000000000000000e-01 3ffe6800000000000000000000000000 */ /* cos(x) = 0.c348846bbd3631338ffe2bfe9dd1381a35b4e9c0c51b4c13fe376bad1bf5caacc4542be0aa9 */ - 7.62825275710576250507098753625429792e-01L, /* 3ffe869108d77a6c62671ffc57fd3ba2 */ - 4.22067411888601505004748939382325080e-35L, /* 3f8cc0d1ada74e0628da609ff1bb5d69 */ + 7.62825275710576250507098753625429792e-01L, /* 3ffe869108d77a6c62671ffc57fd3ba2 */ + 4.22067411888601505004748939382325080e-35L, /* 3f8cc0d1ada74e0628da609ff1bb5d69 */ /* sin(x) = 0.a587e23555bb08086d02b9c662cdd29316c3e9bd08d93793634a21b1810cce73bdb97a99b9e */ - 6.46604669591152370524042159882800763e-01L, /* 3ffe4b0fc46aab761010da05738cc59c */ - -3.41742981816219412415674365946079826e-35L, /* bf8c6b6749e0b217b9364364e5aef274 */ + 6.46604669591152370524042159882800763e-01L, /* 3ffe4b0fc46aab761010da05738cc59c */ + -3.41742981816219412415674365946079826e-35L, /* bf8c6b6749e0b217b9364364e5aef274 */ /* x = 7.10937500000000000000000000000000000e-01 3ffe6c00000000000000000000000000 */ /* cos(x) = 0.c1fbeef380e4ffdd5a613ec8722f643ffe814ec2343e53adb549627224fdc9f2a7b77d3d69f */ - 7.57750448655219342240234832230493361e-01L, /* 3ffe83f7dde701c9ffbab4c27d90e45f */ - -2.08767968311222650582659938787920125e-35L, /* bf8bbc0017eb13dcbc1ac524ab69d8de */ + 7.57750448655219342240234832230493361e-01L, /* 3ffe83f7dde701c9ffbab4c27d90e45f */ + -2.08767968311222650582659938787920125e-35L, /* bf8bbc0017eb13dcbc1ac524ab69d8de */ /* sin(x) = 0.a70d272a76a8d4b6da0ec90712bb748b96dabf88c3079246f3db7eea6e58ead4ed0e2843303 */ - 6.52544448725765956407573982284767763e-01L, /* 3ffe4e1a4e54ed51a96db41d920e2577 */ - -8.61758060284379660697102362141557170e-36L, /* bf8a6e8d24a80ee79f0db721849022b2 */ + 6.52544448725765956407573982284767763e-01L, /* 3ffe4e1a4e54ed51a96db41d920e2577 */ + -8.61758060284379660697102362141557170e-36L, /* bf8a6e8d24a80ee79f0db721849022b2 */ /* x = 7.18750000000000000000000000000000000e-01 3ffe7000000000000000000000000000 */ /* cos(x) = 0.c0ac518c8b6ae710ba37a3eeb90cb15aebcb8bed4356fb507a48a6e97de9aa6d9660116b436 */ - 7.52629372418066476054541324847143116e-01L, /* 3ffe8158a31916d5ce21746f47dd7219 */ - 3.71306958657663189665450864311104571e-35L, /* 3f8c8ad75e5c5f6a1ab7da83d245374c */ + 7.52629372418066476054541324847143116e-01L, /* 3ffe8158a31916d5ce21746f47dd7219 */ + 3.71306958657663189665450864311104571e-35L, /* 3f8c8ad75e5c5f6a1ab7da83d245374c */ /* sin(x) = 0.a88fcfebd9a8dd47e2f3c76ef9e2439920f7e7fbe735f8bcc985491ec6f12a2d4214f8cfa99 */ - 6.58444399910567541589583954884041989e-01L, /* 3ffe511f9fd7b351ba8fc5e78eddf3c5 */ - -4.54412944084300330523721391865787219e-35L, /* bf8ce336f840c020c6503a19b3d5b70a */ + 6.58444399910567541589583954884041989e-01L, /* 3ffe511f9fd7b351ba8fc5e78eddf3c5 */ + -4.54412944084300330523721391865787219e-35L, /* bf8ce336f840c020c6503a19b3d5b70a */ /* x = 7.26562500000000000000000000000000000e-01 3ffe7400000000000000000000000000 */ /* cos(x) = 0.bf59b17550a4406875969296567cf3e3b4e483061877c02811c6cae85fad5a6c3da58f49292 */ - 7.47462359563216166669700384714767552e-01L, /* 3ffe7eb362eaa14880d0eb2d252cacfa */ - -9.11094340926220027288083639048016945e-36L, /* bf8a8389636f9f3cf107fafdc726a2f4 */ + 7.47462359563216166669700384714767552e-01L, /* 3ffe7eb362eaa14880d0eb2d252cacfa */ + -9.11094340926220027288083639048016945e-36L, /* bf8a8389636f9f3cf107fafdc726a2f4 */ /* sin(x) = 0.aa0fd66eddb921232c28520d3911b8a03193b47f187f1471ac216fbcd5bb81029294d3a73f1 */ - 6.64304163042946276515506587432846246e-01L, /* 3ffe541facddbb7242465850a41a7223 */ - 4.26004843895378210155889028714676019e-35L, /* 3f8cc5018c9da3f8c3f8a38d610b7de7 */ + 6.64304163042946276515506587432846246e-01L, /* 3ffe541facddbb7242465850a41a7223 */ + 4.26004843895378210155889028714676019e-35L, /* 3f8cc5018c9da3f8c3f8a38d610b7de7 */ /* x = 7.34375000000000000000000000000000000e-01 3ffe7800000000000000000000000000 */ /* cos(x) = 0.be0413f84f2a771c614946a88cbf4da1d75a5560243de8f2283fefa0ea4a48468a52d51d8b3 */ - 7.42249725458501306991347253449610537e-01L, /* 3ffe7c0827f09e54ee38c2928d51197f */ - -3.78925270049800913539923473871287550e-35L, /* bf8c92f1452d54fede10b86ebe0082f9 */ + 7.42249725458501306991347253449610537e-01L, /* 3ffe7c0827f09e54ee38c2928d51197f */ + -3.78925270049800913539923473871287550e-35L, /* bf8c92f1452d54fede10b86ebe0082f9 */ /* sin(x) = 0.ab8d34b36acd987210ed343ec65d7e3adc2e7109fce43d55c8d57dfdf55b9e01d2cc1f1b9ec */ - 6.70123380473162894654531583500648495e-01L, /* 3ffe571a6966d59b30e421da687d8cbb */ - -1.33165852952743729897634069393684656e-36L, /* bf87c523d18ef6031bc2aa372a82020b */ + 6.70123380473162894654531583500648495e-01L, /* 3ffe571a6966d59b30e421da687d8cbb */ + -1.33165852952743729897634069393684656e-36L, /* bf87c523d18ef6031bc2aa372a82020b */ /* x = 7.42187500000000000000000000000000000e-01 3ffe7c00000000000000000000000000 */ /* cos(x) = 0.bcab7e6bfb2a14a9b122c574a376bec98ab14808c64a4e731b34047e217611013ac99c0f25d */ - 7.36991788256240741057089385586450844e-01L, /* 3ffe7956fcd7f654295362458ae946ed */ - 4.72358938637974850573747497460125519e-35L, /* 3f8cf64c558a404632527398d9a023f1 */ + 7.36991788256240741057089385586450844e-01L, /* 3ffe7956fcd7f654295362458ae946ed */ + 4.72358938637974850573747497460125519e-35L, /* 3f8cf64c558a404632527398d9a023f1 */ /* sin(x) = 0.ad07e4c409d08c4fa3a9057bb0ac24b8636e74e76f51e09bd6b2319707cbd9f5e254643897a */ - 6.75901697026178809189642203142423973e-01L, /* 3ffe5a0fc98813a1189f47520af76158 */ - 2.76252586616364878801928456702948857e-35L, /* 3f8c25c31b73a73b7a8f04deb5918cb8 */ + 6.75901697026178809189642203142423973e-01L, /* 3ffe5a0fc98813a1189f47520af76158 */ + 2.76252586616364878801928456702948857e-35L, /* 3f8c25c31b73a73b7a8f04deb5918cb8 */ /* x = 7.50000000000000000000000000000000000e-01 3ffe8000000000000000000000000000 */ /* cos(x) = 0.bb4ff632a908f73ec151839cb9d993b4e0bfb8f20e7e44e6e4aee845e35575c3106dbe6fd06 */ - 7.31688868873820886311838753000084529e-01L, /* 3ffe769fec655211ee7d82a3073973b3 */ - 1.48255637548931697184991710293198620e-35L, /* 3f8b3b4e0bfb8f20e7e44e6e4aee845e */ + 7.31688868873820886311838753000084529e-01L, /* 3ffe769fec655211ee7d82a3073973b3 */ + 1.48255637548931697184991710293198620e-35L, /* 3f8b3b4e0bfb8f20e7e44e6e4aee845e */ /* sin(x) = 0.ae7fe0b5fc786b2d966e1d6af140a488476747c2646425fc7533f532cd044cb10a971a49a6a */ - 6.81638760023334166733241952779893908e-01L, /* 3ffe5cffc16bf8f0d65b2cdc3ad5e281 */ - 2.74838775935027549024224114338667371e-35L, /* 3f8c24423b3a3e1323212fe3a99fa996 */ + 6.81638760023334166733241952779893908e-01L, /* 3ffe5cffc16bf8f0d65b2cdc3ad5e281 */ + 2.74838775935027549024224114338667371e-35L, /* 3f8c24423b3a3e1323212fe3a99fa996 */ /* x = 7.57812500000000000000000000000000000e-01 3ffe8400000000000000000000000000 */ /* cos(x) = 0.b9f180ba77dd0751628e135a9508299012230f14becacdd14c3f8862d122de5b56d55b53360 */ - 7.26341290974108590410147630237598973e-01L, /* 3ffe73e30174efba0ea2c51c26b52a10 */ - 3.12683579338351123545814364980658990e-35L, /* 3f8c4c80911878a5f6566e8a61fc4317 */ + 7.26341290974108590410147630237598973e-01L, /* 3ffe73e30174efba0ea2c51c26b52a10 */ + 3.12683579338351123545814364980658990e-35L, /* 3f8c4c80911878a5f6566e8a61fc4317 */ /* sin(x) = 0.aff522a954f2ba16d9defdc416e33f5e9a5dfd5a6c228e0abc4d521327ff6e2517a7b3851dd */ - 6.87334219303873534951703613035647220e-01L, /* 3ffe5fea4552a9e5742db3bdfb882dc6 */ - 4.76739454455410744997012795035529128e-35L, /* 3f8cfaf4d2efead361147055e26a9099 */ + 6.87334219303873534951703613035647220e-01L, /* 3ffe5fea4552a9e5742db3bdfb882dc6 */ + 4.76739454455410744997012795035529128e-35L, /* 3f8cfaf4d2efead361147055e26a9099 */ /* x = 7.65625000000000000000000000000000000e-01 3ffe8800000000000000000000000000 */ /* cos(x) = 0.b890237d3bb3c284b614a0539016bfa1053730bbdf940fa895e185f8e58884d3dda15e63371 */ - 7.20949380945696418043812784148447688e-01L, /* 3ffe712046fa776785096c2940a7202d */ - 4.78691285733673379499536326050811832e-35L, /* 3f8cfd0829b985defca07d44af0c2fc7 */ + 7.20949380945696418043812784148447688e-01L, /* 3ffe712046fa776785096c2940a7202d */ + 4.78691285733673379499536326050811832e-35L, /* 3f8cfd0829b985defca07d44af0c2fc7 */ /* sin(x) = 0.b167a4c90d63c4244cf5493b7cc23bd3c3c1225e078baa0c53d6d400b926281f537a1a260e6 */ - 6.92987727246317910281815490823048210e-01L, /* 3ffe62cf49921ac7884899ea9276f984 */ - 4.50089871077663557180849219529189918e-35L, /* 3f8cde9e1e0912f03c5d50629eb6a006 */ + 6.92987727246317910281815490823048210e-01L, /* 3ffe62cf49921ac7884899ea9276f984 */ + 4.50089871077663557180849219529189918e-35L, /* 3f8cde9e1e0912f03c5d50629eb6a006 */ /* x = 7.73437500000000000000000000000000000e-01 3ffe8c00000000000000000000000000 */ /* cos(x) = 0.b72be40067aaf2c050dbdb7a14c3d7d4f203f6b3f0224a4afe55d6ec8e92b508fd5c5984b3b */ - 7.15513467882981573520620561289896903e-01L, /* 3ffe6e57c800cf55e580a1b7b6f42988 */ - -3.02191815581445336509438104625489192e-35L, /* bf8c41586fe04a607eedada80d51489c */ + 7.15513467882981573520620561289896903e-01L, /* 3ffe6e57c800cf55e580a1b7b6f42988 */ + -3.02191815581445336509438104625489192e-35L, /* bf8c41586fe04a607eedada80d51489c */ /* sin(x) = 0.b2d7614b1f3aaa24df2d6e20a77e1ca3e6d838c03e29c1bcb026e6733324815fadc9eb89674 */ - 6.98598938789681741301929277107891591e-01L, /* 3ffe65aec2963e755449be5adc414efc */ - 2.15465226809256290914423429408722521e-35L, /* 3f8bca3e6d838c03e29c1bcb026e6733 */ + 6.98598938789681741301929277107891591e-01L, /* 3ffe65aec2963e755449be5adc414efc */ + 2.15465226809256290914423429408722521e-35L, /* 3f8bca3e6d838c03e29c1bcb026e6733 */ /* x = 7.81250000000000000000000000000000000e-01 3ffe9000000000000000000000000000 */ /* cos(x) = 0.b5c4c7d4f7dae915ac786ccf4b1a498d3e73b6e5e74fe7519d9c53ee6d6b90e881bddfc33e1 */ - 7.10033883566079674974121643959490219e-01L, /* 3ffe6b898fa9efb5d22b58f0d99e9635 */ - -4.09623224763692443220896752907902465e-35L, /* bf8cb3960c6248d0c580c573131d608d */ + 7.10033883566079674974121643959490219e-01L, /* 3ffe6b898fa9efb5d22b58f0d99e9635 */ + -4.09623224763692443220896752907902465e-35L, /* bf8cb3960c6248d0c580c573131d608d */ /* sin(x) = 0.b44452709a59752905913765434a59d111f0433eb2b133f7d103207e2aeb4aae111ddc385b3 */ - 7.04167511454533672780059509973942844e-01L, /* 3ffe6888a4e134b2ea520b226eca8695 */ - -2.87259372740393348676633610275598640e-35L, /* bf8c3177707de60a6a76604177e6fc0f */ + 7.04167511454533672780059509973942844e-01L, /* 3ffe6888a4e134b2ea520b226eca8695 */ + -2.87259372740393348676633610275598640e-35L, /* bf8c3177707de60a6a76604177e6fc0f */ /* x = 7.89062500000000000000000000000000000e-01 3ffe9400000000000000000000000000 */ /* cos(x) = 0.b45ad4975b1294cadca4cf40ec8f22a68cd14b175835239a37e63acb85e8e9505215df18140 */ - 7.04510962440574606164129481545916976e-01L, /* 3ffe68b5a92eb6252995b9499e81d91e */ - 2.60682037357042658395360726992048803e-35L, /* 3f8c1534668a58bac1a91cd1bf31d65c */ + 7.04510962440574606164129481545916976e-01L, /* 3ffe68b5a92eb6252995b9499e81d91e */ + 2.60682037357042658395360726992048803e-35L, /* 3f8c1534668a58bac1a91cd1bf31d65c */ /* sin(x) = 0.b5ae7285bc10cf515753847e8f8b7a30e0a580d929d770103509880680f7b8b0e8ad23b65d8 */ - 7.09693105363899724959669028139035515e-01L, /* 3ffe6b5ce50b78219ea2aea708fd1f17 */ - -4.37026016974122945368562319136420097e-36L, /* bf8973c7d69fc9b58a23fbf2bd9dfe60 */ + 7.09693105363899724959669028139035515e-01L, /* 3ffe6b5ce50b78219ea2aea708fd1f17 */ + -4.37026016974122945368562319136420097e-36L, /* bf8973c7d69fc9b58a23fbf2bd9dfe60 */ }; diff --git a/lib/sinl.c b/lib/sinl.c index 918362daa..eb0e05b6e 100644 --- a/lib/sinl.c +++ b/lib/sinl.c @@ -22,22 +22,22 @@ * Return sine function of x. * * kernel function: - * __kernel_sinl ... sine function on [-pi/4,pi/4] - * __kernel_cosl ... cose function on [-pi/4,pi/4] - * __ieee754_rem_pio2l ... argument reduction routine + * __kernel_sinl ... sine function on [-pi/4,pi/4] + * __kernel_cosl ... cose function on [-pi/4,pi/4] + * __ieee754_rem_pio2l ... argument reduction routine * * Method. * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 + * in [-pi/4 , +pi/4], and let n = k mod 4. + * We have * * n sin(x) cos(x) tan(x) * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T + * 0 S C T + * 1 C -S -1/T + * 2 -S -C T + * 3 -C S -1/T * ---------------------------------------------------------- * * Special cases: @@ -46,7 +46,7 @@ * trig(NaN) is that NaN; * * Accuracy: - * TRIG(x) returns trig(x) nearly rounded + * TRIG(x) returns trig(x) nearly rounded */ #include "trigl.h" @@ -70,23 +70,23 @@ sinl (long double x) /* sinl(Inf) is NaN, sinl(0) is 0 */ else if (x + x == x) - return x - x; /* NaN */ + return x - x; /* NaN */ /* argument reduction needed */ else { n = ieee754_rem_pio2l (x, y); switch (n & 3) - { - case 0: - return kernel_sinl (y[0], y[1], 1); - case 1: - return kernel_cosl (y[0], y[1]); - case 2: - return -kernel_sinl (y[0], y[1], 1); - default: - return -kernel_cosl (y[0], y[1]); - } + { + case 0: + return kernel_sinl (y[0], y[1], 1); + case 1: + return kernel_cosl (y[0], y[1]); + case 2: + return -kernel_sinl (y[0], y[1], 1); + default: + return -kernel_cosl (y[0], y[1]); + } } } diff --git a/lib/snprintf.c b/lib/snprintf.c index 7b9725b3b..310edbde6 100644 --- a/lib/snprintf.c +++ b/lib/snprintf.c @@ -53,11 +53,11 @@ snprintf (char *str, size_t size, const char *format, ...) if (output != str) { if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } free (output); } diff --git a/lib/sockets.c b/lib/sockets.c index cb169f886..b49e58062 100644 --- a/lib/sockets.c +++ b/lib/sockets.c @@ -46,21 +46,21 @@ close_fd_maybe_socket (int fd, const struct close_hook *remaining_list) { /* fd refers to a socket. */ /* FIXME: other applications, like squid, use an undocumented - _free_osfhnd free function. But this is not enough: The 'osfile' - flags for fd also needs to be cleared, but it is hard to access it. - Instead, here we just close twice the file descriptor. */ + _free_osfhnd free function. But this is not enough: The 'osfile' + flags for fd also needs to be cleared, but it is hard to access it. + Instead, here we just close twice the file descriptor. */ if (closesocket (sock)) - { - set_winsock_errno (); - return -1; - } + { + set_winsock_errno (); + return -1; + } else - { - /* This call frees the file descriptor and does a - CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */ - _close (fd); - return 0; - } + { + /* This call frees the file descriptor and does a + CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */ + _close (fd); + return 0; + } } else /* Some other type of file descriptor. */ @@ -84,13 +84,13 @@ gl_sockets_startup (int version _UNUSED_PARAMETER_) err = WSAStartup (version, &data); if (err != 0) - return 1; + return 1; if (data.wVersion < version) - return 2; + return 2; if (initialized_sockets_version == 0) - register_close_hook (close_fd_maybe_socket, &close_sockets_hook); + register_close_hook (close_fd_maybe_socket, &close_sockets_hook); initialized_sockets_version = version; } diff --git a/lib/spawn.c b/lib/spawn.c index 424342d4f..5746ac6eb 100644 --- a/lib/spawn.c +++ b/lib/spawn.c @@ -25,9 +25,9 @@ Before running the process perform the actions described in FILE-ACTIONS. */ int posix_spawn (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[]) + const posix_spawn_file_actions_t *file_actions, + const posix_spawnattr_t *attrp, char *const argv[], + char *const envp[]) { return __spawni (pid, path, file_actions, attrp, argv, envp, 0); } diff --git a/lib/spawn.in.h b/lib/spawn.in.h index d67b766ed..f1155ceaf 100644 --- a/lib/spawn.in.h +++ b/lib/spawn.in.h @@ -55,9 +55,9 @@ 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__)) \ - && !__STRICT_ANSI__)) \ +# if ((199901L <= __STDC_VERSION__ \ + || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \ + && !__STRICT_ANSI__)) \ && !defined __GNUG__) # define _Restrict_arr_ _Restrict_ # else @@ -104,27 +104,27 @@ typedef struct /* 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 +# 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 /* 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 - 1) \ - | POSIX_SPAWN_SETSCHEDULER | (POSIX_SPAWN_SETSCHEDULER - 1)) \ + ((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 - 1) \ + | POSIX_SPAWN_SETSCHEDULER | (POSIX_SPAWN_SETSCHEDULER - 1)) \ + 1) typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap [2 * (((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP - | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK - | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER) - & POSIX_SPAWN_USEVFORK) == 0) - 1]; + | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK + | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER) + & POSIX_SPAWN_USEVFORK) == 0) - 1]; #ifdef __cplusplus @@ -143,11 +143,11 @@ extern "C" { # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawn (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_]); + 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 #endif @@ -161,9 +161,9 @@ extern int posix_spawn (pid_t *_Restrict_ __pid, # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern 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[]); + const posix_spawn_file_actions_t *__file_actions, + const posix_spawnattr_t *__attrp, + char *const argv[], char *const envp[]); # endif #endif @@ -196,7 +196,7 @@ extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW; # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigdefault) + sigset_t *_Restrict_ __sigdefault) __THROW; # endif #endif @@ -208,7 +208,7 @@ extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigdefault) + const sigset_t *_Restrict_ __sigdefault) __THROW; # endif #endif @@ -220,7 +220,7 @@ extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr, # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __attr, - sigset_t *_Restrict_ __sigmask) __THROW; + sigset_t *_Restrict_ __sigmask) __THROW; # endif #endif @@ -231,7 +231,7 @@ extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __att # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr, - const sigset_t *_Restrict_ __sigmask) + const sigset_t *_Restrict_ __sigmask) __THROW; # endif #endif @@ -243,7 +243,7 @@ extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr, # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr, - short int *_Restrict_ __flags) __THROW; + short int *_Restrict_ __flags) __THROW; # endif #endif @@ -254,7 +254,7 @@ extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr, # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr, - short int __flags) __THROW; + short int __flags) __THROW; # endif #endif @@ -265,7 +265,7 @@ extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr, # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr, - pid_t *_Restrict_ __pgroup) + pid_t *_Restrict_ __pgroup) __THROW; # endif #endif @@ -277,7 +277,7 @@ extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr, - pid_t __pgroup) __THROW; + pid_t __pgroup) __THROW; # endif #endif @@ -288,7 +288,7 @@ extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr, # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ __attr, - int *_Restrict_ __schedpolicy) + int *_Restrict_ __schedpolicy) __THROW; # endif #endif @@ -300,7 +300,7 @@ extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ _ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr, - int __schedpolicy) __THROW; + int __schedpolicy) __THROW; # endif #endif @@ -311,7 +311,7 @@ extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr, # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __attr, - struct sched_param *_Restrict_ __schedparam) __THROW; + struct sched_param *_Restrict_ __schedparam) __THROW; # endif #endif @@ -322,7 +322,7 @@ extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawnattr_setschedparam (posix_spawnattr_t *_Restrict_ __attr, - const struct sched_param *_Restrict_ __schedparam) __THROW; + const struct sched_param *_Restrict_ __schedparam) __THROW; # endif #endif @@ -355,9 +355,9 @@ extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_ # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *_Restrict_ __file_actions, - int __fd, - const char *_Restrict_ __path, - int __oflag, mode_t __mode) + int __fd, + const char *_Restrict_ __path, + int __oflag, mode_t __mode) __THROW; # endif #endif @@ -370,7 +370,7 @@ extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *_Restri # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file_actions, - int __fd) + int __fd) __THROW; # endif #endif @@ -383,7 +383,7 @@ extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file # endif # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@ extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *__file_actions, - int __fd, int __newfd) __THROW; + int __fd, int __newfd) __THROW; # endif #endif diff --git a/lib/spawn_faction_addclose.c b/lib/spawn_faction_addclose.c index 356604722..26b25f64f 100644 --- a/lib/spawn_faction_addclose.c +++ b/lib/spawn_faction_addclose.c @@ -32,7 +32,7 @@ `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) + int fd) { int maxfd = __sysconf (_SC_OPEN_MAX); struct __spawn_action *rec; diff --git a/lib/spawn_faction_adddup2.c b/lib/spawn_faction_adddup2.c index 688873fda..e1c707f71 100644 --- a/lib/spawn_faction_adddup2.c +++ b/lib/spawn_faction_adddup2.c @@ -32,7 +32,7 @@ `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) + int fd, int newfd) { int maxfd = __sysconf (_SC_OPEN_MAX); struct __spawn_action *rec; diff --git a/lib/spawn_faction_addopen.c b/lib/spawn_faction_addopen.c index 2f63bc3c2..1a71d61d8 100644 --- a/lib/spawn_faction_addopen.c +++ b/lib/spawn_faction_addopen.c @@ -32,8 +32,8 @@ `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) + int fd, const char *path, int oflag, + mode_t mode) { int maxfd = __sysconf (_SC_OPEN_MAX); struct __spawn_action *rec; diff --git a/lib/spawn_faction_init.c b/lib/spawn_faction_init.c index 28271a75f..d52d1f927 100644 --- a/lib/spawn_faction_init.c +++ b/lib/spawn_faction_init.c @@ -33,7 +33,7 @@ __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)); + newalloc * sizeof (struct __spawn_action)); if (newmem == NULL) /* Not enough memory. */ diff --git a/lib/spawn_int.h b/lib/spawn_int.h index ec06779c6..bcc93e005 100644 --- a/lib/spawn_int.h +++ b/lib/spawn_int.h @@ -51,12 +51,12 @@ struct __spawn_action # 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); + 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); + 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/lib/spawnattr_getdefault.c b/lib/spawnattr_getdefault.c index 53f7d530f..b4f630253 100644 --- a/lib/spawnattr_getdefault.c +++ b/lib/spawnattr_getdefault.c @@ -25,7 +25,7 @@ SIGDEFAULT. */ int posix_spawnattr_getsigdefault (const posix_spawnattr_t *attr, - sigset_t *sigdefault) + sigset_t *sigdefault) { /* Copy the sigset_t data to the user buffer. */ memcpy (sigdefault, &attr->_sd, sizeof (sigset_t)); diff --git a/lib/spawnattr_getschedparam.c b/lib/spawnattr_getschedparam.c index 22664e25f..29af75c60 100644 --- a/lib/spawnattr_getschedparam.c +++ b/lib/spawnattr_getschedparam.c @@ -22,7 +22,7 @@ /* Get scheduling parameters from the attribute structure. */ int posix_spawnattr_getschedparam (const posix_spawnattr_t *attr, - struct sched_param *schedparam) + struct sched_param *schedparam) { /* Copy the scheduling parameters. */ *schedparam = attr->_sp; diff --git a/lib/spawnattr_getschedpolicy.c b/lib/spawnattr_getschedpolicy.c index 49145d137..58d44b754 100644 --- a/lib/spawnattr_getschedpolicy.c +++ b/lib/spawnattr_getschedpolicy.c @@ -24,7 +24,7 @@ /* Get scheduling policy from the attribute structure. */ int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *attr, - int *schedpolicy) + int *schedpolicy) { /* Copy the scheduling policy. */ *schedpolicy = attr->_policy; diff --git a/lib/spawnattr_getsigmask.c b/lib/spawnattr_getsigmask.c index 5ad901a8e..d4d0211e3 100644 --- a/lib/spawnattr_getsigmask.c +++ b/lib/spawnattr_getsigmask.c @@ -24,7 +24,7 @@ /* Store signal mask for the new process from ATTR in SIGMASK. */ int posix_spawnattr_getsigmask (const posix_spawnattr_t *attr, - sigset_t *sigmask) + sigset_t *sigmask) { /* Copy the sigset_t data to the user buffer. */ memcpy (sigmask, &attr->_ss, sizeof (sigset_t)); diff --git a/lib/spawnattr_setdefault.c b/lib/spawnattr_setdefault.c index c53207b70..a53ac0f19 100644 --- a/lib/spawnattr_setdefault.c +++ b/lib/spawnattr_setdefault.c @@ -24,7 +24,7 @@ /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */ int posix_spawnattr_setsigdefault (posix_spawnattr_t *attr, - const sigset_t *sigdefault) + const sigset_t *sigdefault) { /* Copy the sigset_t data to the user buffer. */ memcpy (&attr->_sd, sigdefault, sizeof (sigset_t)); diff --git a/lib/spawnattr_setflags.c b/lib/spawnattr_setflags.c index f5c2dfe50..e57cee80a 100644 --- a/lib/spawnattr_setflags.c +++ b/lib/spawnattr_setflags.c @@ -22,13 +22,13 @@ #include #include -#define ALL_FLAGS (POSIX_SPAWN_RESETIDS \ - | POSIX_SPAWN_SETPGROUP \ - | POSIX_SPAWN_SETSIGDEF \ - | POSIX_SPAWN_SETSIGMASK \ - | POSIX_SPAWN_SETSCHEDPARAM \ - | POSIX_SPAWN_SETSCHEDULER \ - | POSIX_SPAWN_USEVFORK) +#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 diff --git a/lib/spawnattr_setschedparam.c b/lib/spawnattr_setschedparam.c index d07b4f180..c1c2888ee 100644 --- a/lib/spawnattr_setschedparam.c +++ b/lib/spawnattr_setschedparam.c @@ -22,7 +22,7 @@ /* Store scheduling parameters in the attribute structure. */ int posix_spawnattr_setschedparam (posix_spawnattr_t *attr, - const struct sched_param *schedparam) + const struct sched_param *schedparam) { /* Store the scheduling parameters. */ attr->_sp = *schedparam; diff --git a/lib/spawnattr_setsigmask.c b/lib/spawnattr_setsigmask.c index a3dea2615..d1a119b40 100644 --- a/lib/spawnattr_setsigmask.c +++ b/lib/spawnattr_setsigmask.c @@ -24,7 +24,7 @@ /* Set signal mask for the new process in ATTR to SIGMASK. */ int posix_spawnattr_setsigmask (posix_spawnattr_t *attr, - const sigset_t *sigmask) + const sigset_t *sigmask) { /* Copy the sigset_t data to the user buffer. */ memcpy (&attr->_ss, sigmask, sizeof (sigset_t)); diff --git a/lib/spawni.c b/lib/spawni.c index af4168257..cc476e00b 100644 --- a/lib/spawni.c +++ b/lib/spawni.c @@ -86,7 +86,7 @@ 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 +#define SPAWN_ERROR 127 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ @@ -94,9 +94,9 @@ /* Native Woe32 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) + 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; @@ -123,8 +123,8 @@ script_execute (const char *file, char *const argv[], char *const envp[]) new_argv[1] = (char *) file; while (argc > 1) { - new_argv[argc] = argv[argc - 1]; - --argc; + new_argv[argc] = argv[argc - 1]; + --argc; } /* Execute the shell. */ @@ -137,9 +137,9 @@ script_execute (const char *file, char *const argv[], char *const envp[]) 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) + 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; @@ -157,13 +157,13 @@ __spawni (pid_t *pid, const char *file, #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. */ + 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)) + | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER + | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS)) == 0 + && file_actions == NULL)) new_pid = vfork (); else #endif @@ -172,11 +172,11 @@ __spawni (pid_t *pid, const char *file, if (new_pid != 0) { if (new_pid < 0) - return errno; + return errno; /* The call was successful. Store the PID if necessary. */ if (pid != NULL) - *pid = new_pid; + *pid = new_pid; return 0; } @@ -190,9 +190,9 @@ __spawni (pid_t *pid, const char *file, 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. */ + 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; @@ -200,9 +200,9 @@ __spawni (pid_t *pid, const char *file, 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 (sigismember (&attrp->_sd, sig) != 0 + && sigaction (sig, &sa, NULL) != 0) + _exit (SPAWN_ERROR); } @@ -212,14 +212,14 @@ __spawni (pid_t *pid, const char *file, == POSIX_SPAWN_SETSCHEDPARAM) { if (sched_setparam (0, &attrp->_sp) == -1) - _exit (SPAWN_ERROR); + _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); + (flags & POSIX_SPAWN_SETSCHEDPARAM) != 0 + ? &attrp->_sp : NULL) == -1) + _exit (SPAWN_ERROR); } #endif @@ -231,7 +231,7 @@ __spawni (pid_t *pid, const char *file, /* Set the effective user and group IDs. */ if ((flags & POSIX_SPAWN_RESETIDS) != 0 && (local_seteuid (getuid ()) != 0 - || local_setegid (getgid ()) != 0)) + || local_setegid (getgid ()) != 0)) _exit (SPAWN_ERROR); /* Execute the file actions. */ @@ -240,52 +240,52 @@ __spawni (pid_t *pid, const char *file, 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; - } - } + { + 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) @@ -294,7 +294,7 @@ __spawni (pid_t *pid, const char *file, execve (file, argv, envp); if (errno == ENOEXEC) - script_execute (file, argv, envp); + script_execute (file, argv, envp); /* Oh, oh. `execve' returns. This is bad. */ _exit (SPAWN_ERROR); @@ -306,8 +306,8 @@ __spawni (pid_t *pid, const char *file, { #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'. */ + 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] = ':'; @@ -335,35 +335,35 @@ __spawni (pid_t *pid, const char *file, 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; + /* 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); + 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); + 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); - } + { + 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'); diff --git a/lib/spawnp.c b/lib/spawnp.c index 183a17ece..ecc58360f 100644 --- a/lib/spawnp.c +++ b/lib/spawnp.c @@ -25,9 +25,9 @@ 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[]) + 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/lib/stat.c b/lib/stat.c index 8aa770940..d9a7479ff 100644 --- a/lib/stat.c +++ b/lib/stat.c @@ -55,10 +55,10 @@ rpl_stat (char const *name, struct stat *st) { size_t len = strlen (name); if (ISSLASH (name[len - 1])) - { - errno = ENOTDIR; - return -1; - } + { + errno = ENOTDIR; + return -1; + } } #endif /* REPLACE_FUNC_STAT_FILE */ #if REPLACE_FUNC_STAT_DIR diff --git a/lib/stdint.in.h b/lib/stdint.in.h index 869bd3a7f..33a040ebb 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h @@ -102,8 +102,8 @@ ((signed) \ ? ~ _STDINT_MIN (signed, bits, zero) \ : /* The expression for the unsigned case. The subtraction of (signed) \ - is a nop in the unsigned case and avoids "signed integer overflow" \ - warnings in the signed case. */ \ + is a nop in the unsigned case and avoids "signed integer overflow" \ + warnings in the signed case. */ \ ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1) /* 7.18.1.1. Exact-width integer types */ @@ -454,10 +454,10 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - #undef SIG_ATOMIC_MAX #define SIG_ATOMIC_MIN \ _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ - 0@SIG_ATOMIC_T_SUFFIX@) + 0@SIG_ATOMIC_T_SUFFIX@) #define SIG_ATOMIC_MAX \ _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ - 0@SIG_ATOMIC_T_SUFFIX@) + 0@SIG_ATOMIC_T_SUFFIX@) /* size_t limit */ diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h index c803e88c9..bc853c9d4 100644 --- a/lib/stdio-impl.h +++ b/lib/stdio-impl.h @@ -26,21 +26,21 @@ # if defined __DragonFly__ /* DragonFly */ /* See . */ # 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) + 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 . */ # define _p pub._p # define _flags pub._flags @@ -74,12 +74,12 @@ # 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) + unsigned char *_base; \ + unsigned char *_end; \ + long _cnt; \ + int _file; \ + unsigned int _flag; \ + } *) fp) # else # define fp_ fp # endif diff --git a/lib/stdio-write.c b/lib/stdio-write.c index 15cc5ed74..04fcfe62b 100644 --- a/lib/stdio-write.c +++ b/lib/stdio-write.c @@ -39,27 +39,27 @@ # include # define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \ - if (ferror (stream)) \ - return (EXPRESSION); \ - else \ - { \ - RETTYPE ret; \ - SetLastError (0); \ - ret = (EXPRESSION); \ + if (ferror (stream)) \ + return (EXPRESSION); \ + else \ + { \ + RETTYPE ret; \ + SetLastError (0); \ + ret = (EXPRESSION); \ if (FAILED && 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; \ - } \ - } \ - return ret; \ + { \ + 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; \ + } \ + } \ + return ret; \ } # if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */ diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 6ce139515..495e5cd8d 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -302,13 +302,13 @@ extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream); Return the number of bytes read and stored at *LINEPTR (not including the NUL terminator), or -1 on error or EOF. */ extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter, - FILE *stream); + FILE *stream); # endif #elif defined GNULIB_POSIXCHECK # undef getdelim -# define getdelim(l, s, d, f) \ - (GL_LINK_WARNING ("getdelim is unportable - " \ - "use gnulib module getdelim for portability"), \ +# define getdelim(l, s, d, f) \ + (GL_LINK_WARNING ("getdelim is unportable - " \ + "use gnulib module getdelim for portability"), \ getdelim (l, s, d, f)) #endif @@ -328,9 +328,9 @@ extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream); # endif #elif defined GNULIB_POSIXCHECK # undef getline -# define getline(l, s, f) \ - (GL_LINK_WARNING ("getline is unportable - " \ - "use gnulib module getline for portability"), \ +# define getline(l, s, f) \ + (GL_LINK_WARNING ("getline is unportable - " \ + "use gnulib module getline for portability"), \ getline (l, s, f)) #endif @@ -349,7 +349,7 @@ extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream); extern int obstack_printf (struct obstack *obs, const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); extern int obstack_vprintf (struct obstack *obs, const char *format, - va_list args) + va_list args) __attribute__ ((__format__ (__printf__, 2, 0))); # endif #endif @@ -438,7 +438,7 @@ extern int remove (const char *name); # endif #elif defined GNULIB_POSIXCHECK # undef remove -# define remove(n) \ +# define remove(n) \ (GL_LINK_WARNING ("remove cannot handle directories on some platforms - " \ "use gnulib module remove for more portability"), \ remove (n)) @@ -452,7 +452,7 @@ extern int rename (const char *old_filename, const char *new_filename); # endif #elif defined GNULIB_POSIXCHECK # undef rename -# define rename(o,n) \ +# define rename(o,n) \ (GL_LINK_WARNING ("rename is buggy on some platforms - " \ "use gnulib module rename for more portability"), \ rename (o, n)) @@ -468,7 +468,7 @@ extern int renameat (int fd1, char const *file1, int fd2, char const *file2); # endif #elif defined GNULIB_POSIXCHECK # undef renameat -# define renameat(d1,f1,d2,f2) \ +# define renameat(d1,f1,d2,f2) \ (GL_LINK_WARNING ("renameat is not portable - " \ "use gnulib module renameat for portability"), \ renameat (d1, f1, d2, f2)) diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index dd15ac05b..53d48fccc 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -56,13 +56,13 @@ #if !@HAVE_STRUCT_RANDOM_DATA@ struct random_data { - int32_t *fptr; /* Front pointer. */ - int32_t *rptr; /* Rear pointer. */ - int32_t *state; /* Array of state values. */ - int rand_type; /* Type of random number generator. */ - int rand_deg; /* Degree of random number generator. */ - int rand_sep; /* Distance between front and rear. */ - int32_t *end_ptr; /* Pointer behind state table. */ + int32_t *fptr; /* Front pointer. */ + int32_t *rptr; /* Rear pointer. */ + int32_t *state; /* Array of state values. */ + int rand_type; /* Type of random number generator. */ + int rand_deg; /* Degree of random number generator. */ + int rand_sep; /* Distance between front and rear. */ + int32_t *end_ptr; /* Pointer behind state table. */ }; #endif @@ -313,28 +313,28 @@ extern int putenv (char *string); int srandom_r (unsigned int seed, struct random_data *rand_state); int initstate_r (unsigned int seed, char *buf, size_t buf_size, - struct random_data *rand_state); + struct random_data *rand_state); int setstate_r (char *arg_state, struct random_data *rand_state); int random_r (struct random_data *buf, int32_t *result); # endif #elif defined GNULIB_POSIXCHECK # undef random_r -# define random_r(b,r) \ +# define random_r(b,r) \ (GL_LINK_WARNING ("random_r is unportable - " \ "use gnulib module random_r for portability"), \ random_r (b,r)) # undef initstate_r -# define initstate_r(s,b,sz,r) \ +# define initstate_r(s,b,sz,r) \ (GL_LINK_WARNING ("initstate_r is unportable - " \ "use gnulib module random_r for portability"), \ initstate_r (s,b,sz,r)) # undef srandom_r -# define srandom_r(s,r) \ +# define srandom_r(s,r) \ (GL_LINK_WARNING ("srandom_r is unportable - " \ "use gnulib module random_r for portability"), \ srandom_r (s,r)) # undef setstate_r -# define setstate_r(a,r) \ +# define setstate_r(a,r) \ (GL_LINK_WARNING ("setstate_r is unportable - " \ "use gnulib module random_r for portability"), \ setstate_r (a,r)) diff --git a/lib/stpncpy.c b/lib/stpncpy.c index 7a6457460..3c594917d 100644 --- a/lib/stpncpy.c +++ b/lib/stpncpy.c @@ -40,26 +40,26 @@ __stpncpy (char *dest, const char *src, size_t n) size_t n4 = n >> 2; for (;;) - { - c = *src++; - *dest++ = c; - if (c == '\0') - break; - c = *src++; - *dest++ = c; - if (c == '\0') - break; - c = *src++; - *dest++ = c; - if (c == '\0') - break; - c = *src++; - *dest++ = c; - if (c == '\0') - break; - if (--n4 == 0) - goto last_chars; - } + { + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + if (--n4 == 0) + goto last_chars; + } n -= dest - s; goto zero_fill; } @@ -75,9 +75,9 @@ __stpncpy (char *dest, const char *src, size_t n) --n; *dest++ = c; if (c == '\0') - break; + break; if (n == 0) - return dest; + return dest; } zero_fill: diff --git a/lib/str-kmp.h b/lib/str-kmp.h index cf16e4d41..4e73ff944 100644 --- a/lib/str-kmp.h +++ b/lib/str-kmp.h @@ -30,7 +30,7 @@ Return false if it was aborted because not enough memory was available. */ static bool knuth_morris_pratt_unibyte (const char *haystack, const char *needle, - const char **resultp) + const char **resultp) { size_t m = strlen (needle); @@ -62,46 +62,46 @@ knuth_morris_pratt_unibyte (const char *haystack, const char *needle, for (i = 2; i < m; i++) { - /* Here: j = i-1 - table[i-1]. - The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold - for x < table[i-1], by induction. - Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ - unsigned char b = CANON_ELEMENT ((unsigned char) needle[i - 1]); + /* Here: j = i-1 - table[i-1]. + The inequality needle[x..i-1] != needle[0..i-1-x] is known to hold + for x < table[i-1], by induction. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + unsigned char b = CANON_ELEMENT ((unsigned char) needle[i - 1]); - for (;;) - { - /* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x] - is known to hold for x < i-1-j. - Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ - if (b == CANON_ELEMENT ((unsigned char) needle[j])) - { - /* Set table[i] := i-1-j. */ - table[i] = i - ++j; - break; - } - /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds - for x = i-1-j, because - needle[i-1] != needle[j] = needle[i-1-x]. */ - if (j == 0) - { - /* The inequality holds for all possible x. */ - table[i] = i; - break; - } - /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds - for i-1-j < x < i-1-j+table[j], because for these x: - needle[x..i-2] - = needle[x-(i-1-j)..j-1] - != needle[0..j-1-(x-(i-1-j))] (by definition of table[j]) - = needle[0..i-2-x], - hence needle[x..i-1] != needle[0..i-1-x]. - Furthermore - needle[i-1-j+table[j]..i-2] - = needle[table[j]..j-1] - = needle[0..j-1-table[j]] (by definition of table[j]). */ - j = j - table[j]; - } - /* Here: j = i - table[i]. */ + for (;;) + { + /* Invariants: The inequality needle[x..i-1] != needle[0..i-1-x] + is known to hold for x < i-1-j. + Furthermore, if j>0: needle[i-1-j..i-2] = needle[0..j-1]. */ + if (b == CANON_ELEMENT ((unsigned char) needle[j])) + { + /* Set table[i] := i-1-j. */ + table[i] = i - ++j; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for x = i-1-j, because + needle[i-1] != needle[j] = needle[i-1-x]. */ + if (j == 0) + { + /* The inequality holds for all possible x. */ + table[i] = i; + break; + } + /* The inequality needle[x..i-1] != needle[0..i-1-x] also holds + for i-1-j < x < i-1-j+table[j], because for these x: + needle[x..i-2] + = needle[x-(i-1-j)..j-1] + != needle[0..j-1-(x-(i-1-j))] (by definition of table[j]) + = needle[0..i-2-x], + hence needle[x..i-1] != needle[0..i-1-x]. + Furthermore + needle[i-1-j+table[j]..i-2] + = needle[table[j]..j-1] + = needle[0..j-1-table[j]] (by definition of table[j]). */ + j = j - table[j]; + } + /* Here: j = i - table[i]. */ } } @@ -118,29 +118,29 @@ knuth_morris_pratt_unibyte (const char *haystack, const char *needle, /* Invariant: phaystack = rhaystack + j. */ while (*phaystack != '\0') if (CANON_ELEMENT ((unsigned char) needle[j]) - == CANON_ELEMENT ((unsigned char) *phaystack)) - { - j++; - phaystack++; - if (j == m) - { - /* The entire needle has been found. */ - *resultp = rhaystack; - break; - } - } + == CANON_ELEMENT ((unsigned char) *phaystack)) + { + j++; + phaystack++; + if (j == m) + { + /* The entire needle has been found. */ + *resultp = rhaystack; + break; + } + } else if (j > 0) - { - /* Found a match of needle[0..j-1], mismatch at needle[j]. */ - rhaystack += table[j]; - j -= table[j]; - } + { + /* Found a match of needle[0..j-1], mismatch at needle[j]. */ + rhaystack += table[j]; + j -= table[j]; + } else - { - /* Found a mismatch at needle[0] already. */ - rhaystack++; - phaystack++; - } + { + /* Found a mismatch at needle[0] already. */ + rhaystack++; + phaystack++; + } } freea (table); diff --git a/lib/str-two-way.h b/lib/str-two-way.h index b0338a70a..28e4265ad 100644 --- a/lib/str-two-way.h +++ b/lib/str-two-way.h @@ -21,21 +21,21 @@ , 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. + 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. + 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. + 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. @@ -103,7 +103,7 @@ periodicity. */ static size_t critical_factorization (const unsigned char *needle, size_t needle_len, - size_t *period) + size_t *period) { /* Index of last byte of left half, or SIZE_MAX. */ size_t max_suffix, max_suffix_rev; @@ -130,29 +130,29 @@ critical_factorization (const unsigned char *needle, size_t 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; - } + { + /* 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; - } - } + { + /* 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; - } + { + /* Suffix is larger, start over from current location. */ + max_suffix = j++; + k = p = 1; + } } *period = p; @@ -165,29 +165,29 @@ critical_factorization (const unsigned char *needle, size_t 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; - } + { + /* 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; - } - } + { + /* 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; - } + { + /* Suffix is larger, start over from current location. */ + max_suffix_rev = j++; + k = p = 1; + } } /* Choose the longer suffix. Return the first byte of the right @@ -210,7 +210,7 @@ critical_factorization (const unsigned char *needle, size_t needle_len, 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) + 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. */ @@ -227,65 +227,65 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len, if (CMP_FUNC (needle, needle + period, suffix) == 0) { /* Entire needle is periodic; a mismatch can only advance by the - period, so use memory to avoid rescanning known occurrences - of the period. */ + period, so use memory to avoid rescanning known occurrences + of the period. */ 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; - } - } + { + /* 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. */ + 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; - } + { + /* 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; } @@ -304,7 +304,7 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len, 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) + 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. */ @@ -331,93 +331,93 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len, if (CMP_FUNC (needle, needle + period, suffix) == 0) { /* Entire needle is periodic; a mismatch can only advance by the - period, so use memory to avoid rescanning known occurrences - of the period. */ + period, so use memory to avoid rescanning known occurrences + of the period. */ 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; - } - } + { + /* 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. */ + 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; - } + { + /* 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; } diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c index c605fb0f5..575e2cd05 100644 --- a/lib/strcasecmp.c +++ b/lib/strcasecmp.c @@ -46,7 +46,7 @@ strcasecmp (const char *s1, const char *s2) c2 = TOLOWER (*p2); if (c1 == '\0') - break; + break; ++p1; ++p2; diff --git a/lib/strcasestr.c b/lib/strcasestr.c index fe970ae84..d31428228 100644 --- a/lib/strcasestr.c +++ b/lib/strcasestr.c @@ -29,11 +29,11 @@ /* Two-Way algorithm. */ #define RETURN_TYPE char * -#define AVAILABLE(h, h_l, j, n_l) \ - (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ +#define AVAILABLE(h, h_l, j, n_l) \ + (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ && ((h_l) = (j) + (n_l))) #define CANON_ELEMENT(c) TOLOWER (c) -#define CMP_FUNC(p1, p2, l) \ +#define CMP_FUNC(p1, p2, l) \ strncasecmp ((const char *) (p1), (const char *) (p2), l) #include "str-two-way.h" @@ -55,7 +55,7 @@ strcasestr (const char *haystack_start, const char *needle_start) while (*haystack && *needle) { ok &= (TOLOWER ((unsigned char) *haystack) - == TOLOWER ((unsigned char) *needle)); + == TOLOWER ((unsigned char) *needle)); haystack++; needle++; } @@ -72,12 +72,12 @@ strcasestr (const char *haystack_start, const char *needle_start) 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_start, - needle_len); + haystack_len, + (const unsigned char *) needle_start, + needle_len); return two_way_long_needle ((const unsigned char *) haystack, haystack_len, - (const unsigned char *) needle_start, - needle_len); + (const unsigned char *) needle_start, + needle_len); } #undef LONG_NEEDLE_THRESHOLD diff --git a/lib/strerror.c b/lib/strerror.c index dfe6c25f2..fa0ed1474 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -334,10 +334,10 @@ rpl_strerror (int n) if (result == NULL || result[0] == '\0') { - static char const fmt[] = "Unknown error (%d)"; - static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)]; - sprintf (msg_buf, fmt, n); - return msg_buf; + static char const fmt[] = "Unknown error (%d)"; + static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)]; + sprintf (msg_buf, fmt, n); + return msg_buf; } return result; diff --git a/lib/strftime.c b/lib/strftime.c index 4ca2ffa4f..a355b27fd 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -97,9 +97,9 @@ extern char *tzname[]; implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift right in the usual way when A < 0, so SHR falls back on division if ordinary A >> B doesn't seem to be the usual signed shift. */ -#define SHR(a, b) \ - (-1 >> 1 == -1 \ - ? (a) >> (b) \ +#define SHR(a, b) \ + (-1 >> 1 == -1 \ + ? (a) >> (b) \ : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) /* Bound on length of the string representing an integer type or expression T. @@ -114,7 +114,7 @@ extern char *tzname[]; #ifndef __isleap /* Nonzero if YEAR is a leap year (every 4 years, except every 100th isn't, and every 400th is). */ -# define __isleap(year) \ +# define __isleap(year) \ ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) #endif @@ -167,27 +167,27 @@ extern char *tzname[]; # define advance(P, N) ((P) += (N)) #endif -#define add(n, f) \ - do \ - { \ - int _n = (n); \ - int _delta = width - _n; \ - int _incr = _n + (_delta > 0 ? _delta : 0); \ - if ((size_t) _incr >= maxsize - i) \ - return 0; \ - if (p) \ - { \ - if (digits == 0 && _delta > 0) \ - { \ - if (pad == L_('0')) \ - memset_zero (p, _delta); \ - else \ - memset_space (p, _delta); \ - } \ - f; \ - advance (p, _n); \ - } \ - i += _incr; \ +#define add(n, f) \ + do \ + { \ + int _n = (n); \ + int _delta = width - _n; \ + int _incr = _n + (_delta > 0 ? _delta : 0); \ + if ((size_t) _incr >= maxsize - i) \ + return 0; \ + if (p) \ + { \ + if (digits == 0 && _delta > 0) \ + { \ + if (pad == L_('0')) \ + memset_zero (p, _delta); \ + else \ + memset_space (p, _delta); \ + } \ + f; \ + advance (p, _n); \ + } \ + i += _incr; \ } while (0) #if FPRINTFTIME @@ -198,35 +198,35 @@ extern char *tzname[]; #if FPRINTFTIME # define cpy(n, s) \ - add ((n), \ - do \ - { \ - if (to_lowcase) \ - fwrite_lowcase (p, (s), _n); \ - else if (to_uppcase) \ - fwrite_uppcase (p, (s), _n); \ - else \ - { \ - /* We are ignoring the value of fwrite here, in spite of the \ - fact that technically, that may not be valid: the fwrite \ - specification in POSIX 2008 defers to that of fputc, which \ - is intended to be consistent with the one from ISO C, \ - which permits failure due to ENOMEM *without* setting the \ - stream's error indicator. */ \ - ignore_value (fwrite ((s), _n, 1, p)); \ - } \ - } \ - while (0) \ + add ((n), \ + do \ + { \ + if (to_lowcase) \ + fwrite_lowcase (p, (s), _n); \ + else if (to_uppcase) \ + fwrite_uppcase (p, (s), _n); \ + else \ + { \ + /* We are ignoring the value of fwrite here, in spite of the \ + fact that technically, that may not be valid: the fwrite \ + specification in POSIX 2008 defers to that of fputc, which \ + is intended to be consistent with the one from ISO C, \ + which permits failure due to ENOMEM *without* setting the \ + stream's error indicator. */ \ + ignore_value (fwrite ((s), _n, 1, p)); \ + } \ + } \ + while (0) \ ) #else -# define cpy(n, s) \ - add ((n), \ - if (to_lowcase) \ - memcpy_lowcase (p, (s), _n LOCALE_ARG); \ - else if (to_uppcase) \ - memcpy_uppcase (p, (s), _n LOCALE_ARG); \ - else \ - MEMCPY ((void *) p, (void const *) (s), _n)) +# define cpy(n, s) \ + add ((n), \ + if (to_lowcase) \ + memcpy_lowcase (p, (s), _n LOCALE_ARG); \ + else if (to_uppcase) \ + memcpy_uppcase (p, (s), _n LOCALE_ARG); \ + else \ + MEMCPY ((void *) p, (void const *) (s), _n)) #endif #ifdef COMPILE_WIDE @@ -235,13 +235,13 @@ extern char *tzname[]; # define __mbsrtowcs_l(d, s, l, st, loc) __mbsrtowcs (d, s, l, st) # endif # define widen(os, ws, l) \ - { \ - mbstate_t __st; \ - const char *__s = os; \ - memset (&__st, '\0', sizeof (__st)); \ - l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \ - ws = (wchar_t *) alloca ((l + 1) * sizeof (wchar_t)); \ - (void) __mbsrtowcs_l (ws, &__s, l, &__st, loc); \ + { \ + mbstate_t __st; \ + const char *__s = os; \ + memset (&__st, '\0', sizeof (__st)); \ + l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \ + ws = (wchar_t *) alloca ((l + 1) * sizeof (wchar_t)); \ + (void) __mbsrtowcs_l (ws, &__s, l, &__st, loc); \ } #endif @@ -251,8 +251,8 @@ extern char *tzname[]; 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. */ -# define strftime __strftime_l -# define wcsftime __wcsftime_l +# define strftime __strftime_l +# define wcsftime __wcsftime_l # undef _NL_CURRENT # define _NL_CURRENT(category, item) \ (current->values[_NL_ITEM_INDEX (item)].string) @@ -315,7 +315,7 @@ fwrite_uppcase (FILE *fp, const CHAR_T *src, size_t len) #else static CHAR_T * memcpy_lowcase (CHAR_T *dest, const CHAR_T *src, - size_t len LOCALE_PARAM_PROTO) + size_t len LOCALE_PARAM_PROTO) { while (len-- > 0) dest[len] = TOLOWER ((UCHAR_T) src[len], loc); @@ -324,7 +324,7 @@ memcpy_lowcase (CHAR_T *dest, const CHAR_T *src, static CHAR_T * memcpy_uppcase (CHAR_T *dest, const CHAR_T *src, - size_t len LOCALE_PARAM_PROTO) + size_t len LOCALE_PARAM_PROTO) { while (len-- > 0) dest[len] = TOUPPER ((UCHAR_T) src[len], loc); @@ -352,10 +352,10 @@ tm_diff (const struct tm *a, const struct tm *b) int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); int years = a->tm_year - b->tm_year; int days = (365 * years + intervening_leap_days - + (a->tm_yday - b->tm_yday)); + + (a->tm_yday - b->tm_yday)); return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) - + (a->tm_min - b->tm_min)) - + (a->tm_sec - b->tm_sec)); + + (a->tm_min - b->tm_min)) + + (a->tm_sec - b->tm_sec)); } #endif /* ! HAVE_TM_GMTOFF */ @@ -377,8 +377,8 @@ iso_week_days (int yday, int wday) /* Add enough to the first operand of % to make it nonnegative. */ int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7; return (yday - - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7 - + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY); + - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7 + + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY); } @@ -419,9 +419,9 @@ iso_week_days (int yday, int wday) to indicate that the result should be converted to upper case. */ static size_t strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, - STRFTIME_ARG (size_t maxsize) - const CHAR_T *format, - const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO) + STRFTIME_ARG (size_t maxsize) + const CHAR_T *format, + const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO) { #if defined _LIBC && defined USE_IN_EXTENDED_LOCALE_MODEL struct locale_data *const current = loc->__locales[LC_TIME]; @@ -447,8 +447,8 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, # define f_month \ ((const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(MON_1) + tp->tm_mon)) # define ampm \ - ((const CHAR_T *) _NL_CURRENT (LC_TIME, tp->tm_hour > 11 \ - ? NLW(PM_STR) : NLW(AM_STR))) + ((const CHAR_T *) _NL_CURRENT (LC_TIME, tp->tm_hour > 11 \ + ? NLW(PM_STR) : NLW(AM_STR))) # define aw_len STRLEN (a_wkday) # define am_len STRLEN (a_month) @@ -485,12 +485,12 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, if (ut) { if (! (zone && *zone)) - zone = "GMT"; + zone = "GMT"; } else { /* POSIX.1 requires that local time zone information be used as - though strftime called tzset. */ + though strftime called tzset. */ # if HAVE_TZSET tzset (); # endif @@ -505,22 +505,22 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, for (f = format; *f != '\0'; ++f) { - int pad = 0; /* Padding for number ('-', '_', or 0). */ - int modifier; /* Field modifier ('E', 'O', or 0). */ - int digits = 0; /* Max digits for numeric format. */ - int number_value; /* Numeric value to be printed. */ + int pad = 0; /* Padding for number ('-', '_', or 0). */ + int modifier; /* Field modifier ('E', 'O', or 0). */ + int digits = 0; /* Max digits for numeric format. */ + int number_value; /* Numeric value to be printed. */ unsigned int u_number_value; /* (unsigned int) number_value. */ - bool negative_number; /* The number is negative. */ + bool negative_number; /* The number is negative. */ bool always_output_a_sign; /* +/- should always be output. */ - int tz_colon_mask; /* Bitmask of where ':' should appear. */ + int tz_colon_mask; /* Bitmask of where ':' should appear. */ const CHAR_T *subfmt; CHAR_T sign_char; CHAR_T *bufp; CHAR_T buf[1 - + 2 /* for the two colons in a %::z or %:::z time zone */ - + (sizeof (int) < sizeof (time_t) - ? INT_STRLEN_BOUND (time_t) - : INT_STRLEN_BOUND (int))]; + + 2 /* for the two colons in a %::z or %:::z time zone */ + + (sizeof (int) < sizeof (time_t) + ? INT_STRLEN_BOUND (time_t) + : INT_STRLEN_BOUND (int))]; int width = -1; bool to_lowcase = false; bool to_uppcase = upcase; @@ -530,900 +530,900 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, #if DO_MULTIBYTE && !defined COMPILE_WIDE switch (*f) - { - case L_('%'): - break; - - case L_('\b'): case L_('\t'): case L_('\n'): - case L_('\v'): case L_('\f'): case L_('\r'): - case L_(' '): case L_('!'): case L_('"'): case L_('#'): case L_('&'): - case L_('\''): case L_('('): case L_(')'): case L_('*'): case L_('+'): - case L_(','): case L_('-'): case L_('.'): case L_('/'): case L_('0'): - case L_('1'): case L_('2'): case L_('3'): case L_('4'): case L_('5'): - case L_('6'): case L_('7'): case L_('8'): case L_('9'): case L_(':'): - case L_(';'): case L_('<'): case L_('='): case L_('>'): case L_('?'): - case L_('A'): case L_('B'): case L_('C'): case L_('D'): case L_('E'): - case L_('F'): case L_('G'): case L_('H'): case L_('I'): case L_('J'): - case L_('K'): case L_('L'): case L_('M'): case L_('N'): case L_('O'): - case L_('P'): case L_('Q'): case L_('R'): case L_('S'): case L_('T'): - case L_('U'): case L_('V'): case L_('W'): case L_('X'): case L_('Y'): - case L_('Z'): case L_('['): case L_('\\'): case L_(']'): case L_('^'): - case L_('_'): case L_('a'): case L_('b'): case L_('c'): case L_('d'): - case L_('e'): case L_('f'): case L_('g'): case L_('h'): case L_('i'): - case L_('j'): case L_('k'): case L_('l'): case L_('m'): case L_('n'): - case L_('o'): case L_('p'): case L_('q'): case L_('r'): case L_('s'): - case L_('t'): case L_('u'): case L_('v'): case L_('w'): case L_('x'): - case L_('y'): case L_('z'): case L_('{'): case L_('|'): case L_('}'): - case L_('~'): - /* The C Standard requires these 98 characters (plus '%') to - be in the basic execution character set. None of these - characters can start a multibyte sequence, so they need - not be analyzed further. */ - add1 (*f); - continue; - - default: - /* Copy this multibyte sequence until we reach its end, find - an error, or come back to the initial shift state. */ - { - mbstate_t mbstate = mbstate_zero; - size_t len = 0; - size_t fsize; - - if (! format_end) - format_end = f + strlen (f) + 1; - fsize = format_end - f; - - do - { - size_t bytes = mbrlen (f + len, fsize - len, &mbstate); - - if (bytes == 0) - break; - - if (bytes == (size_t) -2) - { - len += strlen (f + len); - break; - } - - if (bytes == (size_t) -1) - { - len++; - break; - } - - len += bytes; - } - while (! mbsinit (&mbstate)); - - cpy (len, f); - f += len - 1; - continue; - } - } + { + case L_('%'): + break; + + case L_('\b'): case L_('\t'): case L_('\n'): + case L_('\v'): case L_('\f'): case L_('\r'): + case L_(' '): case L_('!'): case L_('"'): case L_('#'): case L_('&'): + case L_('\''): case L_('('): case L_(')'): case L_('*'): case L_('+'): + case L_(','): case L_('-'): case L_('.'): case L_('/'): case L_('0'): + case L_('1'): case L_('2'): case L_('3'): case L_('4'): case L_('5'): + case L_('6'): case L_('7'): case L_('8'): case L_('9'): case L_(':'): + case L_(';'): case L_('<'): case L_('='): case L_('>'): case L_('?'): + case L_('A'): case L_('B'): case L_('C'): case L_('D'): case L_('E'): + case L_('F'): case L_('G'): case L_('H'): case L_('I'): case L_('J'): + case L_('K'): case L_('L'): case L_('M'): case L_('N'): case L_('O'): + case L_('P'): case L_('Q'): case L_('R'): case L_('S'): case L_('T'): + case L_('U'): case L_('V'): case L_('W'): case L_('X'): case L_('Y'): + case L_('Z'): case L_('['): case L_('\\'): case L_(']'): case L_('^'): + case L_('_'): case L_('a'): case L_('b'): case L_('c'): case L_('d'): + case L_('e'): case L_('f'): case L_('g'): case L_('h'): case L_('i'): + case L_('j'): case L_('k'): case L_('l'): case L_('m'): case L_('n'): + case L_('o'): case L_('p'): case L_('q'): case L_('r'): case L_('s'): + case L_('t'): case L_('u'): case L_('v'): case L_('w'): case L_('x'): + case L_('y'): case L_('z'): case L_('{'): case L_('|'): case L_('}'): + case L_('~'): + /* The C Standard requires these 98 characters (plus '%') to + be in the basic execution character set. None of these + characters can start a multibyte sequence, so they need + not be analyzed further. */ + add1 (*f); + continue; + + default: + /* Copy this multibyte sequence until we reach its end, find + an error, or come back to the initial shift state. */ + { + mbstate_t mbstate = mbstate_zero; + size_t len = 0; + size_t fsize; + + if (! format_end) + format_end = f + strlen (f) + 1; + fsize = format_end - f; + + do + { + size_t bytes = mbrlen (f + len, fsize - len, &mbstate); + + if (bytes == 0) + break; + + if (bytes == (size_t) -2) + { + len += strlen (f + len); + break; + } + + if (bytes == (size_t) -1) + { + len++; + break; + } + + len += bytes; + } + while (! mbsinit (&mbstate)); + + cpy (len, f); + f += len - 1; + continue; + } + } #else /* ! DO_MULTIBYTE */ /* Either multibyte encodings are not supported, they are - safe for formats, so any non-'%' byte can be copied through, - or this is the wide character version. */ + safe for formats, so any non-'%' byte can be copied through, + or this is the wide character version. */ if (*f != L_('%')) - { - add1 (*f); - continue; - } + { + add1 (*f); + continue; + } #endif /* ! DO_MULTIBYTE */ /* Check for flags that can modify a format. */ while (1) - { - switch (*++f) - { - /* This influences the number formats. */ - case L_('_'): - case L_('-'): - case L_('0'): - pad = *f; - continue; - - /* This changes textual output. */ - case L_('^'): - to_uppcase = true; - continue; - case L_('#'): - change_case = true; - continue; - - default: - break; - } - break; - } + { + switch (*++f) + { + /* This influences the number formats. */ + case L_('_'): + case L_('-'): + case L_('0'): + pad = *f; + continue; + + /* This changes textual output. */ + case L_('^'): + to_uppcase = true; + continue; + case L_('#'): + change_case = true; + continue; + + default: + break; + } + break; + } /* As a GNU extension we allow to specify the field width. */ if (ISDIGIT (*f)) - { - width = 0; - do - { - if (width > INT_MAX / 10 - || (width == INT_MAX / 10 && *f - L_('0') > INT_MAX % 10)) - /* Avoid overflow. */ - width = INT_MAX; - else - { - width *= 10; - width += *f - L_('0'); - } - ++f; - } - while (ISDIGIT (*f)); - } + { + width = 0; + do + { + if (width > INT_MAX / 10 + || (width == INT_MAX / 10 && *f - L_('0') > INT_MAX % 10)) + /* Avoid overflow. */ + width = INT_MAX; + else + { + width *= 10; + width += *f - L_('0'); + } + ++f; + } + while (ISDIGIT (*f)); + } /* Check for modifiers. */ switch (*f) - { - case L_('E'): - case L_('O'): - modifier = *f++; - break; + { + case L_('E'): + case L_('O'): + modifier = *f++; + break; - default: - modifier = 0; - break; - } + default: + modifier = 0; + break; + } /* Now do the specified format. */ format_char = *f; switch (format_char) - { + { #define DO_NUMBER(d, v) \ - digits = d; \ - number_value = v; goto do_number + digits = d; \ + number_value = v; goto do_number #define DO_SIGNED_NUMBER(d, negative, v) \ - digits = d; \ - negative_number = negative; \ - u_number_value = v; goto do_signed_number + digits = d; \ + negative_number = negative; \ + u_number_value = v; goto do_signed_number - /* The mask is not what you might think. - When the ordinal i'th bit is set, insert a colon - before the i'th digit of the time zone representation. */ + /* The mask is not what you might think. + When the ordinal i'th bit is set, insert a colon + before the i'th digit of the time zone representation. */ #define DO_TZ_OFFSET(d, negative, mask, v) \ - digits = d; \ - negative_number = negative; \ - tz_colon_mask = mask; \ - u_number_value = v; goto do_tz_offset + digits = d; \ + negative_number = negative; \ + tz_colon_mask = mask; \ + u_number_value = v; goto do_tz_offset #define DO_NUMBER_SPACEPAD(d, v) \ - digits = d; \ - number_value = v; goto do_number_spacepad - - case L_('%'): - if (modifier != 0) - goto bad_format; - add1 (*f); - break; - - case L_('a'): - if (modifier != 0) - goto bad_format; - if (change_case) - { - to_uppcase = true; - to_lowcase = false; - } + digits = d; \ + number_value = v; goto do_number_spacepad + + case L_('%'): + if (modifier != 0) + goto bad_format; + add1 (*f); + break; + + case L_('a'): + if (modifier != 0) + goto bad_format; + if (change_case) + { + to_uppcase = true; + to_lowcase = false; + } #ifdef _NL_CURRENT - cpy (aw_len, a_wkday); - break; + cpy (aw_len, a_wkday); + break; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case 'A': - if (modifier != 0) - goto bad_format; - if (change_case) - { - to_uppcase = true; - to_lowcase = false; - } + case 'A': + if (modifier != 0) + goto bad_format; + if (change_case) + { + to_uppcase = true; + to_lowcase = false; + } #ifdef _NL_CURRENT - cpy (STRLEN (f_wkday), f_wkday); - break; + cpy (STRLEN (f_wkday), f_wkday); + break; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case L_('b'): - case L_('h'): - if (change_case) - { - to_uppcase = true; - to_lowcase = false; - } - if (modifier != 0) - goto bad_format; + case L_('b'): + case L_('h'): + if (change_case) + { + to_uppcase = true; + to_lowcase = false; + } + if (modifier != 0) + goto bad_format; #ifdef _NL_CURRENT - cpy (am_len, a_month); - break; + cpy (am_len, a_month); + break; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case L_('B'): - if (modifier != 0) - goto bad_format; - if (change_case) - { - to_uppcase = true; - to_lowcase = false; - } + case L_('B'): + if (modifier != 0) + goto bad_format; + if (change_case) + { + to_uppcase = true; + to_lowcase = false; + } #ifdef _NL_CURRENT - cpy (STRLEN (f_month), f_month); - break; + cpy (STRLEN (f_month), f_month); + break; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case L_('c'): - if (modifier == L_('O')) - goto bad_format; + case L_('c'): + if (modifier == L_('O')) + goto bad_format; #ifdef _NL_CURRENT - if (! (modifier == 'E' - && (*(subfmt = - (const CHAR_T *) _NL_CURRENT (LC_TIME, - NLW(ERA_D_T_FMT))) - != '\0'))) - subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_T_FMT)); + if (! (modifier == 'E' + && (*(subfmt = + (const CHAR_T *) _NL_CURRENT (LC_TIME, + NLW(ERA_D_T_FMT))) + != '\0'))) + subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_T_FMT)); #else - goto underlying_strftime; + goto underlying_strftime; #endif - subformat: - { - size_t len = strftime_case_ (to_uppcase, - NULL, STRFTIME_ARG ((size_t) -1) - subfmt, - tp extra_args LOCALE_ARG); - add (len, strftime_case_ (to_uppcase, p, - STRFTIME_ARG (maxsize - i) - subfmt, - tp extra_args LOCALE_ARG)); - } - break; + subformat: + { + size_t len = strftime_case_ (to_uppcase, + NULL, STRFTIME_ARG ((size_t) -1) + subfmt, + tp extra_args LOCALE_ARG); + add (len, strftime_case_ (to_uppcase, p, + STRFTIME_ARG (maxsize - i) + subfmt, + tp extra_args LOCALE_ARG)); + } + break; #if !(defined _NL_CURRENT && HAVE_STRUCT_ERA_ENTRY) - underlying_strftime: - { - /* The relevant information is available only via the - underlying strftime implementation, so use that. */ - char ufmt[5]; - char *u = ufmt; - char ubuf[1024]; /* enough for any single format in practice */ - size_t len; - /* Make sure we're calling the actual underlying strftime. - In some cases, config.h contains something like - "#define strftime rpl_strftime". */ + underlying_strftime: + { + /* The relevant information is available only via the + underlying strftime implementation, so use that. */ + char ufmt[5]; + char *u = ufmt; + char ubuf[1024]; /* enough for any single format in practice */ + size_t len; + /* Make sure we're calling the actual underlying strftime. + In some cases, config.h contains something like + "#define strftime rpl_strftime". */ # ifdef strftime # undef strftime - size_t strftime (); + size_t strftime (); # endif - /* The space helps distinguish strftime failure from empty - output. */ - *u++ = ' '; - *u++ = '%'; - if (modifier != 0) - *u++ = modifier; - *u++ = format_char; - *u = '\0'; - len = strftime (ubuf, sizeof ubuf, ufmt, tp); - if (len != 0) - cpy (len - 1, ubuf + 1); - } - break; + /* The space helps distinguish strftime failure from empty + output. */ + *u++ = ' '; + *u++ = '%'; + if (modifier != 0) + *u++ = modifier; + *u++ = format_char; + *u = '\0'; + len = strftime (ubuf, sizeof ubuf, ufmt, tp); + if (len != 0) + cpy (len - 1, ubuf + 1); + } + break; #endif - case L_('C'): - if (modifier == L_('O')) - goto bad_format; - if (modifier == L_('E')) - { + case L_('C'): + if (modifier == L_('O')) + goto bad_format; + if (modifier == L_('E')) + { #if HAVE_STRUCT_ERA_ENTRY - struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); - if (era) - { + struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); + if (era) + { # ifdef COMPILE_WIDE - size_t len = __wcslen (era->era_wname); - cpy (len, era->era_wname); + size_t len = __wcslen (era->era_wname); + cpy (len, era->era_wname); # else - size_t len = strlen (era->era_name); - cpy (len, era->era_name); + size_t len = strlen (era->era_name); + cpy (len, era->era_name); # endif - break; - } + break; + } #else - goto underlying_strftime; + goto underlying_strftime; #endif - } + } - { - int century = tp->tm_year / 100 + TM_YEAR_BASE / 100; - century -= tp->tm_year % 100 < 0 && 0 < century; - DO_SIGNED_NUMBER (2, tp->tm_year < - TM_YEAR_BASE, century); - } + { + int century = tp->tm_year / 100 + TM_YEAR_BASE / 100; + century -= tp->tm_year % 100 < 0 && 0 < century; + DO_SIGNED_NUMBER (2, tp->tm_year < - TM_YEAR_BASE, century); + } - case L_('x'): - if (modifier == L_('O')) - goto bad_format; + case L_('x'): + if (modifier == L_('O')) + goto bad_format; #ifdef _NL_CURRENT - if (! (modifier == L_('E') - && (*(subfmt = - (const CHAR_T *)_NL_CURRENT (LC_TIME, NLW(ERA_D_FMT))) - != L_('\0')))) - subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_FMT)); - goto subformat; + if (! (modifier == L_('E') + && (*(subfmt = + (const CHAR_T *)_NL_CURRENT (LC_TIME, NLW(ERA_D_FMT))) + != L_('\0')))) + subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(D_FMT)); + goto subformat; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case L_('D'): - if (modifier != 0) - goto bad_format; - subfmt = L_("%m/%d/%y"); - goto subformat; - - case L_('d'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER (2, tp->tm_mday); - - case L_('e'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER_SPACEPAD (2, tp->tm_mday); - - /* All numeric formats set DIGITS and NUMBER_VALUE (or U_NUMBER_VALUE) - and then jump to one of these labels. */ - - do_tz_offset: - always_output_a_sign = true; - goto do_number_body; - - do_number_spacepad: - /* Force `_' flag unless overridden by `0' or `-' flag. */ - if (pad != L_('0') && pad != L_('-')) - pad = L_('_'); - - do_number: - /* Format NUMBER_VALUE according to the MODIFIER flag. */ - negative_number = number_value < 0; - u_number_value = number_value; - - do_signed_number: - always_output_a_sign = false; - tz_colon_mask = 0; - - do_number_body: - /* Format U_NUMBER_VALUE according to the MODIFIER flag. - NEGATIVE_NUMBER is nonzero if the original number was - negative; in this case it was converted directly to - unsigned int (i.e., modulo (UINT_MAX + 1)) without - negating it. */ - if (modifier == L_('O') && !negative_number) - { + case L_('D'): + if (modifier != 0) + goto bad_format; + subfmt = L_("%m/%d/%y"); + goto subformat; + + case L_('d'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER (2, tp->tm_mday); + + case L_('e'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER_SPACEPAD (2, tp->tm_mday); + + /* All numeric formats set DIGITS and NUMBER_VALUE (or U_NUMBER_VALUE) + and then jump to one of these labels. */ + + do_tz_offset: + always_output_a_sign = true; + goto do_number_body; + + do_number_spacepad: + /* Force `_' flag unless overridden by `0' or `-' flag. */ + if (pad != L_('0') && pad != L_('-')) + pad = L_('_'); + + do_number: + /* Format NUMBER_VALUE according to the MODIFIER flag. */ + negative_number = number_value < 0; + u_number_value = number_value; + + do_signed_number: + always_output_a_sign = false; + tz_colon_mask = 0; + + do_number_body: + /* Format U_NUMBER_VALUE according to the MODIFIER flag. + NEGATIVE_NUMBER is nonzero if the original number was + negative; in this case it was converted directly to + unsigned int (i.e., modulo (UINT_MAX + 1)) without + negating it. */ + if (modifier == L_('O') && !negative_number) + { #ifdef _NL_CURRENT - /* Get the locale specific alternate representation of - the number. If none exist NULL is returned. */ - const CHAR_T *cp = nl_get_alt_digit (u_number_value - HELPER_LOCALE_ARG); - - if (cp != NULL) - { - size_t digitlen = STRLEN (cp); - if (digitlen != 0) - { - cpy (digitlen, cp); - break; - } - } + /* Get the locale specific alternate representation of + the number. If none exist NULL is returned. */ + const CHAR_T *cp = nl_get_alt_digit (u_number_value + HELPER_LOCALE_ARG); + + if (cp != NULL) + { + size_t digitlen = STRLEN (cp); + if (digitlen != 0) + { + cpy (digitlen, cp); + break; + } + } #else - goto underlying_strftime; + goto underlying_strftime; #endif - } - - bufp = buf + sizeof (buf) / sizeof (buf[0]); - - if (negative_number) - u_number_value = - u_number_value; - - do - { - if (tz_colon_mask & 1) - *--bufp = ':'; - tz_colon_mask >>= 1; - *--bufp = u_number_value % 10 + L_('0'); - u_number_value /= 10; - } - while (u_number_value != 0 || tz_colon_mask != 0); - - do_number_sign_and_padding: - if (digits < width) - digits = width; - - sign_char = (negative_number ? L_('-') - : always_output_a_sign ? L_('+') - : 0); - - if (pad == L_('-')) - { - if (sign_char) - add1 (sign_char); - } - else - { - int padding = digits - (buf + (sizeof (buf) / sizeof (buf[0])) - - bufp) - !!sign_char; - - if (padding > 0) - { - if (pad == L_('_')) - { - if ((size_t) padding >= maxsize - i) - return 0; - - if (p) - memset_space (p, padding); - i += padding; - width = width > padding ? width - padding : 0; - if (sign_char) - add1 (sign_char); - } - else - { - if ((size_t) digits >= maxsize - i) - return 0; - - if (sign_char) - add1 (sign_char); - - if (p) - memset_zero (p, padding); - i += padding; - width = 0; - } - } - else - { - if (sign_char) - add1 (sign_char); - } - } - - cpy (buf + sizeof (buf) / sizeof (buf[0]) - bufp, bufp); - break; - - case L_('F'): - if (modifier != 0) - goto bad_format; - subfmt = L_("%Y-%m-%d"); - goto subformat; - - case L_('H'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER (2, tp->tm_hour); - - case L_('I'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER (2, hour12); - - case L_('k'): /* GNU extension. */ - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER_SPACEPAD (2, tp->tm_hour); - - case L_('l'): /* GNU extension. */ - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER_SPACEPAD (2, hour12); - - case L_('j'): - if (modifier == L_('E')) - goto bad_format; - - DO_SIGNED_NUMBER (3, tp->tm_yday < -1, tp->tm_yday + 1U); - - case L_('M'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER (2, tp->tm_min); - - case L_('m'): - if (modifier == L_('E')) - goto bad_format; - - DO_SIGNED_NUMBER (2, tp->tm_mon < -1, tp->tm_mon + 1U); + } + + bufp = buf + sizeof (buf) / sizeof (buf[0]); + + if (negative_number) + u_number_value = - u_number_value; + + do + { + if (tz_colon_mask & 1) + *--bufp = ':'; + tz_colon_mask >>= 1; + *--bufp = u_number_value % 10 + L_('0'); + u_number_value /= 10; + } + while (u_number_value != 0 || tz_colon_mask != 0); + + do_number_sign_and_padding: + if (digits < width) + digits = width; + + sign_char = (negative_number ? L_('-') + : always_output_a_sign ? L_('+') + : 0); + + if (pad == L_('-')) + { + if (sign_char) + add1 (sign_char); + } + else + { + int padding = digits - (buf + (sizeof (buf) / sizeof (buf[0])) + - bufp) - !!sign_char; + + if (padding > 0) + { + if (pad == L_('_')) + { + if ((size_t) padding >= maxsize - i) + return 0; + + if (p) + memset_space (p, padding); + i += padding; + width = width > padding ? width - padding : 0; + if (sign_char) + add1 (sign_char); + } + else + { + if ((size_t) digits >= maxsize - i) + return 0; + + if (sign_char) + add1 (sign_char); + + if (p) + memset_zero (p, padding); + i += padding; + width = 0; + } + } + else + { + if (sign_char) + add1 (sign_char); + } + } + + cpy (buf + sizeof (buf) / sizeof (buf[0]) - bufp, bufp); + break; + + case L_('F'): + if (modifier != 0) + goto bad_format; + subfmt = L_("%Y-%m-%d"); + goto subformat; + + case L_('H'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER (2, tp->tm_hour); + + case L_('I'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER (2, hour12); + + case L_('k'): /* GNU extension. */ + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER_SPACEPAD (2, tp->tm_hour); + + case L_('l'): /* GNU extension. */ + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER_SPACEPAD (2, hour12); + + case L_('j'): + if (modifier == L_('E')) + goto bad_format; + + DO_SIGNED_NUMBER (3, tp->tm_yday < -1, tp->tm_yday + 1U); + + case L_('M'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER (2, tp->tm_min); + + case L_('m'): + if (modifier == L_('E')) + goto bad_format; + + DO_SIGNED_NUMBER (2, tp->tm_mon < -1, tp->tm_mon + 1U); #ifndef _LIBC - case L_('N'): /* GNU extension. */ - if (modifier == L_('E')) - goto bad_format; - - number_value = ns; - if (width == -1) - width = 9; - else - { - /* Take an explicit width less than 9 as a precision. */ - int j; - for (j = width; j < 9; j++) - number_value /= 10; - } - - DO_NUMBER (width, number_value); + case L_('N'): /* GNU extension. */ + if (modifier == L_('E')) + goto bad_format; + + number_value = ns; + if (width == -1) + width = 9; + else + { + /* Take an explicit width less than 9 as a precision. */ + int j; + for (j = width; j < 9; j++) + number_value /= 10; + } + + DO_NUMBER (width, number_value); #endif - case L_('n'): - add1 (L_('\n')); - break; + case L_('n'): + add1 (L_('\n')); + break; - case L_('P'): - to_lowcase = true; + case L_('P'): + to_lowcase = true; #ifndef _NL_CURRENT - format_char = L_('p'); + format_char = L_('p'); #endif - /* FALLTHROUGH */ - - case L_('p'): - if (change_case) - { - to_uppcase = false; - to_lowcase = true; - } + /* FALLTHROUGH */ + + case L_('p'): + if (change_case) + { + to_uppcase = false; + to_lowcase = true; + } #ifdef _NL_CURRENT - cpy (ap_len, ampm); - break; + cpy (ap_len, ampm); + break; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case L_('R'): - subfmt = L_("%H:%M"); - goto subformat; + case L_('R'): + subfmt = L_("%H:%M"); + goto subformat; - case L_('r'): + case L_('r'): #ifdef _NL_CURRENT - if (*(subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, - NLW(T_FMT_AMPM))) - == L_('\0')) - subfmt = L_("%I:%M:%S %p"); - goto subformat; + if (*(subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, + NLW(T_FMT_AMPM))) + == L_('\0')) + subfmt = L_("%I:%M:%S %p"); + goto subformat; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case L_('S'): - if (modifier == L_('E')) - goto bad_format; + case L_('S'): + if (modifier == L_('E')) + goto bad_format; - DO_NUMBER (2, tp->tm_sec); + DO_NUMBER (2, tp->tm_sec); - case L_('s'): /* GNU extension. */ - { - struct tm ltm; - time_t t; + case L_('s'): /* GNU extension. */ + { + struct tm ltm; + time_t t; - ltm = *tp; - t = mktime (<m); + ltm = *tp; + t = mktime (<m); - /* Generate string value for T using time_t arithmetic; - this works even if sizeof (long) < sizeof (time_t). */ + /* Generate string value for T using time_t arithmetic; + this works even if sizeof (long) < sizeof (time_t). */ - bufp = buf + sizeof (buf) / sizeof (buf[0]); - negative_number = t < 0; + bufp = buf + sizeof (buf) / sizeof (buf[0]); + negative_number = t < 0; - do - { - int d = t % 10; - t /= 10; - *--bufp = (negative_number ? -d : d) + L_('0'); - } - while (t != 0); + do + { + int d = t % 10; + t /= 10; + *--bufp = (negative_number ? -d : d) + L_('0'); + } + while (t != 0); - digits = 1; - always_output_a_sign = false; - goto do_number_sign_and_padding; - } + digits = 1; + always_output_a_sign = false; + goto do_number_sign_and_padding; + } - case L_('X'): - if (modifier == L_('O')) - goto bad_format; + case L_('X'): + if (modifier == L_('O')) + goto bad_format; #ifdef _NL_CURRENT - if (! (modifier == L_('E') - && (*(subfmt = - (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(ERA_T_FMT))) - != L_('\0')))) - subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(T_FMT)); - goto subformat; + if (! (modifier == L_('E') + && (*(subfmt = + (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(ERA_T_FMT))) + != L_('\0')))) + subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME, NLW(T_FMT)); + goto subformat; #else - goto underlying_strftime; + goto underlying_strftime; #endif - case L_('T'): - subfmt = L_("%H:%M:%S"); - goto subformat; - - case L_('t'): - add1 (L_('\t')); - break; - - case L_('u'): - DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1); - - case L_('U'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7); - - case L_('V'): - case L_('g'): - case L_('G'): - if (modifier == L_('E')) - goto bad_format; - { - /* YEAR is a leap year if and only if (tp->tm_year + TM_YEAR_BASE) - is a leap year, except that YEAR and YEAR - 1 both work - correctly even when (tp->tm_year + TM_YEAR_BASE) would - overflow. */ - int year = (tp->tm_year - + (tp->tm_year < 0 - ? TM_YEAR_BASE % 400 - : TM_YEAR_BASE % 400 - 400)); - int year_adjust = 0; - int days = iso_week_days (tp->tm_yday, tp->tm_wday); - - if (days < 0) - { - /* This ISO week belongs to the previous year. */ - year_adjust = -1; - days = iso_week_days (tp->tm_yday + (365 + __isleap (year - 1)), - tp->tm_wday); - } - else - { - int d = iso_week_days (tp->tm_yday - (365 + __isleap (year)), - tp->tm_wday); - if (0 <= d) - { - /* This ISO week belongs to the next year. */ - year_adjust = 1; - days = d; - } - } - - switch (*f) - { - case L_('g'): - { - int yy = (tp->tm_year % 100 + year_adjust) % 100; - DO_NUMBER (2, (0 <= yy - ? yy - : tp->tm_year < -TM_YEAR_BASE - year_adjust - ? -yy - : yy + 100)); - } - - case L_('G'): - DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE - year_adjust, - (tp->tm_year + (unsigned int) TM_YEAR_BASE - + year_adjust)); - - default: - DO_NUMBER (2, days / 7 + 1); - } - } - - case L_('W'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER (2, (tp->tm_yday - (tp->tm_wday - 1 + 7) % 7 + 7) / 7); - - case L_('w'): - if (modifier == L_('E')) - goto bad_format; - - DO_NUMBER (1, tp->tm_wday); - - case L_('Y'): - if (modifier == 'E') - { + case L_('T'): + subfmt = L_("%H:%M:%S"); + goto subformat; + + case L_('t'): + add1 (L_('\t')); + break; + + case L_('u'): + DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1); + + case L_('U'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7); + + case L_('V'): + case L_('g'): + case L_('G'): + if (modifier == L_('E')) + goto bad_format; + { + /* YEAR is a leap year if and only if (tp->tm_year + TM_YEAR_BASE) + is a leap year, except that YEAR and YEAR - 1 both work + correctly even when (tp->tm_year + TM_YEAR_BASE) would + overflow. */ + int year = (tp->tm_year + + (tp->tm_year < 0 + ? TM_YEAR_BASE % 400 + : TM_YEAR_BASE % 400 - 400)); + int year_adjust = 0; + int days = iso_week_days (tp->tm_yday, tp->tm_wday); + + if (days < 0) + { + /* This ISO week belongs to the previous year. */ + year_adjust = -1; + days = iso_week_days (tp->tm_yday + (365 + __isleap (year - 1)), + tp->tm_wday); + } + else + { + int d = iso_week_days (tp->tm_yday - (365 + __isleap (year)), + tp->tm_wday); + if (0 <= d) + { + /* This ISO week belongs to the next year. */ + year_adjust = 1; + days = d; + } + } + + switch (*f) + { + case L_('g'): + { + int yy = (tp->tm_year % 100 + year_adjust) % 100; + DO_NUMBER (2, (0 <= yy + ? yy + : tp->tm_year < -TM_YEAR_BASE - year_adjust + ? -yy + : yy + 100)); + } + + case L_('G'): + DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE - year_adjust, + (tp->tm_year + (unsigned int) TM_YEAR_BASE + + year_adjust)); + + default: + DO_NUMBER (2, days / 7 + 1); + } + } + + case L_('W'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER (2, (tp->tm_yday - (tp->tm_wday - 1 + 7) % 7 + 7) / 7); + + case L_('w'): + if (modifier == L_('E')) + goto bad_format; + + DO_NUMBER (1, tp->tm_wday); + + case L_('Y'): + if (modifier == 'E') + { #if HAVE_STRUCT_ERA_ENTRY - struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); - if (era) - { + struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); + if (era) + { # ifdef COMPILE_WIDE - subfmt = era->era_wformat; + subfmt = era->era_wformat; # else - subfmt = era->era_format; + subfmt = era->era_format; # endif - goto subformat; - } + goto subformat; + } #else - goto underlying_strftime; + goto underlying_strftime; #endif - } - if (modifier == L_('O')) - goto bad_format; - else - DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE, - tp->tm_year + (unsigned int) TM_YEAR_BASE); - - case L_('y'): - if (modifier == L_('E')) - { + } + if (modifier == L_('O')) + goto bad_format; + else + DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE, + tp->tm_year + (unsigned int) TM_YEAR_BASE); + + case L_('y'): + if (modifier == L_('E')) + { #if HAVE_STRUCT_ERA_ENTRY - struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); - if (era) - { - int delta = tp->tm_year - era->start_date[0]; - DO_NUMBER (1, (era->offset - + delta * era->absolute_direction)); - } + struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG); + if (era) + { + int delta = tp->tm_year - era->start_date[0]; + DO_NUMBER (1, (era->offset + + delta * era->absolute_direction)); + } #else - goto underlying_strftime; + goto underlying_strftime; #endif - } - - { - int yy = tp->tm_year % 100; - if (yy < 0) - yy = tp->tm_year < - TM_YEAR_BASE ? -yy : yy + 100; - DO_NUMBER (2, yy); - } - - case L_('Z'): - if (change_case) - { - to_uppcase = false; - to_lowcase = true; - } + } + + { + int yy = tp->tm_year % 100; + if (yy < 0) + yy = tp->tm_year < - TM_YEAR_BASE ? -yy : yy + 100; + DO_NUMBER (2, yy); + } + + case L_('Z'): + if (change_case) + { + to_uppcase = false; + to_lowcase = true; + } #if HAVE_TZNAME - /* The tzset() call might have changed the value. */ - if (!(zone && *zone) && tp->tm_isdst >= 0) - zone = tzname[tp->tm_isdst != 0]; + /* The tzset() call might have changed the value. */ + if (!(zone && *zone) && tp->tm_isdst >= 0) + zone = tzname[tp->tm_isdst != 0]; #endif - if (! zone) - zone = ""; + if (! zone) + zone = ""; #ifdef COMPILE_WIDE - { - /* The zone string is always given in multibyte form. We have - to transform it first. */ - wchar_t *wczone; - size_t len; - widen (zone, wczone, len); - cpy (len, wczone); - } + { + /* The zone string is always given in multibyte form. We have + to transform it first. */ + wchar_t *wczone; + size_t len; + widen (zone, wczone, len); + cpy (len, wczone); + } #else - cpy (strlen (zone), zone); + cpy (strlen (zone), zone); #endif - break; - - case L_(':'): - /* :, ::, and ::: are valid only just before 'z'. - :::: etc. are rejected later. */ - for (colons = 1; f[colons] == L_(':'); colons++) - continue; - if (f[colons] != L_('z')) - goto bad_format; - f += colons; - goto do_z_conversion; - - case L_('z'): - colons = 0; - - do_z_conversion: - if (tp->tm_isdst < 0) - break; - - { - int diff; - int hour_diff; - int min_diff; - int sec_diff; + break; + + case L_(':'): + /* :, ::, and ::: are valid only just before 'z'. + :::: etc. are rejected later. */ + for (colons = 1; f[colons] == L_(':'); colons++) + continue; + if (f[colons] != L_('z')) + goto bad_format; + f += colons; + goto do_z_conversion; + + case L_('z'): + colons = 0; + + do_z_conversion: + if (tp->tm_isdst < 0) + break; + + { + int diff; + int hour_diff; + int min_diff; + int sec_diff; #if HAVE_TM_GMTOFF - diff = tp->tm_gmtoff; + diff = tp->tm_gmtoff; #else - if (ut) - diff = 0; - else - { - struct tm gtm; - struct tm ltm; - time_t lt; - - ltm = *tp; - lt = mktime (<m); - - if (lt == (time_t) -1) - { - /* mktime returns -1 for errors, but -1 is also a - valid time_t value. Check whether an error really - occurred. */ - struct tm tm; - - if (! __localtime_r (<, &tm) - || ((ltm.tm_sec ^ tm.tm_sec) - | (ltm.tm_min ^ tm.tm_min) - | (ltm.tm_hour ^ tm.tm_hour) - | (ltm.tm_mday ^ tm.tm_mday) - | (ltm.tm_mon ^ tm.tm_mon) - | (ltm.tm_year ^ tm.tm_year))) - break; - } - - if (! __gmtime_r (<, >m)) - break; - - diff = tm_diff (<m, >m); - } + if (ut) + diff = 0; + else + { + struct tm gtm; + struct tm ltm; + time_t lt; + + ltm = *tp; + lt = mktime (<m); + + if (lt == (time_t) -1) + { + /* mktime returns -1 for errors, but -1 is also a + valid time_t value. Check whether an error really + occurred. */ + struct tm tm; + + if (! __localtime_r (<, &tm) + || ((ltm.tm_sec ^ tm.tm_sec) + | (ltm.tm_min ^ tm.tm_min) + | (ltm.tm_hour ^ tm.tm_hour) + | (ltm.tm_mday ^ tm.tm_mday) + | (ltm.tm_mon ^ tm.tm_mon) + | (ltm.tm_year ^ tm.tm_year))) + break; + } + + if (! __gmtime_r (<, >m)) + break; + + diff = tm_diff (<m, >m); + } #endif - hour_diff = diff / 60 / 60; - min_diff = diff / 60 % 60; - sec_diff = diff % 60; - - switch (colons) - { - case 0: /* +hhmm */ - DO_TZ_OFFSET (5, diff < 0, 0, hour_diff * 100 + min_diff); - - case 1: tz_hh_mm: /* +hh:mm */ - DO_TZ_OFFSET (6, diff < 0, 04, hour_diff * 100 + min_diff); - - case 2: tz_hh_mm_ss: /* +hh:mm:ss */ - DO_TZ_OFFSET (9, diff < 0, 024, - hour_diff * 10000 + min_diff * 100 + sec_diff); - - case 3: /* +hh if possible, else +hh:mm, else +hh:mm:ss */ - if (sec_diff != 0) - goto tz_hh_mm_ss; - if (min_diff != 0) - goto tz_hh_mm; - DO_TZ_OFFSET (3, diff < 0, 0, hour_diff); - - default: - goto bad_format; - } - } - - case L_('\0'): /* GNU extension: % at end of format. */ - --f; - /* Fall through. */ - default: - /* Unknown format; output the format, including the '%', - since this is most likely the right thing to do if a - multibyte string has been misparsed. */ - bad_format: - { - int flen; - for (flen = 1; f[1 - flen] != L_('%'); flen++) - continue; - cpy (flen, &f[1 - flen]); - } - break; - } + hour_diff = diff / 60 / 60; + min_diff = diff / 60 % 60; + sec_diff = diff % 60; + + switch (colons) + { + case 0: /* +hhmm */ + DO_TZ_OFFSET (5, diff < 0, 0, hour_diff * 100 + min_diff); + + case 1: tz_hh_mm: /* +hh:mm */ + DO_TZ_OFFSET (6, diff < 0, 04, hour_diff * 100 + min_diff); + + case 2: tz_hh_mm_ss: /* +hh:mm:ss */ + DO_TZ_OFFSET (9, diff < 0, 024, + hour_diff * 10000 + min_diff * 100 + sec_diff); + + case 3: /* +hh if possible, else +hh:mm, else +hh:mm:ss */ + if (sec_diff != 0) + goto tz_hh_mm_ss; + if (min_diff != 0) + goto tz_hh_mm; + DO_TZ_OFFSET (3, diff < 0, 0, hour_diff); + + default: + goto bad_format; + } + } + + case L_('\0'): /* GNU extension: % at end of format. */ + --f; + /* Fall through. */ + default: + /* Unknown format; output the format, including the '%', + since this is most likely the right thing to do if a + multibyte string has been misparsed. */ + bad_format: + { + int flen; + for (flen = 1; f[1 - flen] != L_('%'); flen++) + continue; + cpy (flen, &f[1 - flen]); + } + break; + } } #if ! FPRINTFTIME @@ -1442,11 +1442,11 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s, written, use NULL for S and (size_t) -1 for MAXSIZE. */ size_t my_strftime (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) - const CHAR_T *format, - const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO) + const CHAR_T *format, + const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO) { return strftime_case_ (false, s, STRFTIME_ARG (maxsize) - format, tp extra_args LOCALE_ARG); + format, tp extra_args LOCALE_ARG); } #if defined _LIBC && ! FPRINTFTIME @@ -1459,7 +1459,7 @@ libc_hidden_def (my_strftime) strftime function plus the ut argument, but without the ns argument. */ size_t emacs_strftimeu (char *s, size_t maxsize, const char *format, - const struct tm *tp, int ut) + const struct tm *tp, int ut) { return my_strftime (s, maxsize, format, tp, ut, 0); } diff --git a/lib/strftime.h b/lib/strftime.h index 1937d40cd..1cc9258d2 100644 --- a/lib/strftime.h +++ b/lib/strftime.h @@ -27,7 +27,7 @@ extern "C" { use UTC instead. Use __NS as the number of nanoseconds in the %N directive. */ size_t nstrftime (char *, size_t, char const *, struct tm const *, - int __utc, int __ns); + int __utc, int __ns); #ifdef __cplusplus } diff --git a/lib/striconv.c b/lib/striconv.c index ea4fa2979..9b1c7f44d 100644 --- a/lib/striconv.c +++ b/lib/striconv.c @@ -42,7 +42,7 @@ int mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, - char **resultp, size_t *lengthp) + char **resultp, size_t *lengthp) { # define tmpbufsize 4096 size_t length; @@ -67,33 +67,33 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, while (insize > 0) { - char *outptr = tmpbuf; - size_t outsize = tmpbufsize; - size_t res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - - if (res == (size_t)(-1)) - { - if (errno == E2BIG) - ; - else if (errno == EINVAL) - break; - else - return -1; - } + char *outptr = tmpbuf; + size_t outsize = tmpbufsize; + size_t res = iconv (cd, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + + if (res == (size_t)(-1)) + { + if (errno == E2BIG) + ; + else if (errno == EINVAL) + break; + else + return -1; + } # if !defined _LIBICONV_VERSION && !defined __GLIBC__ - /* Irix iconv() inserts a NUL byte if it cannot convert. - NetBSD iconv() inserts a question mark if it cannot convert. - Only GNU libiconv and GNU libc are known to prefer to fail rather - than doing a lossy conversion. */ - else if (res > 0) - { - errno = EILSEQ; - return -1; - } + /* Irix iconv() inserts a NUL byte if it cannot convert. + NetBSD iconv() inserts a question mark if it cannot convert. + Only GNU libiconv and GNU libc are known to prefer to fail rather + than doing a lossy conversion. */ + else if (res > 0) + { + errno = EILSEQ; + return -1; + } # endif - count += outptr - tmpbuf; + count += outptr - tmpbuf; } /* Avoid glibc-2.1 bug and Solaris 2.7 bug. */ # if defined _LIBICONV_VERSION \ @@ -104,7 +104,7 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, size_t res = iconv (cd, NULL, NULL, &outptr, &outsize); if (res == (size_t)(-1)) - return -1; + return -1; count += outptr - tmpbuf; } # endif @@ -123,10 +123,10 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, { result = (char *) malloc (length); if (result == NULL) - { - errno = ENOMEM; - return -1; - } + { + errno = ENOMEM; + return -1; + } } /* Avoid glibc-2.1 bug and Solaris 2.7-2.9 bug. */ @@ -145,27 +145,27 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, while (insize > 0) { - size_t res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - - if (res == (size_t)(-1)) - { - if (errno == EINVAL) - break; - else - goto fail; - } + size_t res = iconv (cd, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + + if (res == (size_t)(-1)) + { + if (errno == EINVAL) + break; + else + goto fail; + } # if !defined _LIBICONV_VERSION && !defined __GLIBC__ - /* Irix iconv() inserts a NUL byte if it cannot convert. - NetBSD iconv() inserts a question mark if it cannot convert. - Only GNU libiconv and GNU libc are known to prefer to fail rather - than doing a lossy conversion. */ - else if (res > 0) - { - errno = EILSEQ; - goto fail; - } + /* Irix iconv() inserts a NUL byte if it cannot convert. + NetBSD iconv() inserts a question mark if it cannot convert. + Only GNU libiconv and GNU libc are known to prefer to fail rather + than doing a lossy conversion. */ + else if (res > 0) + { + errno = EILSEQ; + goto fail; + } # endif } /* Avoid glibc-2.1 bug and Solaris 2.7 bug. */ @@ -175,7 +175,7 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, size_t res = iconv (cd, NULL, NULL, &outptr, &outsize); if (res == (size_t)(-1)) - goto fail; + goto fail; } # endif if (outsize != 0) @@ -191,9 +191,9 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, { if (result != *resultp) { - int saved_errno = errno; - free (result); - errno = saved_errno; + int saved_errno = errno; + free (result); + errno = saved_errno; } return -1; } @@ -224,7 +224,7 @@ str_cd_iconv (const char *src, iconv_t cd) if (retval < 0) { if (result != NULL) - abort (); + abort (); return NULL; } @@ -234,7 +234,7 @@ str_cd_iconv (const char *src, iconv_t cd) if (final_result == NULL) { if (result != NULL) - free (result); + free (result); errno = ENOMEM; return NULL; } @@ -285,81 +285,81 @@ str_cd_iconv (const char *src, iconv_t cd) for (;;) { - /* Here inptr + inbytes_remaining = src + strlen (src), - outptr + outbytes_remaining = result + result_size - 1. */ - size_t res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytes_remaining, - &outptr, &outbytes_remaining); - - if (res == (size_t)(-1)) - { - if (errno == EINVAL) - break; - else if (errno == E2BIG) - { - size_t used = outptr - result; - size_t newsize = result_size * 2; - char *newresult; - - if (!(newsize > result_size)) - { - errno = ENOMEM; - goto failed; - } - newresult = (char *) realloc (result, newsize); - if (newresult == NULL) - { - errno = ENOMEM; - goto failed; - } - result = newresult; - result_size = newsize; - outptr = result + used; - outbytes_remaining = result_size - 1 - used; - } - else - goto failed; - } - else - break; + /* Here inptr + inbytes_remaining = src + strlen (src), + outptr + outbytes_remaining = result + result_size - 1. */ + size_t res = iconv (cd, + (ICONV_CONST char **) &inptr, &inbytes_remaining, + &outptr, &outbytes_remaining); + + if (res == (size_t)(-1)) + { + if (errno == EINVAL) + break; + else if (errno == E2BIG) + { + size_t used = outptr - result; + size_t newsize = result_size * 2; + char *newresult; + + if (!(newsize > result_size)) + { + errno = ENOMEM; + goto failed; + } + newresult = (char *) realloc (result, newsize); + if (newresult == NULL) + { + errno = ENOMEM; + goto failed; + } + result = newresult; + result_size = newsize; + outptr = result + used; + outbytes_remaining = result_size - 1 - used; + } + else + goto failed; + } + else + break; } /* Avoid glibc-2.1 bug and Solaris 2.7 bug. */ # if defined _LIBICONV_VERSION \ || !((__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) || defined __sun) for (;;) { - /* Here outptr + outbytes_remaining = result + result_size - 1. */ - size_t res = iconv (cd, NULL, NULL, &outptr, &outbytes_remaining); - - if (res == (size_t)(-1)) - { - if (errno == E2BIG) - { - size_t used = outptr - result; - size_t newsize = result_size * 2; - char *newresult; - - if (!(newsize > result_size)) - { - errno = ENOMEM; - goto failed; - } - newresult = (char *) realloc (result, newsize); - if (newresult == NULL) - { - errno = ENOMEM; - goto failed; - } - result = newresult; - result_size = newsize; - outptr = result + used; - outbytes_remaining = result_size - 1 - used; - } - else - goto failed; - } - else - break; + /* Here outptr + outbytes_remaining = result + result_size - 1. */ + size_t res = iconv (cd, NULL, NULL, &outptr, &outbytes_remaining); + + if (res == (size_t)(-1)) + { + if (errno == E2BIG) + { + size_t used = outptr - result; + size_t newsize = result_size * 2; + char *newresult; + + if (!(newsize > result_size)) + { + errno = ENOMEM; + goto failed; + } + newresult = (char *) realloc (result, newsize); + if (newresult == NULL) + { + errno = ENOMEM; + goto failed; + } + result = newresult; + result_size = newsize; + outptr = result + used; + outbytes_remaining = result_size - 1 - used; + } + else + goto failed; + } + else + break; } # endif @@ -375,7 +375,7 @@ str_cd_iconv (const char *src, iconv_t cd) char *smaller_result = (char *) realloc (result, length); if (smaller_result != NULL) - result = smaller_result; + result = smaller_result; } return result; @@ -401,7 +401,7 @@ str_iconv (const char *src, const char *from_codeset, const char *to_codeset) char *result = strdup (src); if (result == NULL) - errno = ENOMEM; + errno = ENOMEM; return result; } else @@ -413,44 +413,44 @@ str_iconv (const char *src, const char *from_codeset, const char *to_codeset) /* Avoid glibc-2.1 bug with EUC-KR. */ # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION if (c_strcasecmp (from_codeset, "EUC-KR") == 0 - || c_strcasecmp (to_codeset, "EUC-KR") == 0) - { - errno = EINVAL; - return NULL; - } + || c_strcasecmp (to_codeset, "EUC-KR") == 0) + { + errno = EINVAL; + return NULL; + } # endif cd = iconv_open (to_codeset, from_codeset); if (cd == (iconv_t) -1) - return NULL; + return NULL; result = str_cd_iconv (src, cd); if (result == NULL) - { - /* Close cd, but preserve the errno from str_cd_iconv. */ - int saved_errno = errno; - iconv_close (cd); - errno = saved_errno; - } + { + /* Close cd, but preserve the errno from str_cd_iconv. */ + int saved_errno = errno; + iconv_close (cd); + errno = saved_errno; + } else - { - if (iconv_close (cd) < 0) - { - /* Return NULL, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; - free (result); - errno = saved_errno; - return NULL; - } - } + { + if (iconv_close (cd) < 0) + { + /* Return NULL, but free the allocated memory, and while doing + that, preserve the errno from iconv_close. */ + int saved_errno = errno; + free (result); + errno = saved_errno; + return NULL; + } + } return result; #else /* This is a different error code than if iconv_open existed but didn't - support from_codeset and to_codeset, so that the caller can emit - an error message such as - "iconv() is not supported. Installing GNU libiconv and - then reinstalling this package would fix this." */ + support from_codeset and to_codeset, so that the caller can emit + an error message such as + "iconv() is not supported. Installing GNU libiconv and + then reinstalling this package would fix this." */ errno = ENOSYS; return NULL; #endif diff --git a/lib/striconv.h b/lib/striconv.h index 00f2cca53..eb7fa4a5d 100644 --- a/lib/striconv.h +++ b/lib/striconv.h @@ -43,7 +43,7 @@ extern "C" { in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is unchanged if no dynamic memory allocation was necessary. */ extern int mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, - char **resultp, size_t *lengthp); + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -65,7 +65,7 @@ extern char * str_cd_iconv (const char *src, iconv_t cd); Return value: the freshly allocated resulting NUL-terminated string if successful, otherwise NULL and errno set. */ extern char * str_iconv (const char *src, - const char *from_codeset, const char *to_codeset); + const char *from_codeset, const char *to_codeset); #ifdef __cplusplus diff --git a/lib/striconveh.c b/lib/striconveh.c index 05dbb73fb..b53169d99 100644 --- a/lib/striconveh.c +++ b/lib/striconveh.c @@ -69,13 +69,13 @@ iconveh_open (const char *to_codeset, const char *from_codeset, iconveh_t *cdp) { cd1 = iconv_open ("UTF-8", from_codeset); if (cd1 == (iconv_t)(-1)) - { - int saved_errno = errno; - if (cd != (iconv_t)(-1)) - iconv_close (cdp->cd); - errno = saved_errno; - return -1; - } + { + int saved_errno = errno; + if (cd != (iconv_t)(-1)) + iconv_close (cdp->cd); + errno = saved_errno; + return -1; + } } if (STRCASEEQ (to_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0) @@ -88,15 +88,15 @@ iconveh_open (const char *to_codeset, const char *from_codeset, iconveh_t *cdp) { cd2 = iconv_open (to_codeset, "UTF-8"); if (cd2 == (iconv_t)(-1)) - { - int saved_errno = errno; - if (cd1 != (iconv_t)(-1)) - iconv_close (cd1); - if (cd != (iconv_t)(-1)) - iconv_close (cd); - errno = saved_errno; - return -1; - } + { + int saved_errno = errno; + if (cd1 != (iconv_t)(-1)) + iconv_close (cd1); + if (cd != (iconv_t)(-1)) + iconv_close (cd); + errno = saved_errno; + return -1; + } } cdp->cd = cd; @@ -113,9 +113,9 @@ iconveh_close (const iconveh_t *cd) /* Return -1, but preserve the errno from iconv_close. */ int saved_errno = errno; if (cd->cd1 != (iconv_t)(-1)) - iconv_close (cd->cd1); + iconv_close (cd->cd1); if (cd->cd != (iconv_t)(-1)) - iconv_close (cd->cd); + iconv_close (cd->cd); errno = saved_errno; return -1; } @@ -124,7 +124,7 @@ iconveh_close (const iconveh_t *cd) /* Return -1, but preserve the errno from iconv_close. */ int saved_errno = errno; if (cd->cd != (iconv_t)(-1)) - iconv_close (cd->cd); + iconv_close (cd->cd); errno = saved_errno; return -1; } @@ -143,9 +143,9 @@ iconveh_close (const iconveh_t *cd) than doing a lossy conversion. */ static size_t iconv_carefully (iconv_t cd, - const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - bool *incremented) + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, + bool *incremented) { const char *inptr = *inbuf; const char *inptr_end = inptr + *inbytesleft; @@ -162,26 +162,26 @@ iconv_carefully (iconv_t cd, res = (size_t)(-1); for (insize = 1; inptr + insize <= inptr_end; insize++) - { - res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - if (!(res == (size_t)(-1) && errno == EINVAL)) - break; - /* iconv can eat up a shift sequence but give EINVAL while attempting - to convert the first character. E.g. libiconv does this. */ - if (inptr > inptr_before) - { - res = 0; - break; - } - } + { + res = iconv (cd, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + if (!(res == (size_t)(-1) && errno == EINVAL)) + break; + /* iconv can eat up a shift sequence but give EINVAL while attempting + to convert the first character. E.g. libiconv does this. */ + if (inptr > inptr_before) + { + res = 0; + break; + } + } if (res == 0) - { - *outbuf = outptr; - *outbytesleft = outsize; - } + { + *outbuf = outptr; + *outbytesleft = outsize; + } } while (res == 0 && inptr < inptr_end); @@ -190,9 +190,9 @@ iconv_carefully (iconv_t cd, if (res != (size_t)(-1) && res > 0) { /* iconv() has already incremented INPTR. We cannot go back to a - previous INPTR, otherwise the state inside CD would become invalid, - if FROM_CODESET is a stateful encoding. So, tell the caller that - *INBUF has already been incremented. */ + previous INPTR, otherwise the state inside CD would become invalid, + if FROM_CODESET is a stateful encoding. So, tell the caller that + *INBUF has already been incremented. */ *incremented = (inptr > inptr_before); errno = EILSEQ; return (size_t)(-1); @@ -213,9 +213,9 @@ iconv_carefully (iconv_t cd, converting one character or one shift sequence. */ static size_t iconv_carefully_1 (iconv_t cd, - const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - bool *incremented) + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, + bool *incremented) { const char *inptr_before = *inbuf; const char *inptr = inptr_before; @@ -229,17 +229,17 @@ iconv_carefully_1 (iconv_t cd, { inptr = inptr_before; res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); if (!(res == (size_t)(-1) && errno == EINVAL)) - break; + break; /* iconv can eat up a shift sequence but give EINVAL while attempting - to convert the first character. E.g. libiconv does this. */ + to convert the first character. E.g. libiconv does this. */ if (inptr > inptr_before) - { - res = 0; - break; - } + { + res = 0; + break; + } } *inbuf = inptr; @@ -252,9 +252,9 @@ iconv_carefully_1 (iconv_t cd, if (res != (size_t)(-1) && res > 0) { /* iconv() has already incremented INPTR. We cannot go back to a - previous INPTR, otherwise the state inside CD would become invalid, - if FROM_CODESET is a stateful encoding. So, tell the caller that - *INBUF has already been incremented. */ + previous INPTR, otherwise the state inside CD would become invalid, + if FROM_CODESET is a stateful encoding. So, tell the caller that + *INBUF has already been incremented. */ *incremented = (inptr > inptr_before); errno = EILSEQ; return (size_t)(-1); @@ -279,9 +279,9 @@ iconv_carefully_1 (iconv_t cd, character. */ static size_t utf8conv_carefully (bool one_character_only, - const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - bool *incremented) + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, + bool *incremented) { const char *inptr = *inbuf; size_t insize = *inbytesleft; @@ -298,39 +298,39 @@ utf8conv_carefully (bool one_character_only, n = u8_mbtoucr (&uc, (const uint8_t *) inptr, insize); if (n < 0) - { - errno = (n == -2 ? EINVAL : EILSEQ); - n = u8_mbtouc (&uc, (const uint8_t *) inptr, insize); - inptr += n; - insize -= n; - res = (size_t)(-1); - *incremented = true; - break; - } + { + errno = (n == -2 ? EINVAL : EILSEQ); + n = u8_mbtouc (&uc, (const uint8_t *) inptr, insize); + inptr += n; + insize -= n; + res = (size_t)(-1); + *incremented = true; + break; + } if (outsize == 0) - { - errno = E2BIG; - res = (size_t)(-1); - *incremented = false; - break; - } + { + errno = E2BIG; + res = (size_t)(-1); + *incremented = false; + break; + } m = u8_uctomb ((uint8_t *) outptr, uc, outsize); if (m == -2) - { - errno = E2BIG; - res = (size_t)(-1); - *incremented = false; - break; - } + { + errno = E2BIG; + res = (size_t)(-1); + *incremented = false; + break; + } inptr += n; insize -= n; if (m == -1) - { - errno = EILSEQ; - res = (size_t)(-1); - *incremented = true; - break; - } + { + errno = EILSEQ; + res = (size_t)(-1); + *incremented = true; + break; + } outptr += m; outsize -= m; } @@ -345,11 +345,11 @@ utf8conv_carefully (bool one_character_only, static int mem_cd_iconveh_internal (const char *src, size_t srclen, - iconv_t cd, iconv_t cd1, iconv_t cd2, - enum iconv_ilseq_handler handler, - size_t extra_alloc, - size_t *offsets, - char **resultp, size_t *lengthp) + iconv_t cd, iconv_t cd1, iconv_t cd2, + enum iconv_ilseq_handler handler, + size_t extra_alloc, + size_t *offsets, + char **resultp, size_t *lengthp) { /* When a conversion error occurs, we cannot start using CD1 and CD2 at this point: FROM_CODESET may be a stateful encoding like ISO-2022-KR. @@ -389,7 +389,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, size_t i; for (i = 0; i < srclen; i++) - offsets[i] = (size_t)(-1); + offsets[i] = (size_t)(-1); last_length = (size_t)(-1); } @@ -410,121 +410,121 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, while (insize > 0) { - char *outptr = result + length; - size_t outsize = allocated - extra_alloc - length; - bool incremented; - size_t res; - bool grow; - - if (offsets != NULL) - { - if (length != last_length) /* ensure that offset[] be increasing */ - { - offsets[inptr - src] = length; - last_length = length; - } - res = iconv_carefully_1 (cd, - &inptr, &insize, - &outptr, &outsize, - &incremented); - } - else - /* Use iconv_carefully instead of iconv here, because: - - If TO_CODESET is UTF-8, we can do the error handling in this - loop, no need for a second loop, - - With iconv() implementations other than GNU libiconv and GNU - libc, if we use iconv() in a big swoop, checking for an E2BIG - return, we lose the number of irreversible conversions. */ - res = iconv_carefully (cd, - &inptr, &insize, - &outptr, &outsize, - &incremented); - - length = outptr - result; - grow = (length + extra_alloc > allocated / 2); - if (res == (size_t)(-1)) - { - if (errno == E2BIG) - grow = true; - else if (errno == EINVAL) - break; - else if (errno == EILSEQ && handler != iconveh_error) - { - if (cd2 == (iconv_t)(-1)) - { - /* TO_CODESET is UTF-8. */ - /* Error handling can produce up to 1 byte of output. */ - if (length + 1 + extra_alloc > allocated) - { - char *memory; - - allocated = 2 * allocated; - if (length + 1 + extra_alloc > allocated) - abort (); - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - grow = false; - } - /* The input is invalid in FROM_CODESET. Eat up one byte - and emit a question mark. */ - if (!incremented) - { - if (insize == 0) - abort (); - inptr++; - insize--; - } - result[length] = '?'; - length++; - } - else - goto indirectly; - } - else - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } - if (insize == 0) - break; - if (grow) - { - char *memory; - - allocated = 2 * allocated; - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - } + char *outptr = result + length; + size_t outsize = allocated - extra_alloc - length; + bool incremented; + size_t res; + bool grow; + + if (offsets != NULL) + { + if (length != last_length) /* ensure that offset[] be increasing */ + { + offsets[inptr - src] = length; + last_length = length; + } + res = iconv_carefully_1 (cd, + &inptr, &insize, + &outptr, &outsize, + &incremented); + } + else + /* Use iconv_carefully instead of iconv here, because: + - If TO_CODESET is UTF-8, we can do the error handling in this + loop, no need for a second loop, + - With iconv() implementations other than GNU libiconv and GNU + libc, if we use iconv() in a big swoop, checking for an E2BIG + return, we lose the number of irreversible conversions. */ + res = iconv_carefully (cd, + &inptr, &insize, + &outptr, &outsize, + &incremented); + + length = outptr - result; + grow = (length + extra_alloc > allocated / 2); + if (res == (size_t)(-1)) + { + if (errno == E2BIG) + grow = true; + else if (errno == EINVAL) + break; + else if (errno == EILSEQ && handler != iconveh_error) + { + if (cd2 == (iconv_t)(-1)) + { + /* TO_CODESET is UTF-8. */ + /* Error handling can produce up to 1 byte of output. */ + if (length + 1 + extra_alloc > allocated) + { + char *memory; + + allocated = 2 * allocated; + if (length + 1 + extra_alloc > allocated) + abort (); + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + grow = false; + } + /* The input is invalid in FROM_CODESET. Eat up one byte + and emit a question mark. */ + if (!incremented) + { + if (insize == 0) + abort (); + inptr++; + insize--; + } + result[length] = '?'; + length++; + } + else + goto indirectly; + } + else + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } + if (insize == 0) + break; + if (grow) + { + char *memory; + + allocated = 2 * allocated; + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + } } } @@ -541,40 +541,40 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, res = iconv (cd, NULL, NULL, &outptr, &outsize); length = outptr - result; if (res == (size_t)(-1)) - { - if (errno == E2BIG) - { - char *memory; - - allocated = 2 * allocated; - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - } - else - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } + { + if (errno == E2BIG) + { + char *memory; + + allocated = 2 * allocated; + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + } + else + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } else - break; + break; } #endif @@ -589,7 +589,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, size_t i; for (i = 0; i < srclen; i++) - offsets[i] = (size_t)(-1); + offsets[i] = (size_t)(-1); last_length = (size_t)(-1); } @@ -616,351 +616,351 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, while (in1size > 0 || do_final_flush1 || utf8len > 0 || do_final_flush2) { - char *out1ptr = utf8buf + utf8len; - size_t out1size = utf8bufsize - utf8len; - bool incremented1; - size_t res1; - int errno1; - - /* Conversion step 1: from FROM_CODESET to UTF-8. */ - if (in1size > 0) - { - if (offsets != NULL - && length != last_length) /* ensure that offset[] be increasing */ - { - offsets[in1ptr - src] = length; - last_length = length; - } - if (cd1 != (iconv_t)(-1)) - { - if (slowly) - res1 = iconv_carefully_1 (cd1, - &in1ptr, &in1size, - &out1ptr, &out1size, - &incremented1); - else - res1 = iconv_carefully (cd1, - &in1ptr, &in1size, - &out1ptr, &out1size, - &incremented1); - } - else - { - /* FROM_CODESET is UTF-8. */ - res1 = utf8conv_carefully (slowly, - &in1ptr, &in1size, - &out1ptr, &out1size, - &incremented1); - } - } - else if (do_final_flush1) - { - /* Now get the conversion state of CD1 back to the initial state. - But avoid glibc-2.1 bug and Solaris 2.7 bug. */ + char *out1ptr = utf8buf + utf8len; + size_t out1size = utf8bufsize - utf8len; + bool incremented1; + size_t res1; + int errno1; + + /* Conversion step 1: from FROM_CODESET to UTF-8. */ + if (in1size > 0) + { + if (offsets != NULL + && length != last_length) /* ensure that offset[] be increasing */ + { + offsets[in1ptr - src] = length; + last_length = length; + } + if (cd1 != (iconv_t)(-1)) + { + if (slowly) + res1 = iconv_carefully_1 (cd1, + &in1ptr, &in1size, + &out1ptr, &out1size, + &incremented1); + else + res1 = iconv_carefully (cd1, + &in1ptr, &in1size, + &out1ptr, &out1size, + &incremented1); + } + else + { + /* FROM_CODESET is UTF-8. */ + res1 = utf8conv_carefully (slowly, + &in1ptr, &in1size, + &out1ptr, &out1size, + &incremented1); + } + } + else if (do_final_flush1) + { + /* Now get the conversion state of CD1 back to the initial state. + But avoid glibc-2.1 bug and Solaris 2.7 bug. */ # if defined _LIBICONV_VERSION \ || !((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) || defined __sun) - if (cd1 != (iconv_t)(-1)) - res1 = iconv (cd1, NULL, NULL, &out1ptr, &out1size); - else + if (cd1 != (iconv_t)(-1)) + res1 = iconv (cd1, NULL, NULL, &out1ptr, &out1size); + else # endif - res1 = 0; - do_final_flush1 = false; - incremented1 = true; - } - else - { - res1 = 0; - incremented1 = true; - } - if (res1 == (size_t)(-1) - && !(errno == E2BIG || errno == EINVAL || errno == EILSEQ)) - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - if (res1 == (size_t)(-1) - && errno == EILSEQ && handler != iconveh_error) - { - /* The input is invalid in FROM_CODESET. Eat up one byte and - emit a question mark. Room for the question mark was allocated - at the end of utf8buf. */ - if (!incremented1) - { - if (in1size == 0) - abort (); - in1ptr++; - in1size--; - } - *out1ptr++ = '?'; - res1 = 0; - } - errno1 = errno; - utf8len = out1ptr - utf8buf; - - if (offsets != NULL - || in1size == 0 - || utf8len > utf8bufsize / 2 - || (res1 == (size_t)(-1) && errno1 == E2BIG)) - { - /* Conversion step 2: from UTF-8 to TO_CODESET. */ - const char *in2ptr = utf8buf; - size_t in2size = utf8len; - - while (in2size > 0 - || (in1size == 0 && !do_final_flush1 && do_final_flush2)) - { - char *out2ptr = result + length; - size_t out2size = allocated - extra_alloc - length; - bool incremented2; - size_t res2; - bool grow; - - if (in2size > 0) - { - if (cd2 != (iconv_t)(-1)) - res2 = iconv_carefully (cd2, - &in2ptr, &in2size, - &out2ptr, &out2size, - &incremented2); - else - /* TO_CODESET is UTF-8. */ - res2 = utf8conv_carefully (false, - &in2ptr, &in2size, - &out2ptr, &out2size, - &incremented2); - } - else /* in1size == 0 && !do_final_flush1 - && in2size == 0 && do_final_flush2 */ - { - /* Now get the conversion state of CD1 back to the initial - state. But avoid glibc-2.1 bug and Solaris 2.7 bug. */ + res1 = 0; + do_final_flush1 = false; + incremented1 = true; + } + else + { + res1 = 0; + incremented1 = true; + } + if (res1 == (size_t)(-1) + && !(errno == E2BIG || errno == EINVAL || errno == EILSEQ)) + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + if (res1 == (size_t)(-1) + && errno == EILSEQ && handler != iconveh_error) + { + /* The input is invalid in FROM_CODESET. Eat up one byte and + emit a question mark. Room for the question mark was allocated + at the end of utf8buf. */ + if (!incremented1) + { + if (in1size == 0) + abort (); + in1ptr++; + in1size--; + } + *out1ptr++ = '?'; + res1 = 0; + } + errno1 = errno; + utf8len = out1ptr - utf8buf; + + if (offsets != NULL + || in1size == 0 + || utf8len > utf8bufsize / 2 + || (res1 == (size_t)(-1) && errno1 == E2BIG)) + { + /* Conversion step 2: from UTF-8 to TO_CODESET. */ + const char *in2ptr = utf8buf; + size_t in2size = utf8len; + + while (in2size > 0 + || (in1size == 0 && !do_final_flush1 && do_final_flush2)) + { + char *out2ptr = result + length; + size_t out2size = allocated - extra_alloc - length; + bool incremented2; + size_t res2; + bool grow; + + if (in2size > 0) + { + if (cd2 != (iconv_t)(-1)) + res2 = iconv_carefully (cd2, + &in2ptr, &in2size, + &out2ptr, &out2size, + &incremented2); + else + /* TO_CODESET is UTF-8. */ + res2 = utf8conv_carefully (false, + &in2ptr, &in2size, + &out2ptr, &out2size, + &incremented2); + } + else /* in1size == 0 && !do_final_flush1 + && in2size == 0 && do_final_flush2 */ + { + /* Now get the conversion state of CD1 back to the initial + state. But avoid glibc-2.1 bug and Solaris 2.7 bug. */ # if defined _LIBICONV_VERSION \ || !((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) || defined __sun) - if (cd2 != (iconv_t)(-1)) - res2 = iconv (cd2, NULL, NULL, &out2ptr, &out2size); - else + if (cd2 != (iconv_t)(-1)) + res2 = iconv (cd2, NULL, NULL, &out2ptr, &out2size); + else # endif - res2 = 0; - do_final_flush2 = false; - incremented2 = true; - } - - length = out2ptr - result; - grow = (length + extra_alloc > allocated / 2); - if (res2 == (size_t)(-1)) - { - if (errno == E2BIG) - grow = true; - else if (errno == EINVAL) - break; - else if (errno == EILSEQ && handler != iconveh_error) - { - /* Error handling can produce up to 10 bytes of ASCII - output. But TO_CODESET may be UCS-2, UTF-16 or - UCS-4, so use CD2 here as well. */ - char scratchbuf[10]; - size_t scratchlen; - ucs4_t uc; - const char *inptr; - size_t insize; - size_t res; - - if (incremented2) - { - if (u8_prev (&uc, (const uint8_t *) in2ptr, - (const uint8_t *) utf8buf) - == NULL) - abort (); - } - else - { - int n; - if (in2size == 0) - abort (); - n = u8_mbtouc_unsafe (&uc, (const uint8_t *) in2ptr, - in2size); - in2ptr += n; - in2size -= n; - } - - if (handler == iconveh_escape_sequence) - { - static char hex[16] = "0123456789ABCDEF"; - scratchlen = 0; - scratchbuf[scratchlen++] = '\\'; - if (uc < 0x10000) - scratchbuf[scratchlen++] = 'u'; - else - { - scratchbuf[scratchlen++] = 'U'; - scratchbuf[scratchlen++] = hex[(uc>>28) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>24) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>20) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>16) & 15]; - } - scratchbuf[scratchlen++] = hex[(uc>>12) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>8) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>4) & 15]; - scratchbuf[scratchlen++] = hex[uc & 15]; - } - else - { - scratchbuf[0] = '?'; - scratchlen = 1; - } - - inptr = scratchbuf; - insize = scratchlen; - if (cd2 != (iconv_t)(-1)) - res = iconv (cd2, - (ICONV_CONST char **) &inptr, &insize, - &out2ptr, &out2size); - else - { - /* TO_CODESET is UTF-8. */ - if (out2size >= insize) - { - memcpy (out2ptr, inptr, insize); - out2ptr += insize; - out2size -= insize; - inptr += insize; - insize = 0; - res = 0; - } - else - { - errno = E2BIG; - res = (size_t)(-1); - } - } - length = out2ptr - result; - if (res == (size_t)(-1) && errno == E2BIG) - { - char *memory; - - allocated = 2 * allocated; - if (length + 1 + extra_alloc > allocated) - abort (); - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - grow = false; - - out2ptr = result + length; - out2size = allocated - extra_alloc - length; - if (cd2 != (iconv_t)(-1)) - res = iconv (cd2, - (ICONV_CONST char **) &inptr, - &insize, - &out2ptr, &out2size); - else - { - /* TO_CODESET is UTF-8. */ - if (!(out2size >= insize)) - abort (); - memcpy (out2ptr, inptr, insize); - out2ptr += insize; - out2size -= insize; - inptr += insize; - insize = 0; - res = 0; - } - length = out2ptr - result; - } + res2 = 0; + do_final_flush2 = false; + incremented2 = true; + } + + length = out2ptr - result; + grow = (length + extra_alloc > allocated / 2); + if (res2 == (size_t)(-1)) + { + if (errno == E2BIG) + grow = true; + else if (errno == EINVAL) + break; + else if (errno == EILSEQ && handler != iconveh_error) + { + /* Error handling can produce up to 10 bytes of ASCII + output. But TO_CODESET may be UCS-2, UTF-16 or + UCS-4, so use CD2 here as well. */ + char scratchbuf[10]; + size_t scratchlen; + ucs4_t uc; + const char *inptr; + size_t insize; + size_t res; + + if (incremented2) + { + if (u8_prev (&uc, (const uint8_t *) in2ptr, + (const uint8_t *) utf8buf) + == NULL) + abort (); + } + else + { + int n; + if (in2size == 0) + abort (); + n = u8_mbtouc_unsafe (&uc, (const uint8_t *) in2ptr, + in2size); + in2ptr += n; + in2size -= n; + } + + if (handler == iconveh_escape_sequence) + { + static char hex[16] = "0123456789ABCDEF"; + scratchlen = 0; + scratchbuf[scratchlen++] = '\\'; + if (uc < 0x10000) + scratchbuf[scratchlen++] = 'u'; + else + { + scratchbuf[scratchlen++] = 'U'; + scratchbuf[scratchlen++] = hex[(uc>>28) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>24) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>20) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>16) & 15]; + } + scratchbuf[scratchlen++] = hex[(uc>>12) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>8) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>4) & 15]; + scratchbuf[scratchlen++] = hex[uc & 15]; + } + else + { + scratchbuf[0] = '?'; + scratchlen = 1; + } + + inptr = scratchbuf; + insize = scratchlen; + if (cd2 != (iconv_t)(-1)) + res = iconv (cd2, + (ICONV_CONST char **) &inptr, &insize, + &out2ptr, &out2size); + else + { + /* TO_CODESET is UTF-8. */ + if (out2size >= insize) + { + memcpy (out2ptr, inptr, insize); + out2ptr += insize; + out2size -= insize; + inptr += insize; + insize = 0; + res = 0; + } + else + { + errno = E2BIG; + res = (size_t)(-1); + } + } + length = out2ptr - result; + if (res == (size_t)(-1) && errno == E2BIG) + { + char *memory; + + allocated = 2 * allocated; + if (length + 1 + extra_alloc > allocated) + abort (); + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + grow = false; + + out2ptr = result + length; + out2size = allocated - extra_alloc - length; + if (cd2 != (iconv_t)(-1)) + res = iconv (cd2, + (ICONV_CONST char **) &inptr, + &insize, + &out2ptr, &out2size); + else + { + /* TO_CODESET is UTF-8. */ + if (!(out2size >= insize)) + abort (); + memcpy (out2ptr, inptr, insize); + out2ptr += insize; + out2size -= insize; + inptr += insize; + insize = 0; + res = 0; + } + length = out2ptr - result; + } # if !defined _LIBICONV_VERSION && !defined __GLIBC__ - /* Irix iconv() inserts a NUL byte if it cannot convert. - NetBSD iconv() inserts a question mark if it cannot - convert. - Only GNU libiconv and GNU libc are known to prefer - to fail rather than doing a lossy conversion. */ - if (res != (size_t)(-1) && res > 0) - { - errno = EILSEQ; - res = (size_t)(-1); - } + /* Irix iconv() inserts a NUL byte if it cannot convert. + NetBSD iconv() inserts a question mark if it cannot + convert. + Only GNU libiconv and GNU libc are known to prefer + to fail rather than doing a lossy conversion. */ + if (res != (size_t)(-1) && res > 0) + { + errno = EILSEQ; + res = (size_t)(-1); + } # endif - if (res == (size_t)(-1)) - { - /* Failure converting the ASCII replacement. */ - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } - else - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } - if (!(in2size > 0 - || (in1size == 0 && !do_final_flush1 && do_final_flush2))) - break; - if (grow) - { - char *memory; - - allocated = 2 * allocated; - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - } - } - - /* Move the remaining bytes to the beginning of utf8buf. */ - if (in2size > 0) - memmove (utf8buf, in2ptr, in2size); - utf8len = in2size; - } - - if (res1 == (size_t)(-1)) - { - if (errno1 == EINVAL) - in1size = 0; - else if (errno1 == EILSEQ) - { - if (result != initial_result) - free (result); - errno = errno1; - return -1; - } - } + if (res == (size_t)(-1)) + { + /* Failure converting the ASCII replacement. */ + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } + else + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } + if (!(in2size > 0 + || (in1size == 0 && !do_final_flush1 && do_final_flush2))) + break; + if (grow) + { + char *memory; + + allocated = 2 * allocated; + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + } + } + + /* Move the remaining bytes to the beginning of utf8buf. */ + if (in2size > 0) + memmove (utf8buf, in2ptr, in2size); + utf8len = in2size; + } + + if (res1 == (size_t)(-1)) + { + if (errno1 == EINVAL) + in1size = 0; + else if (errno1 == EILSEQ) + { + if (result != initial_result) + free (result); + errno = errno1; + return -1; + } + } } # undef utf8bufsize } @@ -974,14 +974,14 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, memory = (char *) malloc (memsize > 0 ? memsize : 1); if (memory != NULL) - { - memcpy (memory, tmpbuf, length); - result = memory; - } + { + memcpy (memory, tmpbuf, length); + result = memory; + } else - { - errno = ENOMEM; - return -1; + { + errno = ENOMEM; + return -1; } } else if (result != *resultp && length + extra_alloc < allocated) @@ -992,7 +992,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, memory = (char *) realloc (result, memsize > 0 ? memsize : 1); if (memory != NULL) - result = memory; + result = memory; } *resultp = result; *lengthp = length; @@ -1003,19 +1003,19 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, int mem_cd_iconveh (const char *src, size_t srclen, - const iconveh_t *cd, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const iconveh_t *cd, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { return mem_cd_iconveh_internal (src, srclen, cd->cd, cd->cd1, cd->cd2, - handler, 0, offsets, resultp, lengthp); + handler, 0, offsets, resultp, lengthp); } char * str_cd_iconveh (const char *src, - const iconveh_t *cd, - enum iconv_ilseq_handler handler) + const iconveh_t *cd, + enum iconv_ilseq_handler handler) { /* For most encodings, a trailing NUL byte in the input will be converted to a trailing NUL byte in the output. But not for UTF-7. So that this @@ -1024,17 +1024,17 @@ str_cd_iconveh (const char *src, char *result = NULL; size_t length = 0; int retval = mem_cd_iconveh_internal (src, strlen (src), - cd->cd, cd->cd1, cd->cd2, handler, 1, - NULL, &result, &length); + cd->cd, cd->cd1, cd->cd2, handler, 1, + NULL, &result, &length); if (retval < 0) { if (result != NULL) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } return NULL; } @@ -1048,10 +1048,10 @@ str_cd_iconveh (const char *src, int mem_iconveh (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { if (srclen == 0) { @@ -1064,16 +1064,16 @@ mem_iconveh (const char *src, size_t srclen, char *result; if (*resultp != NULL && *lengthp >= srclen) - result = *resultp; + result = *resultp; else - { - result = (char *) malloc (srclen); - if (result == NULL) - { - errno = ENOMEM; - return -1; - } - } + { + result = (char *) malloc (srclen); + if (result == NULL) + { + errno = ENOMEM; + return -1; + } + } memcpy (result, src, srclen); *resultp = result; *lengthp = srclen; @@ -1088,42 +1088,42 @@ mem_iconveh (const char *src, size_t srclen, int retval; if (iconveh_open (to_codeset, from_codeset, &cd) < 0) - return -1; + return -1; result = *resultp; length = *lengthp; retval = mem_cd_iconveh (src, srclen, &cd, handler, offsets, - &result, &length); + &result, &length); if (retval < 0) - { - /* Close cd, but preserve the errno from str_cd_iconv. */ - int saved_errno = errno; - iconveh_close (&cd); - errno = saved_errno; - } + { + /* Close cd, but preserve the errno from str_cd_iconv. */ + int saved_errno = errno; + iconveh_close (&cd); + errno = saved_errno; + } else - { - if (iconveh_close (&cd) < 0) - { - /* Return -1, but free the allocated memory, and while doing - that, preserve the errno from iconveh_close. */ - int saved_errno = errno; - if (result != *resultp && result != NULL) - free (result); - errno = saved_errno; - return -1; - } - *resultp = result; - *lengthp = length; - } + { + if (iconveh_close (&cd) < 0) + { + /* Return -1, but free the allocated memory, and while doing + that, preserve the errno from iconveh_close. */ + int saved_errno = errno; + if (result != *resultp && result != NULL) + free (result); + errno = saved_errno; + return -1; + } + *resultp = result; + *lengthp = length; + } return retval; #else /* This is a different error code than if iconv_open existed but didn't - support from_codeset and to_codeset, so that the caller can emit - an error message such as - "iconv() is not supported. Installing GNU libiconv and - then reinstalling this package would fix this." */ + support from_codeset and to_codeset, so that the caller can emit + an error message such as + "iconv() is not supported. Installing GNU libiconv and + then reinstalling this package would fix this." */ errno = ENOSYS; return -1; #endif @@ -1132,15 +1132,15 @@ mem_iconveh (const char *src, size_t srclen, char * str_iconveh (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler) { if (*src == '\0' || c_strcasecmp (from_codeset, to_codeset) == 0) { char *result = strdup (src); if (result == NULL) - errno = ENOMEM; + errno = ENOMEM; return result; } else @@ -1150,36 +1150,36 @@ str_iconveh (const char *src, char *result; if (iconveh_open (to_codeset, from_codeset, &cd) < 0) - return NULL; + return NULL; result = str_cd_iconveh (src, &cd, handler); if (result == NULL) - { - /* Close cd, but preserve the errno from str_cd_iconv. */ - int saved_errno = errno; - iconveh_close (&cd); - errno = saved_errno; - } + { + /* Close cd, but preserve the errno from str_cd_iconv. */ + int saved_errno = errno; + iconveh_close (&cd); + errno = saved_errno; + } else - { - if (iconveh_close (&cd) < 0) - { - /* Return NULL, but free the allocated memory, and while doing - that, preserve the errno from iconveh_close. */ - int saved_errno = errno; - free (result); - errno = saved_errno; - return NULL; - } - } + { + if (iconveh_close (&cd) < 0) + { + /* Return NULL, but free the allocated memory, and while doing + that, preserve the errno from iconveh_close. */ + int saved_errno = errno; + free (result); + errno = saved_errno; + return NULL; + } + } return result; #else /* This is a different error code than if iconv_open existed but didn't - support from_codeset and to_codeset, so that the caller can emit - an error message such as - "iconv() is not supported. Installing GNU libiconv and - then reinstalling this package would fix this." */ + support from_codeset and to_codeset, so that the caller can emit + an error message such as + "iconv() is not supported. Installing GNU libiconv and + then reinstalling this package would fix this." */ errno = ENOSYS; return NULL; #endif diff --git a/lib/striconveh.h b/lib/striconveh.h index e1543da03..72a7625a8 100644 --- a/lib/striconveh.h +++ b/lib/striconveh.h @@ -54,7 +54,7 @@ typedef struct set. */ extern int iconveh_open (const char *to_codeset, const char *from_codeset, - iconveh_t *cdp); + iconveh_t *cdp); /* Close a conversion descriptor created by iconveh_open(). Return value: 0 if successful, otherwise -1 and errno set. */ @@ -78,10 +78,10 @@ extern int unchanged if no dynamic memory allocation was necessary. */ extern int mem_cd_iconveh (const char *src, size_t srclen, - const iconveh_t *cd, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const iconveh_t *cd, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -94,8 +94,8 @@ extern int successful, otherwise NULL and errno set. */ extern char * str_cd_iconveh (const char *src, - const iconveh_t *cd, - enum iconv_ilseq_handler handler); + const iconveh_t *cd, + enum iconv_ilseq_handler handler); #endif @@ -114,10 +114,10 @@ extern char * unchanged if no dynamic memory allocation was necessary. */ extern int mem_iconveh (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -128,8 +128,8 @@ extern int successful, otherwise NULL and errno set. */ extern char * str_iconveh (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler); + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler); #ifdef __cplusplus diff --git a/lib/striconveha.c b/lib/striconveha.c index 8cb50094d..a43ed915e 100644 --- a/lib/striconveha.c +++ b/lib/striconveha.c @@ -82,7 +82,7 @@ static struct autodetect_alias **autodetect_list_end = int uniconv_register_autodetect (const char *name, - const char * const *try_in_order) + const char * const *try_in_order) { size_t namelen; size_t listlen; @@ -122,12 +122,12 @@ uniconv_register_autodetect (const char *name, memory += namelen; for (i = 0; i < listlen; i++) - { - size_t len = strlen (try_in_order[i]) + 1; - memcpy (memory, try_in_order[i], len); - new_try_in_order[i] = (const char *) memory; - memory += len; - } + { + size_t len = strlen (try_in_order[i]) + 1; + memcpy (memory, try_in_order[i], len); + new_try_in_order[i] = (const char *) memory; + memory += len; + } new_try_in_order[i] = NULL; /* Now insert the new alias. */ @@ -149,13 +149,13 @@ uniconv_register_autodetect (const char *name, /* Like mem_iconveha, except no handling of transliteration. */ static int mem_iconveha_notranslit (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { int retval = mem_iconveh (src, srclen, from_codeset, to_codeset, handler, - offsets, resultp, lengthp); + offsets, resultp, lengthp); if (retval >= 0 || errno != EINVAL) return retval; else @@ -163,45 +163,45 @@ mem_iconveha_notranslit (const char *src, size_t srclen, struct autodetect_alias *alias; /* Unsupported from_codeset or to_codeset. Check whether the caller - requested autodetection. */ + requested autodetection. */ for (alias = autodetect_list; alias != NULL; alias = alias->next) - if (strcmp (from_codeset, alias->name) == 0) - { - const char * const *encodings; - - if (handler != iconveh_error) - { - /* First try all encodings without any forgiving. */ - encodings = alias->encodings_to_try; - do - { - retval = mem_iconveha_notranslit (src, srclen, - *encodings, to_codeset, - iconveh_error, offsets, - resultp, lengthp); - if (!(retval < 0 && errno == EILSEQ)) - return retval; - encodings++; - } - while (*encodings != NULL); - } - - encodings = alias->encodings_to_try; - do - { - retval = mem_iconveha_notranslit (src, srclen, - *encodings, to_codeset, - handler, offsets, - resultp, lengthp); - if (!(retval < 0 && errno == EILSEQ)) - return retval; - encodings++; - } - while (*encodings != NULL); - - /* Return the last call's result. */ - return -1; - } + if (strcmp (from_codeset, alias->name) == 0) + { + const char * const *encodings; + + if (handler != iconveh_error) + { + /* First try all encodings without any forgiving. */ + encodings = alias->encodings_to_try; + do + { + retval = mem_iconveha_notranslit (src, srclen, + *encodings, to_codeset, + iconveh_error, offsets, + resultp, lengthp); + if (!(retval < 0 && errno == EILSEQ)) + return retval; + encodings++; + } + while (*encodings != NULL); + } + + encodings = alias->encodings_to_try; + do + { + retval = mem_iconveha_notranslit (src, srclen, + *encodings, to_codeset, + handler, offsets, + resultp, lengthp); + if (!(retval < 0 && errno == EILSEQ)) + return retval; + encodings++; + } + while (*encodings != NULL); + + /* Return the last call's result. */ + return -1; + } /* It wasn't an autodetection name. */ errno = EINVAL; @@ -211,11 +211,11 @@ mem_iconveha_notranslit (const char *src, size_t srclen, int mem_iconveha (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { if (srclen == 0) { @@ -236,8 +236,8 @@ mem_iconveha (const char *src, size_t srclen, memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1); retval = mem_iconveha_notranslit (src, srclen, - from_codeset, to_codeset_suffixed, - handler, offsets, resultp, lengthp); + from_codeset, to_codeset_suffixed, + handler, offsets, resultp, lengthp); freea (to_codeset_suffixed); @@ -246,15 +246,15 @@ mem_iconveha (const char *src, size_t srclen, else #endif return mem_iconveha_notranslit (src, srclen, - from_codeset, to_codeset, - handler, offsets, resultp, lengthp); + from_codeset, to_codeset, + handler, offsets, resultp, lengthp); } /* Like str_iconveha, except no handling of transliteration. */ static char * str_iconveha_notranslit (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler) { char *result = str_iconveh (src, from_codeset, to_codeset, handler); @@ -265,43 +265,43 @@ str_iconveha_notranslit (const char *src, struct autodetect_alias *alias; /* Unsupported from_codeset or to_codeset. Check whether the caller - requested autodetection. */ + requested autodetection. */ for (alias = autodetect_list; alias != NULL; alias = alias->next) - if (strcmp (from_codeset, alias->name) == 0) - { - const char * const *encodings; - - if (handler != iconveh_error) - { - /* First try all encodings without any forgiving. */ - encodings = alias->encodings_to_try; - do - { - result = str_iconveha_notranslit (src, - *encodings, to_codeset, - iconveh_error); - if (!(result == NULL && errno == EILSEQ)) - return result; - encodings++; - } - while (*encodings != NULL); - } - - encodings = alias->encodings_to_try; - do - { - result = str_iconveha_notranslit (src, - *encodings, to_codeset, - handler); - if (!(result == NULL && errno == EILSEQ)) - return result; - encodings++; - } - while (*encodings != NULL); - - /* Return the last call's result. */ - return NULL; - } + if (strcmp (from_codeset, alias->name) == 0) + { + const char * const *encodings; + + if (handler != iconveh_error) + { + /* First try all encodings without any forgiving. */ + encodings = alias->encodings_to_try; + do + { + result = str_iconveha_notranslit (src, + *encodings, to_codeset, + iconveh_error); + if (!(result == NULL && errno == EILSEQ)) + return result; + encodings++; + } + while (*encodings != NULL); + } + + encodings = alias->encodings_to_try; + do + { + result = str_iconveha_notranslit (src, + *encodings, to_codeset, + handler); + if (!(result == NULL && errno == EILSEQ)) + return result; + encodings++; + } + while (*encodings != NULL); + + /* Return the last call's result. */ + return NULL; + } /* It wasn't an autodetection name. */ errno = EINVAL; @@ -311,16 +311,16 @@ str_iconveha_notranslit (const char *src, char * str_iconveha (const char *src, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler) + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler) { if (*src == '\0' || c_strcasecmp (from_codeset, to_codeset) == 0) { char *result = strdup (src); if (result == NULL) - errno = ENOMEM; + errno = ENOMEM; return result; } @@ -336,7 +336,7 @@ str_iconveha (const char *src, memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1); result = str_iconveha_notranslit (src, from_codeset, to_codeset_suffixed, - handler); + handler); freea (to_codeset_suffixed); diff --git a/lib/striconveha.h b/lib/striconveha.h index 5ead5a67b..8c3fc7b10 100644 --- a/lib/striconveha.h +++ b/lib/striconveha.h @@ -48,11 +48,11 @@ extern "C" { unchanged if no dynamic memory allocation was necessary. */ extern int mem_iconveha (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -67,9 +67,9 @@ extern int successful, otherwise NULL and errno set. */ extern char * str_iconveha (const char *src, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler); + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler); /* In the above, FROM_CODESET can also be one of the following values: @@ -84,7 +84,7 @@ extern char * Particular errno values: ENOMEM. */ extern int uniconv_register_autodetect (const char *name, - const char * const *try_in_order); + const char * const *try_in_order); #ifdef __cplusplus diff --git a/lib/string.in.h b/lib/string.in.h index 04deb4295..05669db16 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -73,7 +73,7 @@ extern void *memchr (void const *__s, int __c, size_t __n) # endif # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ extern void *memmem (void const *__haystack, size_t __haystack_len, - void const *__needle, size_t __needle_len) + void const *__needle, size_t __needle_len) __attribute__ ((__pure__)); # endif #elif defined GNULIB_POSIXCHECK @@ -90,7 +90,7 @@ extern void *memmem (void const *__haystack, size_t __haystack_len, #if @GNULIB_MEMPCPY@ # if ! @HAVE_MEMPCPY@ extern void *mempcpy (void *restrict __dest, void const *restrict __src, - size_t __n); + size_t __n); # endif #elif defined GNULIB_POSIXCHECK # undef mempcpy @@ -149,7 +149,7 @@ extern char *stpcpy (char *restrict __dst, char const *restrict __src); # if ! @HAVE_STPNCPY@ # define stpncpy gnu_stpncpy extern char *stpncpy (char *restrict __dst, char const *restrict __src, - size_t __n); + size_t __n); # endif #elif defined GNULIB_POSIXCHECK # undef stpncpy @@ -379,12 +379,12 @@ extern char *strcasestr (const char *haystack, const char *needle) /* Parse S into tokens separated by characters in DELIM. If S is NULL, the saved pointer in SAVE_PTR is used as the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = strtok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" + char s[] = "-abc-=-def"; + char *sp; + x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = strtok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" This is a variant of strtok() that is multithread-safe. @@ -407,7 +407,7 @@ extern char *strcasestr (const char *haystack, const char *needle) # endif # if ! @HAVE_DECL_STRTOK_R@ || @REPLACE_STRTOK_R@ extern char *strtok_r (char *restrict s, char const *restrict delim, - char **restrict save_ptr); + char **restrict save_ptr); # endif # if defined GNULIB_POSIXCHECK # undef strtok_r @@ -562,12 +562,12 @@ extern char * mbssep (char **stringp, const char *delim); the character string DELIM. If STRING is NULL, the saved pointer in SAVE_PTR is used as the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = mbstok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" + char s[] = "-abc-=-def"; + char *sp; + x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = mbstok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" Caveat: It modifies the original string. Caveat: These functions cannot be used on constant strings. diff --git a/lib/strncasecmp.c b/lib/strncasecmp.c index 473a610fe..8a2ddce2e 100644 --- a/lib/strncasecmp.c +++ b/lib/strncasecmp.c @@ -46,7 +46,7 @@ strncasecmp (const char *s1, const char *s2, size_t n) c2 = TOLOWER (*p2); if (--n == 0 || c1 == '\0') - break; + break; ++p1; ++p2; diff --git a/lib/strpbrk.c b/lib/strpbrk.c index 7843a6dd6..82077322d 100644 --- a/lib/strpbrk.c +++ b/lib/strpbrk.c @@ -33,8 +33,8 @@ strpbrk (const char *s, const char *accept) { const char *a = accept; while (*a != '\0') - if (*a++ == *s) - return (char *) s; + if (*a++ == *s) + return (char *) s; ++s; } diff --git a/lib/strptime.c b/lib/strptime.c index a8791cf5a..f906b56fe 100644 --- a/lib/strptime.c +++ b/lib/strptime.c @@ -43,9 +43,9 @@ enum ptime_locale_status { not, loc, raw }; #define match_char(ch1, ch2) if (ch1 != ch2) return NULL #if defined _LIBC && defined __GNUC__ && __GNUC__ >= 2 # define match_string(cs1, s2) \ - ({ size_t len = strlen (cs1); \ - int result = __strncasecmp_l ((cs1), (s2), len, locale) == 0; \ - if (result) (s2) += len; \ + ({ size_t len = strlen (cs1); \ + int result = __strncasecmp_l ((cs1), (s2), len, locale) == 0; \ + if (result) (s2) += len; \ result; }) #else /* Oh come on. Get a reasonable compiler. */ @@ -55,52 +55,52 @@ enum ptime_locale_status { not, loc, raw }; /* We intentionally do not use isdigit() for testing because this will lead to problems with the wide character version. */ #define get_number(from, to, n) \ - do { \ - int __n = n; \ - val = 0; \ - while (*rp == ' ') \ - ++rp; \ - if (*rp < '0' || *rp > '9') \ - return NULL; \ - do { \ - val *= 10; \ - val += *rp++ - '0'; \ - } while (--__n > 0 && val * 10 <= to && *rp >= '0' && *rp <= '9'); \ - if (val < from || val > to) \ - return NULL; \ + do { \ + int __n = n; \ + val = 0; \ + while (*rp == ' ') \ + ++rp; \ + if (*rp < '0' || *rp > '9') \ + return NULL; \ + do { \ + val *= 10; \ + val += *rp++ - '0'; \ + } while (--__n > 0 && val * 10 <= to && *rp >= '0' && *rp <= '9'); \ + if (val < from || val > to) \ + return NULL; \ } while (0) #ifdef _NL_CURRENT # define get_alt_number(from, to, n) \ - ({ \ - __label__ do_normal; \ - \ - if (*decided != raw) \ - { \ - val = _nl_parse_alt_digit (&rp HELPER_LOCALE_ARG); \ - if (val == -1 && *decided != loc) \ - { \ - *decided = loc; \ - goto do_normal; \ - } \ - if (val < from || val > to) \ - return NULL; \ - } \ - else \ - { \ - do_normal: \ - get_number (from, to, n); \ - } \ - 0; \ + ({ \ + __label__ do_normal; \ + \ + if (*decided != raw) \ + { \ + val = _nl_parse_alt_digit (&rp HELPER_LOCALE_ARG); \ + if (val == -1 && *decided != loc) \ + { \ + *decided = loc; \ + goto do_normal; \ + } \ + if (val < from || val > to) \ + return NULL; \ + } \ + else \ + { \ + do_normal: \ + get_number (from, to, n); \ + } \ + 0; \ }) #else # define get_alt_number(from, to, n) \ - /* We don't have the alternate representation. */ \ + /* We don't have the alternate representation. */ \ get_number(from, to, n) #endif #define recursive(new_fmt) \ - (*(new_fmt) != '\0' \ - && (rp = __strptime_internal (rp, (new_fmt), tm, \ - decided, era_cnt LOCALE_ARG)) != NULL) + (*(new_fmt) != '\0' \ + && (rp = __strptime_internal (rp, (new_fmt), tm, \ + decided, era_cnt LOCALE_ARG)) != NULL) #ifdef _LIBC @@ -162,7 +162,7 @@ static const unsigned short int __mon_yday[2][13] = 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. */ -# define strptime __strptime_l +# define strptime __strptime_l # undef _NL_CURRENT # define _NL_CURRENT(category, item) \ (current->values[_NL_ITEM_INDEX (item)].string) @@ -190,7 +190,7 @@ static const unsigned short int __mon_yday[2][13] = #ifndef __isleap /* Nonzero if YEAR is a leap year (every 4 years, except every 100th isn't, and every 400th is). */ -# define __isleap(year) \ +# define __isleap(year) \ ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) #endif @@ -203,12 +203,12 @@ day_of_the_week (struct tm *tm) the weekday. */ int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2); int wday = (-473 - + (365 * (tm->tm_year - 70)) - + (corr_year / 4) - - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0) - + (((corr_year / 4) / 25) / 4) - + __mon_yday[0][tm->tm_mon] - + tm->tm_mday - 1); + + (365 * (tm->tm_year - 70)) + + (corr_year / 4) + - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0) + + (((corr_year / 4) / 25) / 4) + + __mon_yday[0][tm->tm_mon] + + tm->tm_mday - 1); tm->tm_wday = ((wday % 7) + 7) % 7; } @@ -217,7 +217,7 @@ static void day_of_the_year (struct tm *tm) { tm->tm_yday = (__mon_yday[__isleap (1900 + tm->tm_year)][tm->tm_mon] - + (tm->tm_mday - 1)); + + (tm->tm_mday - 1)); } @@ -266,22 +266,22 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM) while (*fmt != '\0') { /* A white space in the format string matches 0 more or white - space in the input string. */ + space in the input string. */ if (ISSPACE (*fmt)) - { - while (ISSPACE (*rp)) - ++rp; - ++fmt; - continue; - } + { + while (ISSPACE (*rp)) + ++rp; + ++fmt; + continue; + } /* Any character but `%' must be matched by the same character - in the iput string. */ + in the iput string. */ if (*fmt != '%') - { - match_char (*fmt++, *rp++); - continue; - } + { + match_char (*fmt++, *rp++); + continue; + } ++fmt; #ifndef _NL_CURRENT @@ -293,729 +293,729 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM) rp_backup = rp; switch (*fmt++) - { - case '%': - /* Match the `%' character itself. */ - match_char ('%', *rp++); - break; - case 'a': - case 'A': - /* Match day of week. */ - for (cnt = 0; cnt < 7; ++cnt) - { + { + case '%': + /* Match the `%' character itself. */ + match_char ('%', *rp++); + break; + case 'a': + case 'A': + /* Match day of week. */ + for (cnt = 0; cnt < 7; ++cnt) + { #ifdef _NL_CURRENT - if (*decided !=raw) - { - if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt), - weekday_name[cnt])) - *decided = loc; - break; - } - if (match_string (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), - ab_weekday_name[cnt])) - *decided = loc; - break; - } - } + if (*decided !=raw) + { + if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), rp)) + { + if (*decided == not + && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt), + weekday_name[cnt])) + *decided = loc; + break; + } + if (match_string (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), rp)) + { + if (*decided == not + && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), + ab_weekday_name[cnt])) + *decided = loc; + break; + } + } #endif - if (*decided != loc - && (match_string (weekday_name[cnt], rp) - || match_string (ab_weekday_name[cnt], rp))) - { - *decided = raw; - break; - } - } - if (cnt == 7) - /* Does not match a weekday name. */ - return NULL; - tm->tm_wday = cnt; - have_wday = 1; - break; - case 'b': - case 'B': - case 'h': - /* Match month name. */ - for (cnt = 0; cnt < 12; ++cnt) - { + if (*decided != loc + && (match_string (weekday_name[cnt], rp) + || match_string (ab_weekday_name[cnt], rp))) + { + *decided = raw; + break; + } + } + if (cnt == 7) + /* Does not match a weekday name. */ + return NULL; + tm->tm_wday = cnt; + have_wday = 1; + break; + case 'b': + case 'B': + case 'h': + /* Match month name. */ + for (cnt = 0; cnt < 12; ++cnt) + { #ifdef _NL_CURRENT - if (*decided !=raw) - { - if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt), - month_name[cnt])) - *decided = loc; - break; - } - if (match_string (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), - ab_month_name[cnt])) - *decided = loc; - break; - } - } + if (*decided !=raw) + { + if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), rp)) + { + if (*decided == not + && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt), + month_name[cnt])) + *decided = loc; + break; + } + if (match_string (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), rp)) + { + if (*decided == not + && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), + ab_month_name[cnt])) + *decided = loc; + break; + } + } #endif - if (match_string (month_name[cnt], rp) - || match_string (ab_month_name[cnt], rp)) - { - *decided = raw; - break; - } - } - if (cnt == 12) - /* Does not match a month name. */ - return NULL; - tm->tm_mon = cnt; - want_xday = 1; - break; - case 'c': - /* Match locale's date and time format. */ + if (match_string (month_name[cnt], rp) + || match_string (ab_month_name[cnt], rp)) + { + *decided = raw; + break; + } + } + if (cnt == 12) + /* Does not match a month name. */ + return NULL; + tm->tm_mon = cnt; + want_xday = 1; + break; + case 'c': + /* Match locale's date and time format. */ #ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, D_T_FMT))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (*decided == not && - strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT)) - *decided = loc; - want_xday = 1; - break; - } - *decided = raw; - } + if (*decided != raw) + { + if (!recursive (_NL_CURRENT (LC_TIME, D_T_FMT))) + { + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + if (*decided == not && + strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT)) + *decided = loc; + want_xday = 1; + break; + } + *decided = raw; + } #endif - if (!recursive (HERE_D_T_FMT)) - return NULL; - want_xday = 1; - break; - case 'C': - /* Match century number. */ - match_century: - get_number (0, 99, 2); - century = val; - want_xday = 1; - break; - case 'd': - case 'e': - /* Match day of month. */ - get_number (1, 31, 2); - tm->tm_mday = val; - have_mday = 1; - want_xday = 1; - break; - case 'F': - if (!recursive ("%Y-%m-%d")) - return NULL; - want_xday = 1; - break; - case 'x': + if (!recursive (HERE_D_T_FMT)) + return NULL; + want_xday = 1; + break; + case 'C': + /* Match century number. */ + match_century: + get_number (0, 99, 2); + century = val; + want_xday = 1; + break; + case 'd': + case 'e': + /* Match day of month. */ + get_number (1, 31, 2); + tm->tm_mday = val; + have_mday = 1; + want_xday = 1; + break; + case 'F': + if (!recursive ("%Y-%m-%d")) + return NULL; + want_xday = 1; + break; + case 'x': #ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, D_FMT))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT)) - *decided = loc; - want_xday = 1; - break; - } - *decided = raw; - } + if (*decided != raw) + { + if (!recursive (_NL_CURRENT (LC_TIME, D_FMT))) + { + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + if (*decided == not + && strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT)) + *decided = loc; + want_xday = 1; + break; + } + *decided = raw; + } #endif - /* Fall through. */ - case 'D': - /* Match standard day format. */ - if (!recursive (HERE_D_FMT)) - return NULL; - want_xday = 1; - break; - case 'k': - case 'H': - /* Match hour in 24-hour clock. */ - get_number (0, 23, 2); - tm->tm_hour = val; - have_I = 0; - break; - case 'l': - /* Match hour in 12-hour clock. GNU extension. */ - case 'I': - /* Match hour in 12-hour clock. */ - get_number (1, 12, 2); - tm->tm_hour = val % 12; - have_I = 1; - break; - case 'j': - /* Match day number of year. */ - get_number (1, 366, 3); - tm->tm_yday = val - 1; - have_yday = 1; - break; - case 'm': - /* Match number of month. */ - get_number (1, 12, 2); - tm->tm_mon = val - 1; - have_mon = 1; - want_xday = 1; - break; - case 'M': - /* Match minute. */ - get_number (0, 59, 2); - tm->tm_min = val; - break; - case 'n': - case 't': - /* Match any white space. */ - while (ISSPACE (*rp)) - ++rp; - break; - case 'p': - /* Match locale's equivalent of AM/PM. */ + /* Fall through. */ + case 'D': + /* Match standard day format. */ + if (!recursive (HERE_D_FMT)) + return NULL; + want_xday = 1; + break; + case 'k': + case 'H': + /* Match hour in 24-hour clock. */ + get_number (0, 23, 2); + tm->tm_hour = val; + have_I = 0; + break; + case 'l': + /* Match hour in 12-hour clock. GNU extension. */ + case 'I': + /* Match hour in 12-hour clock. */ + get_number (1, 12, 2); + tm->tm_hour = val % 12; + have_I = 1; + break; + case 'j': + /* Match day number of year. */ + get_number (1, 366, 3); + tm->tm_yday = val - 1; + have_yday = 1; + break; + case 'm': + /* Match number of month. */ + get_number (1, 12, 2); + tm->tm_mon = val - 1; + have_mon = 1; + want_xday = 1; + break; + case 'M': + /* Match minute. */ + get_number (0, 59, 2); + tm->tm_min = val; + break; + case 'n': + case 't': + /* Match any white space. */ + while (ISSPACE (*rp)) + ++rp; + break; + case 'p': + /* Match locale's equivalent of AM/PM. */ #ifdef _NL_CURRENT - if (*decided != raw) - { - if (match_string (_NL_CURRENT (LC_TIME, AM_STR), rp)) - { - if (strcmp (_NL_CURRENT (LC_TIME, AM_STR), HERE_AM_STR)) - *decided = loc; - break; - } - if (match_string (_NL_CURRENT (LC_TIME, PM_STR), rp)) - { - if (strcmp (_NL_CURRENT (LC_TIME, PM_STR), HERE_PM_STR)) - *decided = loc; - is_pm = 1; - break; - } - *decided = raw; - } + if (*decided != raw) + { + if (match_string (_NL_CURRENT (LC_TIME, AM_STR), rp)) + { + if (strcmp (_NL_CURRENT (LC_TIME, AM_STR), HERE_AM_STR)) + *decided = loc; + break; + } + if (match_string (_NL_CURRENT (LC_TIME, PM_STR), rp)) + { + if (strcmp (_NL_CURRENT (LC_TIME, PM_STR), HERE_PM_STR)) + *decided = loc; + is_pm = 1; + break; + } + *decided = raw; + } #endif - if (!match_string (HERE_AM_STR, rp)) - { - if (match_string (HERE_PM_STR, rp)) - is_pm = 1; - else - return NULL; - } - break; - case 'r': + if (!match_string (HERE_AM_STR, rp)) + { + if (match_string (HERE_PM_STR, rp)) + is_pm = 1; + else + return NULL; + } + break; + case 'r': #ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, T_FMT_AMPM))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (*decided == not && - strcmp (_NL_CURRENT (LC_TIME, T_FMT_AMPM), - HERE_T_FMT_AMPM)) - *decided = loc; - break; - } - *decided = raw; - } + if (*decided != raw) + { + if (!recursive (_NL_CURRENT (LC_TIME, T_FMT_AMPM))) + { + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + if (*decided == not && + strcmp (_NL_CURRENT (LC_TIME, T_FMT_AMPM), + HERE_T_FMT_AMPM)) + *decided = loc; + break; + } + *decided = raw; + } #endif - if (!recursive (HERE_T_FMT_AMPM)) - return NULL; - break; - case 'R': - if (!recursive ("%H:%M")) - return NULL; - break; - case 's': - { - /* The number of seconds may be very high so we cannot use - the `get_number' macro. Instead read the number - character for character and construct the result while - doing this. */ - time_t secs = 0; - if (*rp < '0' || *rp > '9') - /* We need at least one digit. */ - return NULL; - - do - { - secs *= 10; - secs += *rp++ - '0'; - } - while (*rp >= '0' && *rp <= '9'); - - if (localtime_r (&secs, tm) == NULL) - /* Error in function. */ - return NULL; - } - break; - case 'S': - get_number (0, 61, 2); - tm->tm_sec = val; - break; - case 'X': + if (!recursive (HERE_T_FMT_AMPM)) + return NULL; + break; + case 'R': + if (!recursive ("%H:%M")) + return NULL; + break; + case 's': + { + /* The number of seconds may be very high so we cannot use + the `get_number' macro. Instead read the number + character for character and construct the result while + doing this. */ + time_t secs = 0; + if (*rp < '0' || *rp > '9') + /* We need at least one digit. */ + return NULL; + + do + { + secs *= 10; + secs += *rp++ - '0'; + } + while (*rp >= '0' && *rp <= '9'); + + if (localtime_r (&secs, tm) == NULL) + /* Error in function. */ + return NULL; + } + break; + case 'S': + get_number (0, 61, 2); + tm->tm_sec = val; + break; + case 'X': #ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, T_FMT))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (_NL_CURRENT (LC_TIME, T_FMT), HERE_T_FMT)) - *decided = loc; - break; - } - *decided = raw; - } + if (*decided != raw) + { + if (!recursive (_NL_CURRENT (LC_TIME, T_FMT))) + { + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + if (strcmp (_NL_CURRENT (LC_TIME, T_FMT), HERE_T_FMT)) + *decided = loc; + break; + } + *decided = raw; + } #endif - /* Fall through. */ - case 'T': - if (!recursive (HERE_T_FMT)) - return NULL; - break; - case 'u': - get_number (1, 7, 1); - tm->tm_wday = val % 7; - have_wday = 1; - break; - case 'g': - get_number (0, 99, 2); - /* XXX This cannot determine any field in TM. */ - break; - case 'G': - if (*rp < '0' || *rp > '9') - return NULL; - /* XXX Ignore the number since we would need some more - information to compute a real date. */ - do - ++rp; - while (*rp >= '0' && *rp <= '9'); - break; - case 'U': - get_number (0, 53, 2); - week_no = val; - have_uweek = 1; - break; - case 'W': - get_number (0, 53, 2); - week_no = val; - have_wweek = 1; - break; - case 'V': - get_number (0, 53, 2); - /* XXX This cannot determine any field in TM without some - information. */ - break; - case 'w': - /* Match number of weekday. */ - get_number (0, 6, 1); - tm->tm_wday = val; - have_wday = 1; - break; - case 'y': - match_year_in_century: - /* Match year within century. */ - get_number (0, 99, 2); - /* The "Year 2000: The Millennium Rollover" paper suggests that - values in the range 69-99 refer to the twentieth century. */ - tm->tm_year = val >= 69 ? val : val + 100; - /* Indicate that we want to use the century, if specified. */ - want_century = 1; - want_xday = 1; - break; - case 'Y': - /* Match year including century number. */ - get_number (0, 9999, 4); - tm->tm_year = val - 1900; - want_century = 0; - want_xday = 1; - break; - case 'Z': - /* XXX How to handle this? */ - break; - case 'z': - /* We recognize two formats: if two digits are given, these - specify hours. If fours digits are used, minutes are - also specified. */ - { - bool neg; - int n; - - val = 0; - while (*rp == ' ') - ++rp; - if (*rp != '+' && *rp != '-') - return NULL; - neg = *rp++ == '-'; - n = 0; - while (n < 4 && *rp >= '0' && *rp <= '9') - { - val = val * 10 + *rp++ - '0'; - ++n; - } - if (n == 2) - val *= 100; - else if (n != 4) - /* Only two or four digits recognized. */ - return NULL; - else - { - /* We have to convert the minutes into decimal. */ - if (val % 100 >= 60) - return NULL; - val = (val / 100) * 100 + ((val % 100) * 50) / 30; - } - if (val > 1200) - return NULL; + /* Fall through. */ + case 'T': + if (!recursive (HERE_T_FMT)) + return NULL; + break; + case 'u': + get_number (1, 7, 1); + tm->tm_wday = val % 7; + have_wday = 1; + break; + case 'g': + get_number (0, 99, 2); + /* XXX This cannot determine any field in TM. */ + break; + case 'G': + if (*rp < '0' || *rp > '9') + return NULL; + /* XXX Ignore the number since we would need some more + information to compute a real date. */ + do + ++rp; + while (*rp >= '0' && *rp <= '9'); + break; + case 'U': + get_number (0, 53, 2); + week_no = val; + have_uweek = 1; + break; + case 'W': + get_number (0, 53, 2); + week_no = val; + have_wweek = 1; + break; + case 'V': + get_number (0, 53, 2); + /* XXX This cannot determine any field in TM without some + information. */ + break; + case 'w': + /* Match number of weekday. */ + get_number (0, 6, 1); + tm->tm_wday = val; + have_wday = 1; + break; + case 'y': + match_year_in_century: + /* Match year within century. */ + get_number (0, 99, 2); + /* The "Year 2000: The Millennium Rollover" paper suggests that + values in the range 69-99 refer to the twentieth century. */ + tm->tm_year = val >= 69 ? val : val + 100; + /* Indicate that we want to use the century, if specified. */ + want_century = 1; + want_xday = 1; + break; + case 'Y': + /* Match year including century number. */ + get_number (0, 9999, 4); + tm->tm_year = val - 1900; + want_century = 0; + want_xday = 1; + break; + case 'Z': + /* XXX How to handle this? */ + break; + case 'z': + /* We recognize two formats: if two digits are given, these + specify hours. If fours digits are used, minutes are + also specified. */ + { + bool neg; + int n; + + val = 0; + while (*rp == ' ') + ++rp; + if (*rp != '+' && *rp != '-') + return NULL; + neg = *rp++ == '-'; + n = 0; + while (n < 4 && *rp >= '0' && *rp <= '9') + { + val = val * 10 + *rp++ - '0'; + ++n; + } + if (n == 2) + val *= 100; + else if (n != 4) + /* Only two or four digits recognized. */ + return NULL; + else + { + /* We have to convert the minutes into decimal. */ + if (val % 100 >= 60) + return NULL; + val = (val / 100) * 100 + ((val % 100) * 50) / 30; + } + if (val > 1200) + return NULL; #if defined _LIBC || HAVE_TM_GMTOFF - tm->tm_gmtoff = (val * 3600) / 100; - if (neg) - tm->tm_gmtoff = -tm->tm_gmtoff; + tm->tm_gmtoff = (val * 3600) / 100; + if (neg) + tm->tm_gmtoff = -tm->tm_gmtoff; #endif - } - break; - case 'E': + } + break; + case 'E': #ifdef _NL_CURRENT - switch (*fmt++) - { - case 'c': - /* Match locale's alternate date and time format. */ - if (*decided != raw) - { - const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT); - - if (*fmt == '\0') - fmt = _NL_CURRENT (LC_TIME, D_T_FMT); - - if (!recursive (fmt)) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (fmt, HERE_D_T_FMT)) - *decided = loc; - want_xday = 1; - break; - } - *decided = raw; - } - /* The C locale has no era information, so use the - normal representation. */ - if (!recursive (HERE_D_T_FMT)) - return NULL; - want_xday = 1; - break; - case 'C': - if (*decided != raw) - { - if (era_cnt >= 0) - { - era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); - if (era != NULL && match_string (era->era_name, rp)) - { - *decided = loc; - break; - } - else - return NULL; - } - - num_eras = _NL_CURRENT_WORD (LC_TIME, - _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; - ++era_cnt, rp = rp_backup) - { - era = _nl_select_era_entry (era_cnt - HELPER_LOCALE_ARG); - if (era != NULL && match_string (era->era_name, rp)) - { - *decided = loc; - break; - } - } - if (era_cnt != (int) num_eras) - break; - - era_cnt = -1; - if (*decided == loc) - return NULL; - - *decided = raw; - } - /* The C locale has no era information, so use the - normal representation. */ - goto match_century; - case 'y': - if (*decided != raw) - { - get_number(0, 9999, 4); - tm->tm_year = val; - want_era = 1; - want_xday = 1; - want_century = 1; - - if (era_cnt >= 0) - { - assert (*decided == loc); - - era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); - bool match = false; - if (era != NULL) - { - int delta = ((tm->tm_year - era->offset) - * era->absolute_direction); - match = (delta >= 0 - && delta < (((int64_t) era->stop_date[0] - - (int64_t) era->start_date[0]) - * era->absolute_direction)); - } - if (! match) - return NULL; - - break; - } - - num_eras = _NL_CURRENT_WORD (LC_TIME, - _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; ++era_cnt) - { - era = _nl_select_era_entry (era_cnt - HELPER_LOCALE_ARG); - if (era != NULL) - { - int delta = ((tm->tm_year - era->offset) - * era->absolute_direction); - if (delta >= 0 - && delta < (((int64_t) era->stop_date[0] - - (int64_t) era->start_date[0]) - * era->absolute_direction)) - { - *decided = loc; - break; - } - } - } - if (era_cnt != (int) num_eras) - break; - - era_cnt = -1; - if (*decided == loc) - return NULL; - - *decided = raw; - } - - goto match_year_in_century; - case 'Y': - if (*decided != raw) - { - num_eras = _NL_CURRENT_WORD (LC_TIME, - _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; - ++era_cnt, rp = rp_backup) - { - era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); - if (era != NULL && recursive (era->era_format)) - break; - } - if (era_cnt == (int) num_eras) - { - era_cnt = -1; - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - *decided = loc; - era_cnt = -1; - break; - } - - *decided = raw; - } - get_number (0, 9999, 4); - tm->tm_year = val - 1900; - want_century = 0; - want_xday = 1; - break; - case 'x': - if (*decided != raw) - { - const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_FMT); - - if (*fmt == '\0') - fmt = _NL_CURRENT (LC_TIME, D_FMT); - - if (!recursive (fmt)) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (fmt, HERE_D_FMT)) - *decided = loc; - break; - } - *decided = raw; - } - if (!recursive (HERE_D_FMT)) - return NULL; - break; - case 'X': - if (*decided != raw) - { - const char *fmt = _NL_CURRENT (LC_TIME, ERA_T_FMT); - - if (*fmt == '\0') - fmt = _NL_CURRENT (LC_TIME, T_FMT); - - if (!recursive (fmt)) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (fmt, HERE_T_FMT)) - *decided = loc; - break; - } - *decided = raw; - } - if (!recursive (HERE_T_FMT)) - return NULL; - break; - default: - return NULL; - } - break; + switch (*fmt++) + { + case 'c': + /* Match locale's alternate date and time format. */ + if (*decided != raw) + { + const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT); + + if (*fmt == '\0') + fmt = _NL_CURRENT (LC_TIME, D_T_FMT); + + if (!recursive (fmt)) + { + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + if (strcmp (fmt, HERE_D_T_FMT)) + *decided = loc; + want_xday = 1; + break; + } + *decided = raw; + } + /* The C locale has no era information, so use the + normal representation. */ + if (!recursive (HERE_D_T_FMT)) + return NULL; + want_xday = 1; + break; + case 'C': + if (*decided != raw) + { + if (era_cnt >= 0) + { + era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); + if (era != NULL && match_string (era->era_name, rp)) + { + *decided = loc; + break; + } + else + return NULL; + } + + num_eras = _NL_CURRENT_WORD (LC_TIME, + _NL_TIME_ERA_NUM_ENTRIES); + for (era_cnt = 0; era_cnt < (int) num_eras; + ++era_cnt, rp = rp_backup) + { + era = _nl_select_era_entry (era_cnt + HELPER_LOCALE_ARG); + if (era != NULL && match_string (era->era_name, rp)) + { + *decided = loc; + break; + } + } + if (era_cnt != (int) num_eras) + break; + + era_cnt = -1; + if (*decided == loc) + return NULL; + + *decided = raw; + } + /* The C locale has no era information, so use the + normal representation. */ + goto match_century; + case 'y': + if (*decided != raw) + { + get_number(0, 9999, 4); + tm->tm_year = val; + want_era = 1; + want_xday = 1; + want_century = 1; + + if (era_cnt >= 0) + { + assert (*decided == loc); + + era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); + bool match = false; + if (era != NULL) + { + int delta = ((tm->tm_year - era->offset) + * era->absolute_direction); + match = (delta >= 0 + && delta < (((int64_t) era->stop_date[0] + - (int64_t) era->start_date[0]) + * era->absolute_direction)); + } + if (! match) + return NULL; + + break; + } + + num_eras = _NL_CURRENT_WORD (LC_TIME, + _NL_TIME_ERA_NUM_ENTRIES); + for (era_cnt = 0; era_cnt < (int) num_eras; ++era_cnt) + { + era = _nl_select_era_entry (era_cnt + HELPER_LOCALE_ARG); + if (era != NULL) + { + int delta = ((tm->tm_year - era->offset) + * era->absolute_direction); + if (delta >= 0 + && delta < (((int64_t) era->stop_date[0] + - (int64_t) era->start_date[0]) + * era->absolute_direction)) + { + *decided = loc; + break; + } + } + } + if (era_cnt != (int) num_eras) + break; + + era_cnt = -1; + if (*decided == loc) + return NULL; + + *decided = raw; + } + + goto match_year_in_century; + case 'Y': + if (*decided != raw) + { + num_eras = _NL_CURRENT_WORD (LC_TIME, + _NL_TIME_ERA_NUM_ENTRIES); + for (era_cnt = 0; era_cnt < (int) num_eras; + ++era_cnt, rp = rp_backup) + { + era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); + if (era != NULL && recursive (era->era_format)) + break; + } + if (era_cnt == (int) num_eras) + { + era_cnt = -1; + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + *decided = loc; + era_cnt = -1; + break; + } + + *decided = raw; + } + get_number (0, 9999, 4); + tm->tm_year = val - 1900; + want_century = 0; + want_xday = 1; + break; + case 'x': + if (*decided != raw) + { + const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_FMT); + + if (*fmt == '\0') + fmt = _NL_CURRENT (LC_TIME, D_FMT); + + if (!recursive (fmt)) + { + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + if (strcmp (fmt, HERE_D_FMT)) + *decided = loc; + break; + } + *decided = raw; + } + if (!recursive (HERE_D_FMT)) + return NULL; + break; + case 'X': + if (*decided != raw) + { + const char *fmt = _NL_CURRENT (LC_TIME, ERA_T_FMT); + + if (*fmt == '\0') + fmt = _NL_CURRENT (LC_TIME, T_FMT); + + if (!recursive (fmt)) + { + if (*decided == loc) + return NULL; + else + rp = rp_backup; + } + else + { + if (strcmp (fmt, HERE_T_FMT)) + *decided = loc; + break; + } + *decided = raw; + } + if (!recursive (HERE_T_FMT)) + return NULL; + break; + default: + return NULL; + } + break; #else - /* We have no information about the era format. Just use - the normal format. */ - if (*fmt != 'c' && *fmt != 'C' && *fmt != 'y' && *fmt != 'Y' - && *fmt != 'x' && *fmt != 'X') - /* This is an illegal format. */ - return NULL; - - goto start_over; + /* We have no information about the era format. Just use + the normal format. */ + if (*fmt != 'c' && *fmt != 'C' && *fmt != 'y' && *fmt != 'Y' + && *fmt != 'x' && *fmt != 'X') + /* This is an illegal format. */ + return NULL; + + goto start_over; #endif - case 'O': - switch (*fmt++) - { - case 'd': - case 'e': - /* Match day of month using alternate numeric symbols. */ - get_alt_number (1, 31, 2); - tm->tm_mday = val; - have_mday = 1; - want_xday = 1; - break; - case 'H': - /* Match hour in 24-hour clock using alternate numeric - symbols. */ - get_alt_number (0, 23, 2); - tm->tm_hour = val; - have_I = 0; - break; - case 'I': - /* Match hour in 12-hour clock using alternate numeric - symbols. */ - get_alt_number (1, 12, 2); - tm->tm_hour = val % 12; - have_I = 1; - break; - case 'm': - /* Match month using alternate numeric symbols. */ - get_alt_number (1, 12, 2); - tm->tm_mon = val - 1; - have_mon = 1; - want_xday = 1; - break; - case 'M': - /* Match minutes using alternate numeric symbols. */ - get_alt_number (0, 59, 2); - tm->tm_min = val; - break; - case 'S': - /* Match seconds using alternate numeric symbols. */ - get_alt_number (0, 61, 2); - tm->tm_sec = val; - break; - case 'U': - get_alt_number (0, 53, 2); - week_no = val; - have_uweek = 1; - break; - case 'W': - get_alt_number (0, 53, 2); - week_no = val; - have_wweek = 1; - break; - case 'V': - get_alt_number (0, 53, 2); - /* XXX This cannot determine any field in TM without - further information. */ - break; - case 'w': - /* Match number of weekday using alternate numeric symbols. */ - get_alt_number (0, 6, 1); - tm->tm_wday = val; - have_wday = 1; - break; - case 'y': - /* Match year within century using alternate numeric symbols. */ - get_alt_number (0, 99, 2); - tm->tm_year = val >= 69 ? val : val + 100; - want_xday = 1; - break; - default: - return NULL; - } - break; - default: - return NULL; - } + case 'O': + switch (*fmt++) + { + case 'd': + case 'e': + /* Match day of month using alternate numeric symbols. */ + get_alt_number (1, 31, 2); + tm->tm_mday = val; + have_mday = 1; + want_xday = 1; + break; + case 'H': + /* Match hour in 24-hour clock using alternate numeric + symbols. */ + get_alt_number (0, 23, 2); + tm->tm_hour = val; + have_I = 0; + break; + case 'I': + /* Match hour in 12-hour clock using alternate numeric + symbols. */ + get_alt_number (1, 12, 2); + tm->tm_hour = val % 12; + have_I = 1; + break; + case 'm': + /* Match month using alternate numeric symbols. */ + get_alt_number (1, 12, 2); + tm->tm_mon = val - 1; + have_mon = 1; + want_xday = 1; + break; + case 'M': + /* Match minutes using alternate numeric symbols. */ + get_alt_number (0, 59, 2); + tm->tm_min = val; + break; + case 'S': + /* Match seconds using alternate numeric symbols. */ + get_alt_number (0, 61, 2); + tm->tm_sec = val; + break; + case 'U': + get_alt_number (0, 53, 2); + week_no = val; + have_uweek = 1; + break; + case 'W': + get_alt_number (0, 53, 2); + week_no = val; + have_wweek = 1; + break; + case 'V': + get_alt_number (0, 53, 2); + /* XXX This cannot determine any field in TM without + further information. */ + break; + case 'w': + /* Match number of weekday using alternate numeric symbols. */ + get_alt_number (0, 6, 1); + tm->tm_wday = val; + have_wday = 1; + break; + case 'y': + /* Match year within century using alternate numeric symbols. */ + get_alt_number (0, 99, 2); + tm->tm_year = val >= 69 ? val : val + 100; + want_xday = 1; + break; + default: + return NULL; + } + break; + default: + return NULL; + } } if (have_I && is_pm) @@ -1024,10 +1024,10 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM) if (century != -1) { if (want_century) - tm->tm_year = tm->tm_year % 100 + (century - 19) * 100; + tm->tm_year = tm->tm_year % 100 + (century - 19) * 100; else - /* Only the century, but not the year. Strange, but so be it. */ - tm->tm_year = (century - 19) * 100; + /* Only the century, but not the year. Strange, but so be it. */ + tm->tm_year = (century - 19) * 100; } if (era_cnt != -1) @@ -1035,40 +1035,40 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM) #ifdef _NL_CURRENT era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); if (era == NULL) - return NULL; + return NULL; if (want_era) - tm->tm_year = (era->start_date[0] - + ((tm->tm_year - era->offset) - * era->absolute_direction)); + tm->tm_year = (era->start_date[0] + + ((tm->tm_year - era->offset) + * era->absolute_direction)); else - /* Era start year assumed. */ - tm->tm_year = era->start_date[0]; + /* Era start year assumed. */ + tm->tm_year = era->start_date[0]; #endif } else if (want_era) { - /* No era found but we have seen an E modifier. Rectify some - values. */ - if (want_century && century == -1 && tm->tm_year < 69) - tm->tm_year += 100; + /* No era found but we have seen an E modifier. Rectify some + values. */ + if (want_century && century == -1 && tm->tm_year < 69) + tm->tm_year += 100; } if (want_xday && !have_wday) { if ( !(have_mon && have_mday) && have_yday) - { - /* We don't have tm_mon and/or tm_mday, compute them. */ - int t_mon = 0; - while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday) - t_mon++; - if (!have_mon) - tm->tm_mon = t_mon - 1; - if (!have_mday) - tm->tm_mday = - (tm->tm_yday - - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); - } + { + /* We don't have tm_mon and/or tm_mday, compute them. */ + int t_mon = 0; + while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday) + t_mon++; + if (!have_mon) + tm->tm_mon = t_mon - 1; + if (!have_mday) + tm->tm_mday = + (tm->tm_yday + - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); + } day_of_the_week (tm); } @@ -1086,28 +1086,28 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM) tm->tm_mon = 0; day_of_the_week (tm); if (have_mday) - tm->tm_mday = save_mday; + tm->tm_mday = save_mday; if (have_mon) - tm->tm_mon = save_mon; + tm->tm_mon = save_mon; if (!have_yday) - tm->tm_yday = ((7 - (tm->tm_wday - w_offset)) % 7 - + (week_no - 1) *7 - + save_wday - w_offset); + tm->tm_yday = ((7 - (tm->tm_wday - w_offset)) % 7 + + (week_no - 1) *7 + + save_wday - w_offset); if (!have_mday || !have_mon) - { - int t_mon = 0; - while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] - <= tm->tm_yday) - t_mon++; - if (!have_mon) - tm->tm_mon = t_mon - 1; - if (!have_mday) - tm->tm_mday = - (tm->tm_yday - - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); - } + { + int t_mon = 0; + while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] + <= tm->tm_yday) + t_mon++; + if (!have_mon) + tm->tm_mon = t_mon - 1; + if (!have_mday) + tm->tm_mday = + (tm->tm_yday + - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); + } tm->tm_wday = save_wday; } diff --git a/lib/strsignal.c b/lib/strsignal.c index ee9f7a7bd..f4fb088d5 100644 --- a/lib/strsignal.c +++ b/lib/strsignal.c @@ -75,7 +75,7 @@ static __libc_key_t key; /* If nonzero the key allocation failed and we should better use a static buffer than fail. */ -#define BUFFERSIZ 100 +#define BUFFERSIZ 100 static char local_buf[BUFFERSIZ]; static char *static_buf; @@ -106,16 +106,16 @@ strsignal (int signum) int len; #ifdef SIGRTMIN if (signum >= SIGRTMIN && signum <= SIGRTMAX) - len = __snprintf (buffer, BUFFERSIZ - 1, _("Real-time signal %d"), - signum - SIGRTMIN); + len = __snprintf (buffer, BUFFERSIZ - 1, _("Real-time signal %d"), + signum - SIGRTMIN); else #endif - len = __snprintf (buffer, BUFFERSIZ - 1, _("Unknown signal %d"), - signum); + len = __snprintf (buffer, BUFFERSIZ - 1, _("Unknown signal %d"), + signum); if (len >= BUFFERSIZ) - buffer = NULL; + buffer = NULL; else - buffer[len] = '\0'; + buffer[len] = '\0'; return buffer; } @@ -177,18 +177,18 @@ getbuffer (void) else { /* We don't use the static buffer and so we have a key. Use it - to get the thread-specific buffer. */ + 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); - } + { + /* 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/lib/strstr.c b/lib/strstr.c index 338be82a8..b58353d9e 100644 --- a/lib/strstr.c +++ b/lib/strstr.c @@ -32,8 +32,8 @@ #endif #define RETURN_TYPE char * -#define AVAILABLE(h, h_l, j, n_l) \ - (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ +#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" @@ -67,17 +67,17 @@ strstr (const char *haystack_start, const char *needle_start) return (char *) haystack; needle -= needle_len; haystack_len = (haystack > haystack_start + needle_len ? 1 - : needle_len + haystack_start - haystack); + : 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); + 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); + (const unsigned char *) needle, needle_len); } #undef LONG_NEEDLE_THRESHOLD diff --git a/lib/strtod.c b/lib/strtod.c index a2a4d3db6..853ca1cb2 100644 --- a/lib/strtod.c +++ b/lib/strtod.c @@ -38,9 +38,9 @@ strtod (const char *nptr, char **endptr) /* The number so far. */ double num; - bool got_dot; /* Found a decimal point. */ - bool got_digit; /* Seen any digits. */ - bool hex = false; /* Look for hex float exponent. */ + bool got_dot; /* Found a decimal point. */ + bool got_digit; /* Seen any digits. */ + bool hex = false; /* Look for hex float exponent. */ /* The exponent of the number. */ long int exponent; @@ -75,114 +75,114 @@ strtod (const char *nptr, char **endptr) hex = true; s += 2; for (;; ++s) - { - if (c_isxdigit (*s)) - { - got_digit = true; - - /* Make sure that multiplication by 16 will not overflow. */ - if (num > DBL_MAX / 16) - /* The value of the digit doesn't matter, since we have already - gotten as many digits as can be represented in a `double'. - This doesn't necessarily mean the result will overflow. - The exponent may reduce it to within range. - - We just need to record that there was another - digit so that we can multiply by 16 later. */ - ++exponent; - else - num = ((num * 16.0) - + (c_tolower (*s) - (c_isdigit (*s) ? '0' : 'a' - 10))); - - /* Keep track of the number of digits after the decimal point. - If we just divided by 16 here, we would lose precision. */ - if (got_dot) - --exponent; - } - else if (!got_dot && *s == '.') - /* Record that we have found the decimal point. */ - got_dot = true; - else - /* Any other character terminates the number. */ - break; - } + { + if (c_isxdigit (*s)) + { + got_digit = true; + + /* Make sure that multiplication by 16 will not overflow. */ + if (num > DBL_MAX / 16) + /* The value of the digit doesn't matter, since we have already + gotten as many digits as can be represented in a `double'. + This doesn't necessarily mean the result will overflow. + The exponent may reduce it to within range. + + We just need to record that there was another + digit so that we can multiply by 16 later. */ + ++exponent; + else + num = ((num * 16.0) + + (c_tolower (*s) - (c_isdigit (*s) ? '0' : 'a' - 10))); + + /* Keep track of the number of digits after the decimal point. + If we just divided by 16 here, we would lose precision. */ + if (got_dot) + --exponent; + } + else if (!got_dot && *s == '.') + /* Record that we have found the decimal point. */ + got_dot = true; + else + /* Any other character terminates the number. */ + break; + } } /* Not a hex float. */ else { for (;; ++s) - { - if (c_isdigit (*s)) - { - got_digit = true; - - /* Make sure that multiplication by 10 will not overflow. */ - if (num > DBL_MAX * 0.1) - /* The value of the digit doesn't matter, since we have already - gotten as many digits as can be represented in a `double'. - This doesn't necessarily mean the result will overflow. - The exponent may reduce it to within range. - - We just need to record that there was another - digit so that we can multiply by 10 later. */ - ++exponent; - else - num = (num * 10.0) + (*s - '0'); - - /* Keep track of the number of digits after the decimal point. - If we just divided by 10 here, we would lose precision. */ - if (got_dot) - --exponent; - } - else if (!got_dot && *s == '.') - /* Record that we have found the decimal point. */ - got_dot = true; - else - /* Any other character terminates the number. */ - break; - } + { + if (c_isdigit (*s)) + { + got_digit = true; + + /* Make sure that multiplication by 10 will not overflow. */ + if (num > DBL_MAX * 0.1) + /* The value of the digit doesn't matter, since we have already + gotten as many digits as can be represented in a `double'. + This doesn't necessarily mean the result will overflow. + The exponent may reduce it to within range. + + We just need to record that there was another + digit so that we can multiply by 10 later. */ + ++exponent; + else + num = (num * 10.0) + (*s - '0'); + + /* Keep track of the number of digits after the decimal point. + If we just divided by 10 here, we would lose precision. */ + if (got_dot) + --exponent; + } + else if (!got_dot && *s == '.') + /* Record that we have found the decimal point. */ + got_dot = true; + else + /* Any other character terminates the number. */ + break; + } } if (!got_digit) { /* Check for infinities and NaNs. */ if (c_tolower (*s) == 'i' - && c_tolower (s[1]) == 'n' - && c_tolower (s[2]) == 'f') - { - s += 3; - num = HUGE_VAL; - if (c_tolower (*s) == 'i' - && c_tolower (s[1]) == 'n' - && c_tolower (s[2]) == 'i' - && c_tolower (s[3]) == 't' - && c_tolower (s[4]) == 'y') - s += 5; - goto valid; - } + && c_tolower (s[1]) == 'n' + && c_tolower (s[2]) == 'f') + { + s += 3; + num = HUGE_VAL; + if (c_tolower (*s) == 'i' + && c_tolower (s[1]) == 'n' + && c_tolower (s[2]) == 'i' + && c_tolower (s[3]) == 't' + && c_tolower (s[4]) == 'y') + s += 5; + goto valid; + } #ifdef NAN else if (c_tolower (*s) == 'n' - && c_tolower (s[1]) == 'a' - && c_tolower (s[2]) == 'n') - { - s += 3; - num = NAN; - /* Since nan() is implementation-defined, - we define it by ignoring . A nicer - implementation would populate the bits of the NaN - according to interpreting n-char-sequence as a - hexadecimal number, but the result is still a NaN. */ - if (*s == '(') - { - const unsigned char *p = s + 1; - while (c_isalnum (*p)) - p++; - if (*p == ')') - s = p + 1; - } - goto valid; - } + && c_tolower (s[1]) == 'a' + && c_tolower (s[2]) == 'n') + { + s += 3; + num = NAN; + /* Since nan() is implementation-defined, + we define it by ignoring . A nicer + implementation would populate the bits of the NaN + according to interpreting n-char-sequence as a + hexadecimal number, but the result is still a NaN. */ + if (*s == '(') + { + const unsigned char *p = s + 1; + while (c_isalnum (*p)) + p++; + if (*p == ')') + s = p + 1; + } + goto valid; + } #endif goto noconv; } @@ -198,21 +198,21 @@ strtod (const char *nptr, char **endptr) ++s; value = strtol ((char *) s, &end, 10); if (errno == ERANGE && num) - { - /* The exponent overflowed a `long int'. It is probably a safe - assumption that an exponent that cannot be represented by - a `long int' exceeds the limits of a `double'. */ - if (endptr != NULL) - *endptr = end; - if (value < 0) - goto underflow; - else - goto overflow; - } + { + /* The exponent overflowed a `long int'. It is probably a safe + assumption that an exponent that cannot be represented by + a `long int' exceeds the limits of a `double'. */ + if (endptr != NULL) + *endptr = end; + if (value < 0) + goto underflow; + else + goto overflow; + } else if (end == (char *) s) - /* There was no exponent. Reset END to point to - the 'e' or 'E', so *ENDPTR will be set there. */ - end = (char *) s - 1; + /* There was no exponent. Reset END to point to + the 'e' or 'E', so *ENDPTR will be set there. */ + end = (char *) s - 1; errno = save; s = (unsigned char *) end; exponent += value; @@ -234,12 +234,12 @@ strtod (const char *nptr, char **endptr) if (exponent < 0) { if (num < DBL_MIN * pow (10.0, (double) -exponent)) - goto underflow; + goto underflow; } else if (exponent > 0) { if (num > DBL_MAX * pow (10.0, (double) -exponent)) - goto overflow; + goto overflow; } num *= pow (10.0, (double) exponent); diff --git a/lib/strtoimax.c b/lib/strtoimax.c index ab9bcff3c..f7c20a445 100644 --- a/lib/strtoimax.c +++ b/lib/strtoimax.c @@ -63,7 +63,7 @@ strtoimax (char const *ptr, char **endptr, int base) { #if Have_long_long verify (sizeof (Int) == sizeof (Unsigned long int) - || sizeof (Int) == sizeof (Unsigned long long int)); + || sizeof (Int) == sizeof (Unsigned long long int)); if (sizeof (Int) != sizeof (Unsigned long int)) return strtoll (ptr, endptr, base); diff --git a/lib/strtok_r.c b/lib/strtok_r.c index f7e0e63e5..67c9d2d81 100644 --- a/lib/strtok_r.c +++ b/lib/strtok_r.c @@ -32,12 +32,12 @@ /* Parse S into tokens separated by characters in DELIM. If S is NULL, the saved pointer in SAVE_PTR is used as the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = strtok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" + char s[] = "-abc-=-def"; + char *sp; + x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = strtok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" */ char * __strtok_r (char *s, const char *delim, char **save_ptr) diff --git a/lib/strtol.c b/lib/strtol.c index 0b2c82a01..a6ca72885 100644 --- a/lib/strtol.c +++ b/lib/strtol.c @@ -139,14 +139,14 @@ your host. */ # define TYPE_MINIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ - ? (t) 0 \ - : TYPE_SIGNED_MAGNITUDE (t) \ - ? ~ (t) 0 \ - : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) + ? (t) 0 \ + : TYPE_SIGNED_MAGNITUDE (t) \ + ? ~ (t) 0 \ + : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) # define TYPE_MAXIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ - ? (t) -1 \ - : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) + ? (t) -1 \ + : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) # ifndef ULONG_LONG_MAX # define ULONG_LONG_MAX TYPE_MAXIMUM (unsigned long long) @@ -238,7 +238,7 @@ INT INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, - int base, int group LOCALE_PARAM_PROTO) + int base, int group LOCALE_PARAM_PROTO) { int negative; register unsigned LONG int cutoff; @@ -263,18 +263,18 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, { grouping = _NL_CURRENT (LC_NUMERIC, GROUPING); if (*grouping <= 0 || *grouping == CHAR_MAX) - grouping = NULL; + grouping = NULL; else - { - /* Figure out the thousands separator character. */ + { + /* 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'; + thousands = __btowc (*_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP)); + if (thousands == WEOF) + thousands = L'\0'; # endif - if (thousands == L'\0') - grouping = NULL; - } + if (thousands == L'\0') + grouping = NULL; + } } else grouping = NULL; @@ -312,12 +312,12 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, if (*s == L_('0')) { if ((base == 0 || base == 16) && TOUPPER (s[1]) == L_('X')) - { - s += 2; - base = 16; - } + { + s += 2; + base = 16; + } else if (base == 0) - base = 8; + base = 8; } else if (base == 0) base = 10; @@ -331,14 +331,14 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, /* 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 ((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; + end = s; else - end = correctly_grouped_prefix (s, end, thousands, grouping); + end = correctly_grouped_prefix (s, end, thousands, grouping); } else #endif @@ -352,23 +352,23 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, for (c = *s; c != L_('\0'); c = *++s) { if (s == end) - break; + break; if (c >= L_('0') && c <= L_('9')) - c -= L_('0'); + c -= L_('0'); else if (ISALPHA (c)) - c = TOUPPER (c) - L_('A') + 10; + c = TOUPPER (c) - L_('A') + 10; else - break; + break; if ((int) c >= base) - break; + break; /* Check for overflow. */ if (i > cutoff || (i == cutoff && c > cutlim)) - overflow = 1; + overflow = 1; else - { - i *= (unsigned LONG int) base; - i += c; - } + { + i *= (unsigned LONG int) base; + i += c; + } } /* Check if anything actually happened. */ @@ -385,8 +385,8 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, `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)) + ? -((unsigned LONG int) (STRTOL_LONG_MIN + 1)) + 1 + : (unsigned LONG int) STRTOL_LONG_MAX)) overflow = 1; #endif @@ -411,11 +411,11 @@ noconv: if (endptr != NULL) { if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X') - && save[-2] == L_('0')) - *endptr = (STRING_TYPE *) &save[-1]; + && save[-2] == L_('0')) + *endptr = (STRING_TYPE *) &save[-1]; else - /* There was no number to convert. */ - *endptr = (STRING_TYPE *) nptr; + /* There was no number to convert. */ + *endptr = (STRING_TYPE *) nptr; } return 0L; @@ -429,7 +429,7 @@ INT weak_function #endif strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, - int base LOCALE_PARAM_PROTO) + int base LOCALE_PARAM_PROTO) { return INTERNAL (strtol) (nptr, endptr, base, 0 LOCALE_PARAM); } diff --git a/lib/strtoll.c b/lib/strtoll.c index ccc99cb43..84a7a09e8 100644 --- a/lib/strtoll.c +++ b/lib/strtoll.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#define QUAD 1 +#define QUAD 1 #include diff --git a/lib/strtoul.c b/lib/strtoul.c index 88dbfc074..94d1164ea 100644 --- a/lib/strtoul.c +++ b/lib/strtoul.c @@ -14,6 +14,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#define UNSIGNED 1 +#define UNSIGNED 1 #include "strtol.c" diff --git a/lib/strverscmp.c b/lib/strverscmp.c index f0776516f..fe37a27d6 100644 --- a/lib/strverscmp.c +++ b/lib/strverscmp.c @@ -117,8 +117,8 @@ __strverscmp (const char *s1, const char *s2) case LEN: while (ISDIGIT (*p1++)) - if (!ISDIGIT (*p2++)) - return 1; + if (!ISDIGIT (*p2++)) + return 1; return ISDIGIT (*p2) ? -1 : diff; diff --git a/lib/symlink.c b/lib/symlink.c index 89ddddb6f..1e6cbedc3 100644 --- a/lib/symlink.c +++ b/lib/symlink.c @@ -37,7 +37,7 @@ rpl_symlink (char const *contents, char const *name) { struct stat st; if (lstat (name, &st) == 0) - errno = EEXIST; + errno = EEXIST; return -1; } return symlink (contents, name); @@ -48,7 +48,7 @@ rpl_symlink (char const *contents, char const *name) /* The system does not support symlinks. */ int symlink (char const *contents _UNUSED_PARAMETER_, - char const *name _UNUSED_PARAMETER_) + char const *name _UNUSED_PARAMETER_) { errno = ENOSYS; return -1; diff --git a/lib/symlinkat.c b/lib/symlinkat.c index d9032b93a..cb5251048 100644 --- a/lib/symlinkat.c +++ b/lib/symlinkat.c @@ -28,7 +28,7 @@ int symlinkat (char const *path1 _UNUSED_PARAMETER_, int fd _UNUSED_PARAMETER_, - char const *path2 _UNUSED_PARAMETER_) + char const *path2 _UNUSED_PARAMETER_) { errno = ENOSYS; return -1; diff --git a/lib/sys_file.in.h b/lib/sys_file.in.h index a16eea083..a8f81fe6b 100644 --- a/lib/sys_file.in.h +++ b/lib/sys_file.in.h @@ -49,7 +49,7 @@ extern int flock (int fd, int operation); # endif #elif defined GNULIB_POSIXCHECK # undef flock -# define flock(fd,op) \ +# define flock(fd,op) \ (GL_LINK_WARNING ("flock is unportable - " \ "use gnulib module flock for portability"), \ flock ((fd), (op))) diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h index e3f6d6c6e..c94ce172f 100644 --- a/lib/sys_socket.in.h +++ b/lib/sys_socket.in.h @@ -54,10 +54,10 @@ typedef unsigned short sa_family_t; # define __ss_aligntype unsigned long int # define _SS_SIZE 256 # define _SS_PADSIZE \ - (_SS_SIZE - ((sizeof (sa_family_t) >= alignof (__ss_aligntype) \ - ? sizeof (sa_family_t) \ - : alignof (__ss_aligntype)) \ - + sizeof (__ss_aligntype))) + (_SS_SIZE - ((sizeof (sa_family_t) >= alignof (__ss_aligntype) \ + ? sizeof (sa_family_t) \ + : alignof (__ss_aligntype)) \ + + sizeof (__ss_aligntype))) struct sockaddr_storage { @@ -177,7 +177,7 @@ rpl_fd_isset (SOCKET fd, fd_set * set) # if @GNULIB_SOCKET@ # if @HAVE_WINSOCK2_H@ # undef socket -# define socket rpl_socket +# define socket rpl_socket extern int rpl_socket (int, int, int protocol); # endif # elif @HAVE_WINSOCK2_H@ @@ -194,7 +194,7 @@ extern int rpl_socket (int, int, int protocol); # if @GNULIB_CONNECT@ # if @HAVE_WINSOCK2_H@ # undef connect -# define connect rpl_connect +# define connect rpl_connect extern int rpl_connect (int, struct sockaddr *, int); # endif # elif @HAVE_WINSOCK2_H@ @@ -211,7 +211,7 @@ extern int rpl_connect (int, struct sockaddr *, int); # if @GNULIB_ACCEPT@ # if @HAVE_WINSOCK2_H@ # undef accept -# define accept rpl_accept +# define accept rpl_accept extern int rpl_accept (int, struct sockaddr *, int *); # endif # elif @HAVE_WINSOCK2_H@ @@ -228,7 +228,7 @@ extern int rpl_accept (int, struct sockaddr *, int *); # if @GNULIB_BIND@ # if @HAVE_WINSOCK2_H@ # undef bind -# define bind rpl_bind +# define bind rpl_bind extern int rpl_bind (int, struct sockaddr *, int); # endif # elif @HAVE_WINSOCK2_H@ @@ -245,7 +245,7 @@ extern int rpl_bind (int, struct sockaddr *, int); # if @GNULIB_GETPEERNAME@ # if @HAVE_WINSOCK2_H@ # undef getpeername -# define getpeername rpl_getpeername +# define getpeername rpl_getpeername extern int rpl_getpeername (int, struct sockaddr *, int *); # endif # elif @HAVE_WINSOCK2_H@ @@ -262,7 +262,7 @@ extern int rpl_getpeername (int, struct sockaddr *, int *); # if @GNULIB_GETSOCKNAME@ # if @HAVE_WINSOCK2_H@ # undef getsockname -# define getsockname rpl_getsockname +# define getsockname rpl_getsockname extern int rpl_getsockname (int, struct sockaddr *, int *); # endif # elif @HAVE_WINSOCK2_H@ @@ -279,7 +279,7 @@ extern int rpl_getsockname (int, struct sockaddr *, int *); # if @GNULIB_GETSOCKOPT@ # if @HAVE_WINSOCK2_H@ # undef getsockopt -# define getsockopt rpl_getsockopt +# define getsockopt rpl_getsockopt extern int rpl_getsockopt (int, int, int, void *, socklen_t *); # endif # elif @HAVE_WINSOCK2_H@ @@ -296,7 +296,7 @@ extern int rpl_getsockopt (int, int, int, void *, socklen_t *); # if @GNULIB_LISTEN@ # if @HAVE_WINSOCK2_H@ # undef listen -# define listen rpl_listen +# define listen rpl_listen extern int rpl_listen (int, int); # endif # elif @HAVE_WINSOCK2_H@ @@ -313,7 +313,7 @@ extern int rpl_listen (int, int); # if @GNULIB_RECV@ # if @HAVE_WINSOCK2_H@ # undef recv -# define recv rpl_recv +# define recv rpl_recv extern int rpl_recv (int, void *, int, int); # endif # elif @HAVE_WINSOCK2_H@ @@ -330,7 +330,7 @@ extern int rpl_recv (int, void *, int, int); # if @GNULIB_SEND@ # if @HAVE_WINSOCK2_H@ # undef send -# define send rpl_send +# define send rpl_send extern int rpl_send (int, const void *, int, int); # endif # elif @HAVE_WINSOCK2_H@ @@ -347,7 +347,7 @@ extern int rpl_send (int, const void *, int, int); # if @GNULIB_RECVFROM@ # if @HAVE_WINSOCK2_H@ # undef recvfrom -# define recvfrom rpl_recvfrom +# define recvfrom rpl_recvfrom extern int rpl_recvfrom (int, void *, int, int, struct sockaddr *, int *); # endif # elif @HAVE_WINSOCK2_H@ @@ -364,7 +364,7 @@ extern int rpl_recvfrom (int, void *, int, int, struct sockaddr *, int *); # if @GNULIB_SENDTO@ # if @HAVE_WINSOCK2_H@ # undef sendto -# define sendto rpl_sendto +# define sendto rpl_sendto extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int); # endif # elif @HAVE_WINSOCK2_H@ @@ -381,7 +381,7 @@ extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int); # if @GNULIB_SETSOCKOPT@ # if @HAVE_WINSOCK2_H@ # undef setsockopt -# define setsockopt rpl_setsockopt +# define setsockopt rpl_setsockopt extern int rpl_setsockopt (int, int, int, const void *, socklen_t); # endif # elif @HAVE_WINSOCK2_H@ @@ -398,7 +398,7 @@ extern int rpl_setsockopt (int, int, int, const void *, socklen_t); # if @GNULIB_SHUTDOWN@ # if @HAVE_WINSOCK2_H@ # undef shutdown -# define shutdown rpl_shutdown +# define shutdown rpl_shutdown extern int rpl_shutdown (int, int); # endif # elif @HAVE_WINSOCK2_H@ @@ -414,7 +414,7 @@ extern int rpl_shutdown (int, int); # if @HAVE_WINSOCK2_H@ # undef select -# define select select_used_without_including_sys_select_h +# define select select_used_without_including_sys_select_h # endif # ifdef __cplusplus @@ -437,7 +437,7 @@ extern "C" { # define accept4 rpl_accept4 # endif extern int accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, - int flags); + int flags); #elif defined GNULIB_POSIXCHECK # undef accept4 # define accept4(s,a,l,f) \ diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index 4c6644890..48d7fc1bb 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -383,9 +383,9 @@ extern int rpl_lstat (const char *name, struct stat *buf); # endif #elif defined GNULIB_POSIXCHECK # undef lstat -# define lstat(p,b) \ - (GL_LINK_WARNING ("lstat is unportable - " \ - "use gnulib module lstat for portability"), \ +# define lstat(p,b) \ + (GL_LINK_WARNING ("lstat is unportable - " \ + "use gnulib module lstat for portability"), \ lstat (p, b)) #endif @@ -447,7 +447,7 @@ int mkfifoat (int fd, char const *file, mode_t mode); # endif #elif defined GNULIB_POSIXCHECK # undef mkfifoat -# define mkfifoat(d,n,m) \ +# define mkfifoat(d,n,m) \ (GL_LINK_WARNING ("mkfifoat is not portable - " \ "use gnulib module mkfifoat for portability"), \ mkfifoat (d, n, m)) @@ -477,7 +477,7 @@ int mknodat (int fd, char const *file, mode_t mode, dev_t dev); # endif #elif defined GNULIB_POSIXCHECK # undef mknodat -# define mknodat(f,n,m,d) \ +# define mknodat(f,n,m,d) \ (GL_LINK_WARNING ("mknodat is not portable - " \ "use gnulib module mkfifoat for portability"), \ mknodat (f, n, m, d)) @@ -503,9 +503,9 @@ extern int stat (const char *name, struct stat *buf); # endif #elif defined GNULIB_POSIXCHECK # undef stat -# define stat(p,b) \ - (GL_LINK_WARNING ("stat is unportable - " \ - "use gnulib module stat for portability"), \ +# define stat(p,b) \ + (GL_LINK_WARNING ("stat is unportable - " \ + "use gnulib module stat for portability"), \ stat (p, b)) #endif diff --git a/lib/sys_times.in.h b/lib/sys_times.in.h index 56ac45313..381d7de56 100644 --- a/lib/sys_times.in.h +++ b/lib/sys_times.in.h @@ -35,20 +35,20 @@ extern "C" { /* Structure describing CPU time used by a process and its children. */ struct tms { - clock_t tms_utime; /* User CPU time. */ - clock_t tms_stime; /* System CPU time. */ + clock_t tms_utime; /* User CPU time. */ + clock_t tms_stime; /* System CPU time. */ - clock_t tms_cutime; /* User CPU time of dead children. */ - clock_t tms_cstime; /* System CPU time of dead children. */ + clock_t tms_cutime; /* User CPU time of dead children. */ + clock_t tms_cstime; /* System CPU time of dead children. */ }; # if @GNULIB_TIMES@ extern clock_t times (struct tms *buffer); # elif defined GNULIB_POSIXCHECK # undef times -# define times(s) \ - (GL_LINK_WARNING ("times is unportable - " \ - "use gnulib module times for portability"), \ +# define times(s) \ + (GL_LINK_WARNING ("times is unportable - " \ + "use gnulib module times for portability"), \ times (s)) # endif @@ -56,4 +56,4 @@ extern "C" { } # endif -#endif /* _GL_SYS_TIMES_H */ +#endif /* _GL_SYS_TIMES_H */ diff --git a/lib/tanl.c b/lib/tanl.c index 60e663761..51262f0d8 100644 --- a/lib/tanl.c +++ b/lib/tanl.c @@ -23,21 +23,21 @@ * Return tangent function of x. * * kernel function: - * __kernel_tanl ... tangent function on [-pi/4,pi/4] - * __ieee754_rem_pio2l ... argument reduction routine + * __kernel_tanl ... tangent function on [-pi/4,pi/4] + * __ieee754_rem_pio2l ... argument reduction routine * * Method. * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 + * in [-pi/4 , +pi/4], and let n = k mod 4. + * We have * * n sin(x) cos(x) tan(x) * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T + * 0 S C T + * 1 C -S -1/T + * 2 -S -C T + * 3 -C S -1/T * ---------------------------------------------------------- * * Special cases: @@ -46,7 +46,7 @@ * trig(NaN) is that NaN; * * Accuracy: - * TRIG(x) returns trig(x) nearly rounded + * TRIG(x) returns trig(x) nearly rounded */ #include "trigl.h" @@ -80,21 +80,21 @@ * -1/tan (if k= -1) is returned. * * Algorithm - * 1. Since tan(-x) = -tan(x), we need only to consider positive x. - * 2. if x < 2^-57, return x with inexact if x!=0. - * 3. tan(x) is approximated by a rational form x + x^3 / 3 + x^5 R(x^2) + * 1. Since tan(-x) = -tan(x), we need only to consider positive x. + * 2. if x < 2^-57, return x with inexact if x!=0. + * 3. tan(x) is approximated by a rational form x + x^3 / 3 + x^5 R(x^2) * on [0,0.67433]. * - * Note: tan(x+y) = tan(x) + tan'(x)*y - * ~ tan(x) + (1+x*x)*y - * Therefore, for better accuracy in computing tan(x+y), let - * r = x^3 * R(x^2) - * then - * tan(x+y) = x + (x^3 / 3 + (x^2 *(r+y)+y)) + * Note: tan(x+y) = tan(x) + tan'(x)*y + * ~ tan(x) + (1+x*x)*y + * Therefore, for better accuracy in computing tan(x+y), let + * r = x^3 * R(x^2) + * then + * tan(x+y) = x + (x^3 / 3 + (x^2 *(r+y)+y)) * * 4. For x in [0.67433,pi/4], let y = pi/4 - x, then - * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) - * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) + * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) + * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) */ @@ -137,12 +137,12 @@ kernel_tanl (long double x, long double y, int iy) if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* x < 2**-57 */ { if ((int) x == 0) - { /* generate inexact */ - if (iy == -1 && x == 0.0) - return 1.0L / fabs (x); - else - return (iy == 1) ? x : -1.0L / x; - } + { /* generate inexact */ + if (iy == -1 && x == 0.0) + return 1.0L / fabs (x); + else + return (iy == 1) ? x : -1.0L / x; + } } if (x >= 0.6743316650390625) /* |x| >= 0.6743316650390625 */ { @@ -167,14 +167,14 @@ kernel_tanl (long double x, long double y, int iy) v = (long double) iy; w = (v - 2.0 * (x - (w * w / (w + v) - r))); if (sign < 0) - w = -w; + w = -w; return w; } if (iy == 1) return w; else - { /* if allow error up to 2 ulp, - simply return -1.0/(x+r) here */ + { /* if allow error up to 2 ulp, + simply return -1.0/(x+r) here */ /* compute -1.0/(x+r) accurately */ u1 = (double) w; v = r - (u1 - x); @@ -202,7 +202,7 @@ tanl (long double x) /* tanl(Inf) is NaN, tanl(0) is 0 */ else if (x + x == x) - return x - x; /* NaN */ + return x - x; /* NaN */ /* argument reduction needed */ else diff --git a/lib/tempname.c b/lib/tempname.c index 2da5afeec..d8cc14128 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -40,9 +40,9 @@ # define TMP_MAX 238328 #endif #ifndef __GT_FILE -# define __GT_FILE 0 -# define __GT_DIR 1 -# define __GT_NOCREATE 2 +# 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) @@ -82,17 +82,17 @@ # include # 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; \ - } \ + 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 @@ -123,7 +123,7 @@ direxists (const char *dir) enough space in TMPL. */ int __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, - int try_tmpdir) + int try_tmpdir) { const char *d; size_t dlen, plen; @@ -137,35 +137,35 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, { plen = strlen (pfx); if (plen > 5) - plen = 5; + plen = 5; } if (try_tmpdir) { d = __secure_getenv ("TMPDIR"); if (d != NULL && direxists (d)) - dir = d; + dir = d; else if (dir != NULL && direxists (dir)) - /* nothing */ ; + /* nothing */ ; else - dir = NULL; + dir = NULL; } if (dir == NULL) { if (direxists (P_tmpdir)) - dir = P_tmpdir; + dir = P_tmpdir; else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp")) - dir = "/tmp"; + dir = "/tmp"; else - { - __set_errno (ENOENT); - return -1; - } + { + __set_errno (ENOENT); + return -1; + } } dlen = strlen (dir); while (dlen > 1 && dir[dlen - 1] == '/') - dlen--; /* remove trailing slashes */ + dlen--; /* remove trailing slashes */ /* check we have room for "${dir}/${pfx}XXXXXX\0" */ if (tmpl_len < dlen + 1 + plen + 6 + 1) @@ -189,11 +189,11 @@ static const char letters[] = __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. + __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 @@ -264,47 +264,47 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind) 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 (); - } + { + 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; - } + { + __set_errno (save_errno); + return fd; + } else if (errno != EEXIST) - return -1; + return -1; } /* We got out of the loop because we ran out of combinations to try. */ diff --git a/lib/tempname.h b/lib/tempname.h index cd69e7d75..5ed1834cd 100644 --- a/lib/tempname.h +++ b/lib/tempname.h @@ -38,11 +38,11 @@ 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. + 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); diff --git a/lib/time.in.h b/lib/time.in.h index e8e7c197f..4f44bb08a 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -84,9 +84,9 @@ extern time_t mktime (struct tm *__tp); # undef gmtime_r # define gmtime_r rpl_gmtime_r struct tm *localtime_r (time_t const *restrict __timer, - struct tm *restrict __result); + struct tm *restrict __result); struct tm *gmtime_r (time_t const *restrict __timer, - struct tm *restrict __result); + struct tm *restrict __result); # endif /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store @@ -96,7 +96,7 @@ struct tm *gmtime_r (time_t const *restrict __timer, # undef strptime # define strptime rpl_strptime char *strptime (char const *restrict __buf, char const *restrict __format, - struct tm *restrict __tm); + struct tm *restrict __tm); # endif /* Convert TM to a time_t value, assuming UTC. */ diff --git a/lib/times.c b/lib/times.c index f71889a43..fc8c0dfa2 100644 --- a/lib/times.c +++ b/lib/times.c @@ -55,7 +55,7 @@ times (struct tms * buffer) FILETIME creation_time, exit_time, kernel_time, user_time; if (GetProcessTimes (GetCurrentProcess (), &creation_time, &exit_time, - &kernel_time, &user_time) == 0) + &kernel_time, &user_time) == 0) return (clock_t) -1; buffer->tms_utime = filetime2clock (user_time); diff --git a/lib/timespec.h b/lib/timespec.h index db3453a24..3e4c3fc9a 100644 --- a/lib/timespec.h +++ b/lib/timespec.h @@ -26,10 +26,10 @@ static inline int timespec_cmp (struct timespec a, struct timespec b) { return (a.tv_sec < b.tv_sec ? -1 - : a.tv_sec > b.tv_sec ? 1 - : a.tv_nsec < b.tv_nsec ? -1 - : a.tv_nsec > b.tv_nsec ? 1 - : 0); + : a.tv_sec > b.tv_sec ? 1 + : a.tv_nsec < b.tv_nsec ? -1 + : a.tv_nsec > b.tv_nsec ? 1 + : 0); } void gettime (struct timespec *); diff --git a/lib/tmpdir.c b/lib/tmpdir.c index f5982ed55..c82952739 100644 --- a/lib/tmpdir.c +++ b/lib/tmpdir.c @@ -76,7 +76,7 @@ direxists (const char *dir) enough space in TMPL. */ int path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, - bool try_tmpdir) + bool try_tmpdir) { const char *d; size_t dlen, plen; @@ -90,35 +90,35 @@ path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, { plen = strlen (pfx); if (plen > 5) - plen = 5; + plen = 5; } if (try_tmpdir) { d = __secure_getenv ("TMPDIR"); if (d != NULL && direxists (d)) - dir = d; + dir = d; else if (dir != NULL && direxists (dir)) - /* nothing */ ; + /* nothing */ ; else - dir = NULL; + dir = NULL; } if (dir == NULL) { if (direxists (P_tmpdir)) - dir = P_tmpdir; + dir = P_tmpdir; else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp")) - dir = "/tmp"; + dir = "/tmp"; else - { - __set_errno (ENOENT); - return -1; - } + { + __set_errno (ENOENT); + return -1; + } } dlen = strlen (dir); while (dlen >= 1 && ISSLASH (dir[dlen - 1])) - dlen--; /* remove trailing slashes */ + dlen--; /* remove trailing slashes */ /* check we have room for "${dir}/${pfx}XXXXXX\0" */ if (tmpl_len < dlen + 1 + plen + 6 + 1) diff --git a/lib/tmpfile-safer.c b/lib/tmpfile-safer.c index e8d05aec3..6c9a4183d 100644 --- a/lib/tmpfile-safer.c +++ b/lib/tmpfile-safer.c @@ -41,28 +41,28 @@ tmpfile_safer (void) 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; - } - - /* Keep the temporary file in binary mode, on platforms - where that matters. */ - if (fclose (fp) != 0 - || ! (fp = fdopen (f, O_BINARY ? "wb+" : "w+"))) - { - int e = errno; - close (f); - errno = e; - return NULL; - } - } + { + int f = dup_safer (fd); + + if (f < 0) + { + int e = errno; + fclose (fp); + errno = e; + return NULL; + } + + /* Keep the temporary file in binary mode, on platforms + where that matters. */ + if (fclose (fp) != 0 + || ! (fp = fdopen (f, O_BINARY ? "wb+" : "w+"))) + { + int e = errno; + close (f); + errno = e; + return NULL; + } + } } return fp; diff --git a/lib/tmpfile.c b/lib/tmpfile.c index 83df9fe29..2a5bbc6a5 100644 --- a/lib/tmpfile.c +++ b/lib/tmpfile.c @@ -52,9 +52,9 @@ supports_delete_on_close () OSVERSIONINFO v; if (GetVersionEx (&v)) - known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1); + known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1); else - known = -1; + known = -1; } return (known > 0); } @@ -75,49 +75,49 @@ tmpfile (void) char xtemplate[PATH_MAX]; if (path_search (xtemplate, PATH_MAX, dir, NULL, true) >= 0) - { - size_t len = strlen (xtemplate); - int o_temporary = (supports_delete_on_close () ? _O_TEMPORARY : 0); - int fd; - - do - { - memcpy (&xtemplate[len - 6], "XXXXXX", 6); - if (gen_tempname (xtemplate, 0, 0, GT_NOCREATE) < 0) - { - fd = -1; - break; - } - - fd = _open (xtemplate, - _O_CREAT | _O_EXCL | o_temporary - | _O_RDWR | _O_BINARY, - _S_IREAD | _S_IWRITE); - } - while (fd < 0 && errno == EEXIST); - - if (fd >= 0) - { - FILE *fp = _fdopen (fd, "w+b"); - - if (fp != NULL) - return fp; - else - { - int saved_errno = errno; - _close (fd); - errno = saved_errno; - } - } - } + { + size_t len = strlen (xtemplate); + int o_temporary = (supports_delete_on_close () ? _O_TEMPORARY : 0); + int fd; + + do + { + memcpy (&xtemplate[len - 6], "XXXXXX", 6); + if (gen_tempname (xtemplate, 0, 0, GT_NOCREATE) < 0) + { + fd = -1; + break; + } + + fd = _open (xtemplate, + _O_CREAT | _O_EXCL | o_temporary + | _O_RDWR | _O_BINARY, + _S_IREAD | _S_IWRITE); + } + while (fd < 0 && errno == EEXIST); + + if (fd >= 0) + { + FILE *fp = _fdopen (fd, "w+b"); + + if (fp != NULL) + return fp; + else + { + int saved_errno = errno; + _close (fd); + errno = saved_errno; + } + } + } } else { if (retval > 0) - errno = ENAMETOOLONG; + errno = ENAMETOOLONG; else - /* Ideally this should translate GetLastError () to an errno value. */ - errno = ENOENT; + /* Ideally this should translate GetLastError () to an errno value. */ + errno = ENOENT; } return NULL; diff --git a/lib/trigl.c b/lib/trigl.c index 6f9dcf526..a608d91c6 100644 --- a/lib/trigl.c +++ b/lib/trigl.c @@ -187,15 +187,15 @@ static const int two_over_pi[] = { static const long double c[] = { /* 93 bits of pi/2 */ #define PI_2_1 c[0] - 1.57079632679489661923132169155131424e+00L, /* 3fff921fb54442d18469898cc5100000 */ + 1.57079632679489661923132169155131424e+00L, /* 3fff921fb54442d18469898cc5100000 */ /* pi/2 - PI_2_1 */ #define PI_2_1t c[1] - 8.84372056613570112025531863263659260e-29L, /* 3fa1c06e0e68948127044533e63a0106 */ + 8.84372056613570112025531863263659260e-29L, /* 3fa1c06e0e68948127044533e63a0106 */ }; static int kernel_rem_pio2 (double *x, double *y, int e0, int nx, int prec, - const int *ipio2); + const int *ipio2); int ieee754_rem_pio2l (long double x, long double *y) @@ -215,23 +215,23 @@ ieee754_rem_pio2l (long double x, long double *y) if (x > 0 && x < 2.35619449019234492884698253745962716314787704953131) { - /* 113 + 93 bit PI is ok */ - z = x - PI_2_1; - y[0] = z - PI_2_1t; - y[1] = (z - y[0]) - PI_2_1t; - return 1; + /* 113 + 93 bit PI is ok */ + z = x - PI_2_1; + y[0] = z - PI_2_1t; + y[1] = (z - y[0]) - PI_2_1t; + return 1; } if (x < 0 && x > -2.35619449019234492884698253745962716314787704953131) { - /* 113 + 93 bit PI is ok */ - z = x + PI_2_1; - y[0] = z + PI_2_1t; - y[1] = (z - y[0]) + PI_2_1t; - return -1; + /* 113 + 93 bit PI is ok */ + z = x + PI_2_1; + y[0] = z + PI_2_1t; + y[1] = (z - y[0]) + PI_2_1t; + return -1; } - if (x + x == x) /* x is ±oo */ + if (x + x == x) /* x is ±oo */ { y[0] = x - x; y[1] = y[0]; @@ -295,7 +295,7 @@ static char rcsid[] = * double x[],y[]; int e0,nx,prec; int ipio2[]; * * kernel_rem_pio2 return the last three digits of N with - * y = x - N*pi/2 + * y = x - N*pi/2 * so that |y| < pi/2. * * The method is to compute the integer (mod 8) and fraction parts of @@ -307,93 +307,93 @@ static char rcsid[] = * (2/pi) is represented by an array of 24-bit integers in ipio2[]. * * Input parameters: - * x[] The input value (must be positive) is broken into nx - * pieces of 24-bit integers in double precision format. - * x[i] will be the i-th 24 bit of x. The scaled exponent - * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 - * match x's up to 24 bits. + * x[] The input value (must be positive) is broken into nx + * pieces of 24-bit integers in double precision format. + * x[i] will be the i-th 24 bit of x. The scaled exponent + * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 + * match x's up to 24 bits. * - * Example of breaking a double positive z into x[0]+x[1]+x[2]: - * e0 = ilogb(z)-23 - * z = scalbn(z,-e0) - * for i = 0,1,2 - * x[i] = floor(z) - * z = (z-x[i])*2**24 + * Example of breaking a double positive z into x[0]+x[1]+x[2]: + * e0 = ilogb(z)-23 + * z = scalbn(z,-e0) + * for i = 0,1,2 + * x[i] = floor(z) + * z = (z-x[i])*2**24 * * - * y[] ouput result in an array of double precision numbers. - * The dimension of y[] is: - * 24-bit precision 1 - * 53-bit precision 2 - * 64-bit precision 2 - * 113-bit precision 3 - * The actual value is the sum of them. Thus for 113-bit - * precision, one may have to do something like: + * y[] ouput result in an array of double precision numbers. + * The dimension of y[] is: + * 24-bit precision 1 + * 53-bit precision 2 + * 64-bit precision 2 + * 113-bit precision 3 + * The actual value is the sum of them. Thus for 113-bit + * precision, one may have to do something like: * - * long double t,w,r_head, r_tail; - * t = (long double)y[2] + (long double)y[1]; - * w = (long double)y[0]; - * r_head = t+w; - * r_tail = w - (r_head - t); + * long double t,w,r_head, r_tail; + * t = (long double)y[2] + (long double)y[1]; + * w = (long double)y[0]; + * r_head = t+w; + * r_tail = w - (r_head - t); * - * e0 The exponent of x[0] + * e0 The exponent of x[0] * - * nx dimension of x[] + * nx dimension of x[] * - * prec an integer indicating the precision: - * 0 24 bits (single) - * 1 53 bits (double) - * 2 64 bits (extended) - * 3 113 bits (quad) + * prec an integer indicating the precision: + * 0 24 bits (single) + * 1 53 bits (double) + * 2 64 bits (extended) + * 3 113 bits (quad) * - * ipio2[] - * integer array, contains the (24*i)-th to (24*i+23)-th - * bit of 2/pi after binary point. The corresponding - * floating value is + * ipio2[] + * integer array, contains the (24*i)-th to (24*i+23)-th + * bit of 2/pi after binary point. The corresponding + * floating value is * - * ipio2[i] * 2^(-24(i+1)). + * ipio2[i] * 2^(-24(i+1)). * * External function: - * double scalbn(), floor(); + * double scalbn(), floor(); * * * Here is the description of some local variables: * - * jk jk+1 is the initial number of terms of ipio2[] needed - * in the computation. The recommended value is 2,3,4, - * 6 for single, double, extended,and quad. + * jk jk+1 is the initial number of terms of ipio2[] needed + * in the computation. The recommended value is 2,3,4, + * 6 for single, double, extended,and quad. * - * jz local integer variable indicating the number of - * terms of ipio2[] used. + * jz local integer variable indicating the number of + * terms of ipio2[] used. * - * jx nx - 1 + * jx nx - 1 * - * jv index for pointing to the suitable ipio2[] for the - * computation. In general, we want - * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 - * is an integer. Thus - * e0-3-24*jv >= 0 or (e0-3)/24 >= jv - * Hence jv = max(0,(e0-3)/24). + * jv index for pointing to the suitable ipio2[] for the + * computation. In general, we want + * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 + * is an integer. Thus + * e0-3-24*jv >= 0 or (e0-3)/24 >= jv + * Hence jv = max(0,(e0-3)/24). * - * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. + * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. * - * q[] double array with integral value, representing the - * 24-bits chunk of the product of x and 2/pi. + * q[] double array with integral value, representing the + * 24-bits chunk of the product of x and 2/pi. * - * q0 the corresponding exponent of q[0]. Note that the - * exponent for q[i] would be q0-24*i. + * q0 the corresponding exponent of q[0]. Note that the + * exponent for q[i] would be q0-24*i. * - * PIo2[] double precision array, obtained by cutting pi/2 - * into 24 bits chunks. + * PIo2[] double precision array, obtained by cutting pi/2 + * into 24 bits chunks. * - * f[] ipio2[] in floating point + * f[] ipio2[] in floating point * - * iq[] integer array by breaking up q[] in 24-bits chunk. + * iq[] integer array by breaking up q[] in 24-bits chunk. * - * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] + * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] * - * ih integer. If >0 it indicates q[] is >= 0.5, hence - * it also indicates the *sign* of the result. + * ih integer. If >0 it indicates q[] is >= 0.5, hence + * it also indicates the *sign* of the result. * */ @@ -406,24 +406,24 @@ static char rcsid[] = * to produce the hexadecimal values shown. */ -static const int init_jk[] = { 2, 3, 4, 6 }; /* initial value for jk */ +static const int init_jk[] = { 2, 3, 4, 6 }; /* initial value for jk */ static const double PIo2[] = { - 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ - 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ - 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ - 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ - 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ - 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ - 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ - 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ + 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ + 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ + 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ + 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ + 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ + 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ + 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ + 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ }; -static const double zero = 0.0, one = 1.0, two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ - twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ +static const double zero = 0.0, one = 1.0, two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ + twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ static int kernel_rem_pio2 (double *x, double *y, int e0, int nx, int prec, - const int *ipio2) + const int *ipio2) { int jz, jx, jv, jp, jk, carry, n, iq[20], i, j, k, m, q0, ih; double z, fw, f[20], fq[20], q[20]; @@ -449,7 +449,7 @@ kernel_rem_pio2 (double *x, double *y, int e0, int nx, int prec, for (i = 0; i <= jk; i++) { for (j = 0, fw = 0.0; j <= jx; j++) - fw += x[j] * f[jx + i - j]; + fw += x[j] * f[jx + i - j]; q[i] = fw; } @@ -464,13 +464,13 @@ recompute: } /* compute n */ - z = ldexp (z, q0); /* actual value of z */ - z -= 8.0 * floor (z * 0.125); /* trim off integer >= 8 */ + z = ldexp (z, q0); /* actual value of z */ + z -= 8.0 * floor (z * 0.125); /* trim off integer >= 8 */ n = (int) z; z -= (double) n; ih = 0; if (q0 > 0) - { /* need iq[jz-1] to determine n */ + { /* need iq[jz-1] to determine n */ i = (iq[jz - 1] >> (24 - q0)); n += i; iq[jz - 1] -= i << (24 - q0); @@ -482,41 +482,41 @@ recompute: ih = 2; if (ih > 0) - { /* q > 0.5 */ + { /* q > 0.5 */ n += 1; carry = 0; for (i = 0; i < jz; i++) - { /* compute 1-q */ - j = iq[i]; - if (carry == 0) - { - if (j != 0) - { - carry = 1; - iq[i] = 0x1000000 - j; - } - } - else - iq[i] = 0xffffff - j; - } + { /* compute 1-q */ + j = iq[i]; + if (carry == 0) + { + if (j != 0) + { + carry = 1; + iq[i] = 0x1000000 - j; + } + } + else + iq[i] = 0xffffff - j; + } if (q0 > 0) - { /* rare case: chance is 1 in 12 */ - switch (q0) - { - case 1: - iq[jz - 1] &= 0x7fffff; - break; - case 2: - iq[jz - 1] &= 0x3fffff; - break; - } - } + { /* rare case: chance is 1 in 12 */ + switch (q0) + { + case 1: + iq[jz - 1] &= 0x7fffff; + break; + case 2: + iq[jz - 1] &= 0x3fffff; + break; + } + } if (ih == 2) - { - z = one - z; - if (carry != 0) - z -= ldexp (one, q0); - } + { + z = one - z; + if (carry != 0) + z -= ldexp (one, q0); + } } /* check if recomputation is needed */ @@ -524,21 +524,21 @@ recompute: { j = 0; for (i = jz - 1; i >= jk; i--) - j |= iq[i]; + j |= iq[i]; if (j == 0) - { /* need recomputation */ - for (k = 1; iq[jk - k] == 0; k++); /* k = no. of terms needed */ - - for (i = jz + 1; i <= jz + k; i++) - { /* add q[jz+1] to q[jz+k] */ - f[jx + i] = (double) ipio2[jv + i]; - for (j = 0, fw = 0.0; j <= jx; j++) - fw += x[j] * f[jx + i - j]; - q[i] = fw; - } - jz += k; - goto recompute; - } + { /* need recomputation */ + for (k = 1; iq[jk - k] == 0; k++); /* k = no. of terms needed */ + + for (i = jz + 1; i <= jz + k; i++) + { /* add q[jz+1] to q[jz+k] */ + f[jx + i] = (double) ipio2[jv + i]; + for (j = 0, fw = 0.0; j <= jx; j++) + fw += x[j] * f[jx + i - j]; + q[i] = fw; + } + jz += k; + goto recompute; + } } /* chop off zero terms */ @@ -547,24 +547,24 @@ recompute: jz -= 1; q0 -= 24; while (iq[jz] == 0) - { - jz--; - q0 -= 24; - } + { + jz--; + q0 -= 24; + } } else - { /* break z into 24-bit if necessary */ + { /* break z into 24-bit if necessary */ z = ldexp (z, -q0); if (z >= two24) - { - fw = (double) ((int) (twon24 * z)); - iq[jz] = (int) (z - two24 * fw); - jz += 1; - q0 += 24; - iq[jz] = (int) fw; - } + { + fw = (double) ((int) (twon24 * z)); + iq[jz] = (int) (z - two24 * fw); + jz += 1; + q0 += 24; + iq[jz] = (int) fw; + } else - iq[jz] = (int) z; + iq[jz] = (int) z; } /* convert integer "bit" chunk to floating-point value */ @@ -579,7 +579,7 @@ recompute: for (i = jz; i >= 0; i--) { for (fw = 0.0, k = 0; k <= jp && k <= jz - i; k++) - fw += PIo2[k] * q[i + k]; + fw += PIo2[k] * q[i + k]; fq[jz - i] = fw; } @@ -589,47 +589,47 @@ recompute: case 0: fw = 0.0; for (i = jz; i >= 0; i--) - fw += fq[i]; + fw += fq[i]; y[0] = (ih == 0) ? fw : -fw; break; case 1: case 2: fw = 0.0; for (i = jz; i >= 0; i--) - fw += fq[i]; + fw += fq[i]; y[0] = (ih == 0) ? fw : -fw; fw = fq[0] - fw; for (i = 1; i <= jz; i++) - fw += fq[i]; + fw += fq[i]; y[1] = (ih == 0) ? fw : -fw; break; - case 3: /* painful */ + case 3: /* painful */ for (i = jz; i > 0; i--) - { - fw = fq[i - 1] + fq[i]; - fq[i] += fq[i - 1] - fw; - fq[i - 1] = fw; - } + { + fw = fq[i - 1] + fq[i]; + fq[i] += fq[i - 1] - fw; + fq[i - 1] = fw; + } for (i = jz; i > 1; i--) - { - fw = fq[i - 1] + fq[i]; - fq[i] += fq[i - 1] - fw; - fq[i - 1] = fw; - } + { + fw = fq[i - 1] + fq[i]; + fq[i] += fq[i - 1] - fw; + fq[i - 1] = fw; + } for (fw = 0.0, i = jz; i >= 2; i--) - fw += fq[i]; + fw += fq[i]; if (ih == 0) - { - y[0] = fq[0]; - y[1] = fq[1]; - y[2] = fw; - } + { + y[0] = fq[0]; + y[1] = fq[1]; + y[2] = fw; + } else - { - y[0] = -fq[0]; - y[1] = -fq[1]; - y[2] = -fw; - } + { + y[0] = -fq[0]; + y[1] = -fq[1]; + y[2] = -fw; + } } return n & 7; } diff --git a/lib/trim.c b/lib/trim.c index 452d8bc74..6824200fa 100644 --- a/lib/trim.c +++ b/lib/trim.c @@ -53,61 +53,61 @@ trim2(const char *s, int how) /* Trim leading whitespaces. */ if (how != TRIM_TRAILING) - { - mbi_init (i, d, strlen (d)); + { + mbi_init (i, d, strlen (d)); - for (; mbi_avail (i) && mb_isspace (mbi_cur (i)); mbi_advance (i)) - ; + for (; mbi_avail (i) && mb_isspace (mbi_cur (i)); mbi_advance (i)) + ; - memmove (d, mbi_cur_ptr (i), strlen (mbi_cur_ptr (i)) + 1); - } + memmove (d, mbi_cur_ptr (i), strlen (mbi_cur_ptr (i)) + 1); + } /* Trim trailing whitespaces. */ if (how != TRIM_LEADING) - { - int state = 0; - char *r IF_LINT (= NULL); /* used only while state = 2 */ - - mbi_init (i, d, strlen (d)); - - for (; mbi_avail (i); mbi_advance (i)) - { - if (state == 0 && mb_isspace (mbi_cur (i))) - { - state = 0; - continue; - } - - if (state == 0 && !mb_isspace (mbi_cur (i))) - { - state = 1; - continue; - } - - if (state == 1 && !mb_isspace (mbi_cur (i))) - { - state = 1; - continue; - } - - if (state == 1 && mb_isspace (mbi_cur (i))) - { - state = 2; - r = (char *) mbi_cur_ptr (i); - } - else if (state == 2 && mb_isspace (mbi_cur (i))) - { - state = 2; - } - else - { - state = 1; - } - } - - if (state == 2) - *r = '\0'; - } + { + int state = 0; + char *r IF_LINT (= NULL); /* used only while state = 2 */ + + mbi_init (i, d, strlen (d)); + + for (; mbi_avail (i); mbi_advance (i)) + { + if (state == 0 && mb_isspace (mbi_cur (i))) + { + state = 0; + continue; + } + + if (state == 0 && !mb_isspace (mbi_cur (i))) + { + state = 1; + continue; + } + + if (state == 1 && !mb_isspace (mbi_cur (i))) + { + state = 1; + continue; + } + + if (state == 1 && mb_isspace (mbi_cur (i))) + { + state = 2; + r = (char *) mbi_cur_ptr (i); + } + else if (state == 2 && mb_isspace (mbi_cur (i))) + { + state = 2; + } + else + { + state = 1; + } + } + + if (state == 2) + *r = '\0'; + } } else { @@ -115,16 +115,16 @@ trim2(const char *s, int how) /* Trim leading whitespaces. */ if (how != TRIM_TRAILING) { - for (p = d; *p && isspace ((unsigned char) *p); p++) - ; + for (p = d; *p && isspace ((unsigned char) *p); p++) + ; - memmove (d, p, strlen (p) + 1); + memmove (d, p, strlen (p) + 1); } /* Trim trailing whitespaces. */ if (how != TRIM_LEADING) { - for (p = d + strlen (d) - 1; p >= d && isspace ((unsigned char) *p); p--) - *p = '\0'; + for (p = d + strlen (d) - 1; p >= d && isspace ((unsigned char) *p); p--) + *p = '\0'; } } diff --git a/lib/trunc.c b/lib/trunc.c index e8d3d87dc..a10184e35 100644 --- a/lib/trunc.c +++ b/lib/trunc.c @@ -67,27 +67,27 @@ FUNC (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; } diff --git a/lib/tsearch.c b/lib/tsearch.c index 45cce058a..a2e053aa5 100644 --- a/lib/tsearch.c +++ b/lib/tsearch.c @@ -177,7 +177,7 @@ check_tree (node root) edges between GPARENTP and ROOTP. */ static void maybe_split_for_insert (node *rootp, node *parentp, node *gparentp, - int p_r, int gp_r, int mode) + int p_r, int gp_r, int mode) { node root = *rootp; node *rp, *lp; @@ -191,67 +191,67 @@ maybe_split_for_insert (node *rootp, node *parentp, node *gparentp, /* This node becomes red, its successors black. */ root->red = 1; if (*rp) - (*rp)->red = 0; + (*rp)->red = 0; if (*lp) - (*lp)->red = 0; + (*lp)->red = 0; /* If the parent of this node is also red, we have to do - rotations. */ + rotations. */ if (parentp != NULL && (*parentp)->red) - { - node gp = *gparentp; - node p = *parentp; - /* There are two main cases: - 1. The edge types (left or right) of the two red edges differ. - 2. Both red edges are of the same type. - There exist two symmetries of each case, so there is a total of - 4 cases. */ - if ((p_r > 0) != (gp_r > 0)) - { - /* Put the child at the top of the tree, with its parent - and grandparent as successors. */ - p->red = 1; - gp->red = 1; - root->red = 0; - if (p_r < 0) - { - /* Child is left of parent. */ - p->left = *rp; - *rp = p; - gp->right = *lp; - *lp = gp; - } - else - { - /* Child is right of parent. */ - p->right = *lp; - *lp = p; - gp->left = *rp; - *rp = gp; - } - *gparentp = root; - } - else - { - *gparentp = *parentp; - /* Parent becomes the top of the tree, grandparent and - child are its successors. */ - p->red = 0; - gp->red = 1; - if (p_r < 0) - { - /* Left edges. */ - gp->left = p->right; - p->right = gp; - } - else - { - /* Right edges. */ - gp->right = p->left; - p->left = gp; - } - } - } + { + node gp = *gparentp; + node p = *parentp; + /* There are two main cases: + 1. The edge types (left or right) of the two red edges differ. + 2. Both red edges are of the same type. + There exist two symmetries of each case, so there is a total of + 4 cases. */ + if ((p_r > 0) != (gp_r > 0)) + { + /* Put the child at the top of the tree, with its parent + and grandparent as successors. */ + p->red = 1; + gp->red = 1; + root->red = 0; + if (p_r < 0) + { + /* Child is left of parent. */ + p->left = *rp; + *rp = p; + gp->right = *lp; + *lp = gp; + } + else + { + /* Child is right of parent. */ + p->right = *lp; + *lp = p; + gp->left = *rp; + *rp = gp; + } + *gparentp = root; + } + else + { + *gparentp = *parentp; + /* Parent becomes the top of the tree, grandparent and + child are its successors. */ + p->red = 0; + gp->red = 1; + if (p_r < 0) + { + /* Left edges. */ + gp->left = p->right; + p->right = gp; + } + else + { + /* Right edges. */ + gp->right = p->left; + p->left = gp; + } + } + } } } @@ -282,16 +282,16 @@ __tsearch (const void *key, void **vrootp, __compar_fn_t compar) node root = *rootp; r = (*compar) (key, root->key); if (r == 0) - return root; + return root; maybe_split_for_insert (rootp, parentp, gparentp, p_r, gp_r, 0); /* If that did any rotations, parentp and gparentp are now garbage. - That doesn't matter, because the values they contain are never - used again in that case. */ + That doesn't matter, because the values they contain are never + used again in that case. */ nextp = r < 0 ? &root->left : &root->right; if (*nextp == NULL) - break; + break; gparentp = parentp; parentp = rootp; @@ -304,15 +304,15 @@ __tsearch (const void *key, void **vrootp, __compar_fn_t compar) q = (struct node_t *) malloc (sizeof (struct node_t)); if (q != NULL) { - *nextp = q; /* link new node to old */ - q->key = key; /* initialize new node */ + *nextp = q; /* link new node to old */ + q->key = key; /* initialize new node */ q->red = 1; q->left = q->right = NULL; if (nextp != rootp) - /* There may be two red edges in a row now, which we must avoid by - rotating the tree. */ - maybe_split_for_insert (nextp, rootp, parentp, r, p_r, 1); + /* There may be two red edges in a row now, which we must avoid by + rotating the tree. */ + maybe_split_for_insert (nextp, rootp, parentp, r, p_r, 1); } return q; @@ -345,7 +345,7 @@ __tfind (key, vrootp, compar) r = (*compar) (key, root->key); if (r == 0) - return root; + return root; rootp = r < 0 ? &root->left : &root->right; } @@ -384,15 +384,15 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) while ((cmp = (*compar) (key, (*rootp)->key)) != 0) { if (sp == stacksize) - abort (); + abort (); nodestack[sp++] = rootp; p = *rootp; rootp = ((cmp < 0) - ? &(*rootp)->left - : &(*rootp)->right); + ? &(*rootp)->left + : &(*rootp)->right); if (*rootp == NULL) - return NULL; + return NULL; } /* This is bogus if the node to be deleted is the root... this routine @@ -415,15 +415,15 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) { node *parent = rootp, *up = &root->right; for (;;) - { - if (sp == stacksize) - abort (); - nodestack[sp++] = parent; - parent = up; - if ((*up)->left == NULL) - break; - up = &(*up)->left; - } + { + if (sp == stacksize) + abort (); + nodestack[sp++] = parent; + parent = up; + if ((*up)->left == NULL) + break; + up = &(*up)->left; + } unchained = *up; } @@ -438,9 +438,9 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) { q = *nodestack[sp-1]; if (unchained == q->right) - q->right = r; + q->right = r; else - q->left = r; + q->left = r; } if (unchained != root) @@ -448,156 +448,156 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) if (!unchained->red) { /* Now we lost a black edge, which means that the number of black - edges on every path is no longer constant. We must balance the - tree. */ + edges on every path is no longer constant. We must balance the + tree. */ /* NODESTACK now contains all parents of R. R is likely to be NULL - in the first iteration. */ + in the first iteration. */ /* NULL nodes are considered black throughout - this is necessary for - correctness. */ + correctness. */ while (sp > 0 && (r == NULL || !r->red)) - { - node *pp = nodestack[sp - 1]; - p = *pp; - /* Two symmetric cases. */ - if (r == p->left) - { - /* Q is R's brother, P is R's parent. The subtree with root - R has one black edge less than the subtree with root Q. */ - q = p->right; - if (q->red) - { - /* If Q is red, we know that P is black. We rotate P left - so that Q becomes the top node in the tree, with P below - it. P is colored red, Q is colored black. - This action does not change the black edge count for any - leaf in the tree, but we will be able to recognize one - of the following situations, which all require that Q - is black. */ - q->red = 0; - p->red = 1; - /* Left rotate p. */ - p->right = q->left; - q->left = p; - *pp = q; - /* Make sure pp is right if the case below tries to use - it. */ - nodestack[sp++] = pp = &q->left; - q = p->right; - } - /* We know that Q can't be NULL here. We also know that Q is - black. */ - if ((q->left == NULL || !q->left->red) - && (q->right == NULL || !q->right->red)) - { - /* Q has two black successors. We can simply color Q red. - The whole subtree with root P is now missing one black - edge. Note that this action can temporarily make the - tree invalid (if P is red). But we will exit the loop - in that case and set P black, which both makes the tree - valid and also makes the black edge count come out - right. If P is black, we are at least one step closer - to the root and we'll try again the next iteration. */ - q->red = 1; - r = p; - } - else - { - /* Q is black, one of Q's successors is red. We can - repair the tree with one operation and will exit the - loop afterwards. */ - if (q->right == NULL || !q->right->red) - { - /* The left one is red. We perform the same action as - in maybe_split_for_insert where two red edges are - adjacent but point in different directions: - Q's left successor (let's call it Q2) becomes the - top of the subtree we are looking at, its parent (Q) - and grandparent (P) become its successors. The former - successors of Q2 are placed below P and Q. - P becomes black, and Q2 gets the color that P had. - This changes the black edge count only for node R and - its successors. */ - node q2 = q->left; - q2->red = p->red; - p->right = q2->left; - q->left = q2->right; - q2->right = q; - q2->left = p; - *pp = q2; - p->red = 0; - } - else - { - /* It's the right one. Rotate P left. P becomes black, - and Q gets the color that P had. Q's right successor - also becomes black. This changes the black edge - count only for node R and its successors. */ - q->red = p->red; - p->red = 0; - - q->right->red = 0; - - /* left rotate p */ - p->right = q->left; - q->left = p; - *pp = q; - } - - /* We're done. */ - sp = 1; - r = NULL; - } - } - else - { - /* Comments: see above. */ - q = p->left; - if (q->red) - { - q->red = 0; - p->red = 1; - p->left = q->right; - q->right = p; - *pp = q; - nodestack[sp++] = pp = &q->right; - q = p->left; - } - if ((q->right == NULL || !q->right->red) - && (q->left == NULL || !q->left->red)) - { - q->red = 1; - r = p; - } - else - { - if (q->left == NULL || !q->left->red) - { - node q2 = q->right; - q2->red = p->red; - p->left = q2->right; - q->right = q2->left; - q2->left = q; - q2->right = p; - *pp = q2; - p->red = 0; - } - else - { - q->red = p->red; - p->red = 0; - q->left->red = 0; - p->left = q->right; - q->right = p; - *pp = q; - } - sp = 1; - r = NULL; - } - } - --sp; - } + { + node *pp = nodestack[sp - 1]; + p = *pp; + /* Two symmetric cases. */ + if (r == p->left) + { + /* Q is R's brother, P is R's parent. The subtree with root + R has one black edge less than the subtree with root Q. */ + q = p->right; + if (q->red) + { + /* If Q is red, we know that P is black. We rotate P left + so that Q becomes the top node in the tree, with P below + it. P is colored red, Q is colored black. + This action does not change the black edge count for any + leaf in the tree, but we will be able to recognize one + of the following situations, which all require that Q + is black. */ + q->red = 0; + p->red = 1; + /* Left rotate p. */ + p->right = q->left; + q->left = p; + *pp = q; + /* Make sure pp is right if the case below tries to use + it. */ + nodestack[sp++] = pp = &q->left; + q = p->right; + } + /* We know that Q can't be NULL here. We also know that Q is + black. */ + if ((q->left == NULL || !q->left->red) + && (q->right == NULL || !q->right->red)) + { + /* Q has two black successors. We can simply color Q red. + The whole subtree with root P is now missing one black + edge. Note that this action can temporarily make the + tree invalid (if P is red). But we will exit the loop + in that case and set P black, which both makes the tree + valid and also makes the black edge count come out + right. If P is black, we are at least one step closer + to the root and we'll try again the next iteration. */ + q->red = 1; + r = p; + } + else + { + /* Q is black, one of Q's successors is red. We can + repair the tree with one operation and will exit the + loop afterwards. */ + if (q->right == NULL || !q->right->red) + { + /* The left one is red. We perform the same action as + in maybe_split_for_insert where two red edges are + adjacent but point in different directions: + Q's left successor (let's call it Q2) becomes the + top of the subtree we are looking at, its parent (Q) + and grandparent (P) become its successors. The former + successors of Q2 are placed below P and Q. + P becomes black, and Q2 gets the color that P had. + This changes the black edge count only for node R and + its successors. */ + node q2 = q->left; + q2->red = p->red; + p->right = q2->left; + q->left = q2->right; + q2->right = q; + q2->left = p; + *pp = q2; + p->red = 0; + } + else + { + /* It's the right one. Rotate P left. P becomes black, + and Q gets the color that P had. Q's right successor + also becomes black. This changes the black edge + count only for node R and its successors. */ + q->red = p->red; + p->red = 0; + + q->right->red = 0; + + /* left rotate p */ + p->right = q->left; + q->left = p; + *pp = q; + } + + /* We're done. */ + sp = 1; + r = NULL; + } + } + else + { + /* Comments: see above. */ + q = p->left; + if (q->red) + { + q->red = 0; + p->red = 1; + p->left = q->right; + q->right = p; + *pp = q; + nodestack[sp++] = pp = &q->right; + q = p->left; + } + if ((q->right == NULL || !q->right->red) + && (q->left == NULL || !q->left->red)) + { + q->red = 1; + r = p; + } + else + { + if (q->left == NULL || !q->left->red) + { + node q2 = q->right; + q2->red = p->red; + p->left = q2->right; + q->right = q2->left; + q2->left = q; + q2->right = p; + *pp = q2; + p->red = 0; + } + else + { + q->red = p->red; + p->red = 0; + q->left->red = 0; + p->left = q->right; + q->right = p; + *pp = q; + } + sp = 1; + r = NULL; + } + } + --sp; + } if (r != NULL) - r->red = 0; + r->red = 0; } free (unchained); @@ -623,10 +623,10 @@ trecurse (const void *vroot, __action_fn_t action, int level) { (*action) (root, preorder, level); if (root->left != NULL) - trecurse (root->left, action, level + 1); + trecurse (root->left, action, level + 1); (*action) (root, postorder, level); if (root->right != NULL) - trecurse (root->right, action, level + 1); + trecurse (root->right, action, level + 1); (*action) (root, endorder, level); } } diff --git a/lib/uname.c b/lib/uname.c index 4e79ba1b4..bb2fd12c4 100644 --- a/lib/uname.c +++ b/lib/uname.c @@ -67,7 +67,7 @@ uname (struct utsname *buf) { version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (!GetVersionEx (&version)) - abort (); + abort (); } /* Fill in nodename. */ @@ -89,20 +89,20 @@ uname (struct utsname *buf) { /* Windows 95/98/ME. */ switch (version.dwMinorVersion) - { - case 0: - super_version = "95"; - break; - case 10: - super_version = "98"; - break; - case 90: - super_version = "ME"; - break; - default: - super_version = ""; - break; - } + { + case 0: + super_version = "95"; + break; + case 10: + super_version = "98"; + break; + case 90: + super_version = "ME"; + break; + default: + super_version = ""; + break; + } } else super_version = ""; @@ -115,8 +115,8 @@ uname (struct utsname *buf) $ ./uname.exe -s => MINGW32_NT-5.1 */ sprintf (buf->sysname, "MINGW32_%s-%u.%u", super_version, - (unsigned int) version.dwMajorVersion, - (unsigned int) version.dwMinorVersion); + (unsigned int) version.dwMajorVersion, + (unsigned int) version.dwMinorVersion); #else sprintf (buf->sysname, "Windows%s", super_version); #endif @@ -130,59 +130,59 @@ uname (struct utsname *buf) { /* Windows NT or newer. */ struct windows_version - { - int major; - int minor; - unsigned int server_offset; - const char *name; - }; + { + int major; + int minor; + unsigned int server_offset; + const char *name; + }; /* Storing the workstation and server version names in a single stream does not waste memory when they are the same. These macros abstract the representation. VERSION1 is used if - version.wProductType does not matter, VERSION2 if it does. */ + version.wProductType does not matter, VERSION2 if it does. */ #define VERSION1(major, minor, name) \ - { major, minor, 0, name } + { major, minor, 0, name } #define VERSION2(major, minor, workstation, server) \ - { major, minor, sizeof workstation, workstation "\0" server } + { major, minor, sizeof workstation, workstation "\0" server } static const struct windows_version versions[] = - { - VERSION2 (3, -1, "Windows NT Workstation", "Windows NT Server"), - VERSION2 (4, -1, "Windows NT Workstation", "Windows NT Server"), - VERSION1 (5, 0, "Windows 2000"), - VERSION1 (5, 1, "Windows XP"), - VERSION1 (5, 2, "Windows Server 2003"), - VERSION2 (6, 0, "Windows Vista", "Windows Server 2008"), - VERSION2 (6, 1, "Windows 7", "Windows Server 2008 R2"), - VERSION2 (-1, -1, "Windows", "Windows Server") - }; + { + VERSION2 (3, -1, "Windows NT Workstation", "Windows NT Server"), + VERSION2 (4, -1, "Windows NT Workstation", "Windows NT Server"), + VERSION1 (5, 0, "Windows 2000"), + VERSION1 (5, 1, "Windows XP"), + VERSION1 (5, 2, "Windows Server 2003"), + VERSION2 (6, 0, "Windows Vista", "Windows Server 2008"), + VERSION2 (6, 1, "Windows 7", "Windows Server 2008 R2"), + VERSION2 (-1, -1, "Windows", "Windows Server") + }; const char *base; const struct windows_version *v = versions; /* Find a version that matches ours. The last element is a wildcard that always ends the loop. */ while ((v->major != version.dwMajorVersion && v->major != -1) - || (v->minor != version.dwMinorVersion && v->minor != -1)) - v++; + || (v->minor != version.dwMinorVersion && v->minor != -1)) + v++; if (have_versionex && versionex.wProductType != VER_NT_WORKSTATION) - base = v->name + v->server_offset; + base = v->name + v->server_offset; else - base = v->name; + base = v->name; if (v->major == -1 || v->minor == -1) - sprintf (buf->release, "%s %u.%u", - base, - (unsigned int) version.dwMajorVersion, - (unsigned int) version.dwMinorVersion); + sprintf (buf->release, "%s %u.%u", + base, + (unsigned int) version.dwMajorVersion, + (unsigned int) version.dwMinorVersion); else - strcpy (buf->release, base); + strcpy (buf->release, base); } else if (version.dwPlatformId == VER_PLATFORM_WIN32_CE) { /* Windows CE or Embedded CE. */ sprintf (buf->release, "Windows CE %u.%u", - (unsigned int) version.dwMajorVersion, - (unsigned int) version.dwMinorVersion); + (unsigned int) version.dwMajorVersion, + (unsigned int) version.dwMinorVersion); } else { @@ -199,66 +199,66 @@ uname (struct utsname *buf) /* Check for Windows NT or CE, since the info.wProcessorLevel is garbage on Windows 95. */ if (version.dwPlatformId == VER_PLATFORM_WIN32_NT - || version.dwPlatformId == VER_PLATFORM_WIN32_CE) + || version.dwPlatformId == VER_PLATFORM_WIN32_CE) { - /* Windows NT or newer, or Windows CE or Embedded CE. */ - switch (info.wProcessorArchitecture) - { - case PROCESSOR_ARCHITECTURE_AMD64: - strcpy (buf->machine, "x86_64"); - break; - case PROCESSOR_ARCHITECTURE_IA64: - strcpy (buf->machine, "ia64"); - break; - case PROCESSOR_ARCHITECTURE_INTEL: - strcpy (buf->machine, "i386"); - if (info.wProcessorLevel >= 3) - buf->machine[1] = - '0' + (info.wProcessorLevel <= 6 ? info.wProcessorLevel : 6); - break; - case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64: - strcpy (buf->machine, "i686"); - break; - case PROCESSOR_ARCHITECTURE_MIPS: - strcpy (buf->machine, "mips"); - break; - case PROCESSOR_ARCHITECTURE_ALPHA: - case PROCESSOR_ARCHITECTURE_ALPHA64: - strcpy (buf->machine, "alpha"); - break; - case PROCESSOR_ARCHITECTURE_PPC: - strcpy (buf->machine, "powerpc"); - break; - case PROCESSOR_ARCHITECTURE_SHX: - strcpy (buf->machine, "sh"); - break; - case PROCESSOR_ARCHITECTURE_ARM: - strcpy (buf->machine, "arm"); - break; - default: - strcpy (buf->machine, "unknown"); - break; - } + /* Windows NT or newer, or Windows CE or Embedded CE. */ + switch (info.wProcessorArchitecture) + { + case PROCESSOR_ARCHITECTURE_AMD64: + strcpy (buf->machine, "x86_64"); + break; + case PROCESSOR_ARCHITECTURE_IA64: + strcpy (buf->machine, "ia64"); + break; + case PROCESSOR_ARCHITECTURE_INTEL: + strcpy (buf->machine, "i386"); + if (info.wProcessorLevel >= 3) + buf->machine[1] = + '0' + (info.wProcessorLevel <= 6 ? info.wProcessorLevel : 6); + break; + case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64: + strcpy (buf->machine, "i686"); + break; + case PROCESSOR_ARCHITECTURE_MIPS: + strcpy (buf->machine, "mips"); + break; + case PROCESSOR_ARCHITECTURE_ALPHA: + case PROCESSOR_ARCHITECTURE_ALPHA64: + strcpy (buf->machine, "alpha"); + break; + case PROCESSOR_ARCHITECTURE_PPC: + strcpy (buf->machine, "powerpc"); + break; + case PROCESSOR_ARCHITECTURE_SHX: + strcpy (buf->machine, "sh"); + break; + case PROCESSOR_ARCHITECTURE_ARM: + strcpy (buf->machine, "arm"); + break; + default: + strcpy (buf->machine, "unknown"); + break; + } } else { - /* Windows 95/98/ME. */ - switch (info.dwProcessorType) - { - case PROCESSOR_AMD_X8664: - strcpy (buf->machine, "x86_64"); - break; - case PROCESSOR_INTEL_IA64: - strcpy (buf->machine, "ia64"); - break; - default: - if (info.dwProcessorType % 100 == 86) - sprintf (buf->machine, "i%u", - (unsigned int) info.dwProcessorType); - else - strcpy (buf->machine, "unknown"); - break; - } + /* Windows 95/98/ME. */ + switch (info.dwProcessorType) + { + case PROCESSOR_AMD_X8664: + strcpy (buf->machine, "x86_64"); + break; + case PROCESSOR_INTEL_IA64: + strcpy (buf->machine, "ia64"); + break; + default: + if (info.dwProcessorType % 100 == 86) + sprintf (buf->machine, "i%u", + (unsigned int) info.dwProcessorType); + else + strcpy (buf->machine, "unknown"); + break; + } } } diff --git a/lib/unicase.h b/lib/unicase.h index cb2df95b6..cc14c71b2 100644 --- a/lib/unicase.h +++ b/lib/unicase.h @@ -91,57 +91,57 @@ extern const char * case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_toupper (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_toupper (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_toupper (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the lowercase mapping of a string. The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_tolower (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_tolower (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_tolower (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the titlecase mapping of a string. The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_totitle (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_totitle (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_totitle (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* The case-mapping context given by a prefix string. */ typedef struct casing_prefix_context - { - /* These fields are private, undocumented. */ - uint32_t last_char_except_ignorable; - uint32_t last_char_normal_or_above; - } - casing_prefix_context_t; + { + /* These fields are private, undocumented. */ + uint32_t last_char_except_ignorable; + uint32_t last_char_normal_or_above; + } + casing_prefix_context_t; /* The case-mapping context of the empty prefix string. */ extern const casing_prefix_context_t unicase_empty_prefix_context; /* Return the case-mapping context of a given prefix string. */ @@ -155,22 +155,22 @@ extern casing_prefix_context_t case-mapping context of the prefix A. */ extern casing_prefix_context_t u8_casing_prefixes_context (const uint8_t *s, size_t n, - casing_prefix_context_t a_context); + casing_prefix_context_t a_context); extern casing_prefix_context_t u16_casing_prefixes_context (const uint16_t *s, size_t n, - casing_prefix_context_t a_context); + casing_prefix_context_t a_context); extern casing_prefix_context_t u32_casing_prefixes_context (const uint32_t *s, size_t n, - casing_prefix_context_t a_context); + casing_prefix_context_t a_context); /* The case-mapping context given by a suffix string. */ typedef struct casing_suffix_context - { - /* These fields are private, undocumented. */ - uint32_t first_char_except_ignorable; - uint32_t bits; - } - casing_suffix_context_t; + { + /* These fields are private, undocumented. */ + uint32_t first_char_except_ignorable; + uint32_t bits; + } + casing_suffix_context_t; /* The case-mapping context of the empty suffix string. */ extern const casing_suffix_context_t unicase_empty_suffix_context; /* Return the case-mapping context of a given suffix string. */ @@ -184,85 +184,85 @@ extern casing_suffix_context_t case-mapping context of the suffix A. */ extern casing_suffix_context_t u8_casing_suffixes_context (const uint8_t *s, size_t n, - casing_suffix_context_t a_context); + casing_suffix_context_t a_context); extern casing_suffix_context_t u16_casing_suffixes_context (const uint16_t *s, size_t n, - casing_suffix_context_t a_context); + casing_suffix_context_t a_context); extern casing_suffix_context_t u32_casing_suffixes_context (const uint32_t *s, size_t n, - casing_suffix_context_t a_context); + casing_suffix_context_t a_context); /* Return the uppercase mapping of a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_toupper (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_toupper (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_toupper (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the lowercase mapping of a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_tolower (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_tolower (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_tolower (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the titlecase mapping of a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_totitle (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_totitle (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_totitle (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the case folded string. Comparing uN_casefold (S1) and uN_casefold (S2) with uN_cmp2() is equivalent @@ -271,38 +271,38 @@ extern uint32_t * case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_casefold (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_casefold (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_casefold (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Likewise, for a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_casefold (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_casefold (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_casefold (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in case and normalization. The nf argument identifies the normalization form to apply after the @@ -311,20 +311,20 @@ extern uint32_t * return 0. Upon failure, return -1 with errno set. */ extern int u8_casecmp (const uint8_t *s1, size_t n1, - const uint8_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint8_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u16_casecmp (const uint16_t *s1, size_t n1, - const uint16_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint16_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u32_casecmp (const uint32_t *s1, size_t n1, - const uint32_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint32_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int ulc_casecmp (const char *s1, size_t n1, - const char *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const char *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); /* Convert the string S of length N to a NUL-terminated byte sequence, in such a way that comparing uN_casexfrm (S1) and uN_casexfrm (S2) with the gnulib @@ -332,16 +332,16 @@ extern int NF must be either UNINORM_NFC, UNINORM_NFKC, or NULL for no normalization. */ extern char * u8_casexfrm (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); extern char * u16_casexfrm (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); extern char * u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); extern char * ulc_casexfrm (const char *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in case and normalization, using the collation rules of the current locale. @@ -352,81 +352,81 @@ extern char * return 0. Upon failure, return -1 with errno set. */ extern int u8_casecoll (const uint8_t *s1, size_t n1, - const uint8_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint8_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u16_casecoll (const uint16_t *s1, size_t n1, - const uint16_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint16_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u32_casecoll (const uint32_t *s1, size_t n1, - const uint32_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint32_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int ulc_casecoll (const char *s1, size_t n1, - const char *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const char *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); /* Set *RESULTP to true if mapping NFD(S) to upper case is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_uppercase (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_uppercase (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_uppercase (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if mapping NFD(S) to lower case is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_lowercase (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_lowercase (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_lowercase (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if mapping NFD(S) to title case is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_titlecase (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_titlecase (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_titlecase (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if applying case folding to NFD(S) is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_casefolded (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_casefolded (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_casefolded (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if case matters for S, that is, if mapping NFD(S) to either upper case or lower case or title case is not a no-op. @@ -436,16 +436,16 @@ extern int Upon failure, return -1 with errno set. */ extern int u8_is_cased (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_cased (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_cased (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* ========================================================================= */ diff --git a/lib/unicase/cased.c b/lib/unicase/cased.c index 5fbf4cb74..13b88e454 100644 --- a/lib/unicase/cased.c +++ b/lib/unicase/cased.c @@ -33,8 +33,8 @@ bool uc_is_cased (ucs4_t uc) { return (uc_is_property_lowercase (uc) - || uc_is_property_uppercase (uc) - || uc_is_general_category (uc, UC_TITLECASE_LETTER)); + || uc_is_property_uppercase (uc) + || uc_is_general_category (uc, UC_TITLECASE_LETTER)); } #else diff --git a/lib/unicase/ignorable.c b/lib/unicase/ignorable.c index 84b2634cc..9721046a5 100644 --- a/lib/unicase/ignorable.c +++ b/lib/unicase/ignorable.c @@ -47,12 +47,12 @@ uc_is_case_ignorable (ucs4_t uc) int wbp = uc_wordbreak_property (uc); return (wbp == WBP_MIDLETTER || wbp == WBP_MIDNUMLET - || uc_is_general_category_withtable (uc, UC_CATEGORY_MASK_Mn - | UC_CATEGORY_MASK_Me - | UC_CATEGORY_MASK_Cf - | UC_CATEGORY_MASK_Lm - | UC_CATEGORY_MASK_Sk)) - && !uc_is_cased (uc); + || uc_is_general_category_withtable (uc, UC_CATEGORY_MASK_Mn + | UC_CATEGORY_MASK_Me + | UC_CATEGORY_MASK_Cf + | UC_CATEGORY_MASK_Lm + | UC_CATEGORY_MASK_Sk)) + && !uc_is_cased (uc); } #else diff --git a/lib/unicase/invariant.h b/lib/unicase/invariant.h index 201514333..170358ef6 100644 --- a/lib/unicase/invariant.h +++ b/lib/unicase/invariant.h @@ -24,22 +24,22 @@ /* Return true if mapping NFD(S) to via MAPPING is a no-op. */ extern int u8_is_invariant (const uint8_t *s, size_t n, - uint8_t * (*mapping) (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp), - const char *iso639_language, - bool *resultp); + uint8_t * (*mapping) (const uint8_t *s, size_t n, const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp), + const char *iso639_language, + bool *resultp); extern int u16_is_invariant (const uint16_t *s, size_t n, - uint16_t * (*mapping) (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp), - const char *iso639_language, - bool *resultp); + uint16_t * (*mapping) (const uint16_t *s, size_t n, const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp), + const char *iso639_language, + bool *resultp); extern int u32_is_invariant (const uint32_t *s, size_t n, - uint32_t * (*mapping) (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp), - const char *iso639_language, - bool *resultp); + uint32_t * (*mapping) (const uint32_t *s, size_t n, const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp), + const char *iso639_language, + bool *resultp); diff --git a/lib/unicase/locale-language.c b/lib/unicase/locale-language.c index 074baa410..3b7455693 100644 --- a/lib/unicase/locale-language.c +++ b/lib/unicase/locale-language.c @@ -46,9 +46,9 @@ uc_locale_language (void) if (p != locale_name) { const char *language = - uc_locale_languages_lookup (locale_name, p - locale_name); + uc_locale_languages_lookup (locale_name, p - locale_name); if (language != NULL) - return language; + return language; } return ""; diff --git a/lib/unicase/simple-mapping.h b/lib/unicase/simple-mapping.h index 44cecc81d..fcd2a4bac 100644 --- a/lib/unicase/simple-mapping.h +++ b/lib/unicase/simple-mapping.h @@ -23,17 +23,17 @@ FUNC (ucs4_t uc) { int lookup1 = u_mapping.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> mapping_header_2) & mapping_header_3; - int lookup2 = u_mapping.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & mapping_header_4); - int lookup3 = u_mapping.level3[lookup2 + index3]; + { + unsigned int index2 = (uc >> mapping_header_2) & mapping_header_3; + int lookup2 = u_mapping.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & mapping_header_4); + int lookup3 = u_mapping.level3[lookup2 + index3]; - return uc + lookup3; - } - } + return uc + lookup3; + } + } } return uc; } diff --git a/lib/unicase/u-casecmp.h b/lib/unicase/u-casecmp.h index e1cf99c46..c152063c8 100644 --- a/lib/unicase/u-casecmp.h +++ b/lib/unicase/u-casecmp.h @@ -45,11 +45,11 @@ FUNC (const SRC_UNIT *s1, size_t n1, const SRC_UNIT *s2, size_t n2, if (norms2 == NULL) { if (norms1 != buf1) - { - int saved_errno = errno; - free (norms1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms1); + errno = saved_errno; + } return -1; } diff --git a/lib/unicase/u-casecoll.h b/lib/unicase/u-casecoll.h index 73094abe8..a2cd5ec63 100644 --- a/lib/unicase/u-casecoll.h +++ b/lib/unicase/u-casecoll.h @@ -43,17 +43,17 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2, if (transformed2 == NULL) { if (transformed1 != buf1) - { - int saved_errno = errno; - free (transformed1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (transformed1); + errno = saved_errno; + } return -1; } /* Compare the transformed strings. */ cmp = memcmp2 (transformed1, transformed1_length, - transformed2, transformed2_length); + transformed2, transformed2_length); if (cmp < 0) cmp = -1; else if (cmp > 0) diff --git a/lib/unicase/u-casefold.h b/lib/unicase/u-casefold.h index c41f4e182..0124509e6 100644 --- a/lib/unicase/u-casefold.h +++ b/lib/unicase/u-casefold.h @@ -21,8 +21,8 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, UNIT *resultbuf, size_t *lengthp) { return U_CT_CASEFOLD (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u-casemap.h b/lib/unicase/u-casemap.h index ea41444a1..bbcfd27a9 100644 --- a/lib/unicase/u-casemap.h +++ b/lib/unicase/u-casemap.h @@ -58,311 +58,311 @@ FUNC (const UNIT *s, size_t n, while (s < s_end) { - ucs4_t uc; - int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); - - ucs4_t mapped_uc[3]; - unsigned int mapped_count; - - if (uc < 0x10000) - { - /* Look first in the special-casing table. */ - char code[3]; - - code[0] = (uc >> 8) & 0xff; - code[1] = uc & 0xff; - - for (code[2] = 0; ; code[2]++) - { - const struct special_casing_rule *rule = - gl_unicase_special_lookup (code, 3); - - if (rule == NULL) - break; - - /* Test if the condition applies. */ - /* Does the language apply? */ - if (rule->language[0] == '\0' - || (iso639_language != NULL - && iso639_language[0] == rule->language[0] - && iso639_language[1] == rule->language[1])) - { - /* Does the context apply? */ - int context = rule->context; - bool applies; - - if (context < 0) - context = - context; - switch (context) - { - case SCC_ALWAYS: - applies = true; - break; - - case SCC_FINAL_SIGMA: - /* "Before" condition: preceded by a sequence - consisting of a cased letter and a case-ignorable - sequence. - "After" condition: not followed by a sequence - consisting of a case-ignorable sequence and then a - cased letter. */ - /* Test the "before" condition. */ - applies = uc_is_cased (last_char_except_ignorable); - /* Test the "after" condition. */ - if (applies) - { - const UNIT *s2 = s + count; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - /* Our uc_is_case_ignorable function is - known to return false for all cased - characters. So we can call - uc_is_case_ignorable first. */ - if (!uc_is_case_ignorable (uc2)) - { - applies = ! uc_is_cased (uc2); - break; - } - s2 += count2; - } - else - { - applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); - break; - } - } - } - break; - - case SCC_AFTER_SOFT_DOTTED: - /* "Before" condition: There is a Soft_Dotted character - before it, with no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = uc_is_property_soft_dotted (last_char_normal_or_above); - break; - - case SCC_MORE_ABOVE: - /* "After" condition: followed by a character of - combining class 230 (Above) with no intervening - character of combining class 0 or 230 (Above). */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A) - { - applies = true; - break; - } - if (ccc == UC_CCC_NR) - break; - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); - break; - } - } - } - break; - - case SCC_BEFORE_DOT: - /* "After" condition: followed by COMBINING DOT ABOVE - (U+0307). Any sequence of characters with a - combining class that is neither 0 nor 230 may - intervene between the current character and the - combining dot above. */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ - { - applies = true; - break; - } - { - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - break; - } - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); - break; - } - } - } - break; - - case SCC_AFTER_I: - /* "Before" condition: There is an uppercase I before - it, and there is no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = (last_char_normal_or_above == 'I'); - break; - - default: - abort (); - } - if (rule->context < 0) - applies = !applies; - - if (applies) - { - /* The rule applies. - Look up the mapping (0 to 3 characters). */ - const unsigned short *mapped_in_rule = - (const unsigned short *)((const char *)rule + offset_in_rule); - - if (mapped_in_rule[0] == 0) - mapped_count = 0; - else - { - mapped_uc[0] = mapped_in_rule[0]; - if (mapped_in_rule[1] == 0) - mapped_count = 1; - else - { - mapped_uc[1] = mapped_in_rule[1]; - if (mapped_in_rule[2] == 0) - mapped_count = 2; - else - { - mapped_uc[2] = mapped_in_rule[2]; - mapped_count = 3; - } - } - } - goto found_mapping; - } - } - - /* Optimization: Save a hash table lookup in the next round. */ - if (!rule->has_next) - break; - } - } - - /* No special-cased mapping. So use the locale and context independent - mapping. */ - mapped_uc[0] = single_character_map (uc); - mapped_count = 1; + ucs4_t uc; + int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); + + ucs4_t mapped_uc[3]; + unsigned int mapped_count; + + if (uc < 0x10000) + { + /* Look first in the special-casing table. */ + char code[3]; + + code[0] = (uc >> 8) & 0xff; + code[1] = uc & 0xff; + + for (code[2] = 0; ; code[2]++) + { + const struct special_casing_rule *rule = + gl_unicase_special_lookup (code, 3); + + if (rule == NULL) + break; + + /* Test if the condition applies. */ + /* Does the language apply? */ + if (rule->language[0] == '\0' + || (iso639_language != NULL + && iso639_language[0] == rule->language[0] + && iso639_language[1] == rule->language[1])) + { + /* Does the context apply? */ + int context = rule->context; + bool applies; + + if (context < 0) + context = - context; + switch (context) + { + case SCC_ALWAYS: + applies = true; + break; + + case SCC_FINAL_SIGMA: + /* "Before" condition: preceded by a sequence + consisting of a cased letter and a case-ignorable + sequence. + "After" condition: not followed by a sequence + consisting of a case-ignorable sequence and then a + cased letter. */ + /* Test the "before" condition. */ + applies = uc_is_cased (last_char_except_ignorable); + /* Test the "after" condition. */ + if (applies) + { + const UNIT *s2 = s + count; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + /* Our uc_is_case_ignorable function is + known to return false for all cased + characters. So we can call + uc_is_case_ignorable first. */ + if (!uc_is_case_ignorable (uc2)) + { + applies = ! uc_is_cased (uc2); + break; + } + s2 += count2; + } + else + { + applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); + break; + } + } + } + break; + + case SCC_AFTER_SOFT_DOTTED: + /* "Before" condition: There is a Soft_Dotted character + before it, with no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = uc_is_property_soft_dotted (last_char_normal_or_above); + break; + + case SCC_MORE_ABOVE: + /* "After" condition: followed by a character of + combining class 230 (Above) with no intervening + character of combining class 0 or 230 (Above). */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A) + { + applies = true; + break; + } + if (ccc == UC_CCC_NR) + break; + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); + break; + } + } + } + break; + + case SCC_BEFORE_DOT: + /* "After" condition: followed by COMBINING DOT ABOVE + (U+0307). Any sequence of characters with a + combining class that is neither 0 nor 230 may + intervene between the current character and the + combining dot above. */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ + { + applies = true; + break; + } + { + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + break; + } + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); + break; + } + } + } + break; + + case SCC_AFTER_I: + /* "Before" condition: There is an uppercase I before + it, and there is no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = (last_char_normal_or_above == 'I'); + break; + + default: + abort (); + } + if (rule->context < 0) + applies = !applies; + + if (applies) + { + /* The rule applies. + Look up the mapping (0 to 3 characters). */ + const unsigned short *mapped_in_rule = + (const unsigned short *)((const char *)rule + offset_in_rule); + + if (mapped_in_rule[0] == 0) + mapped_count = 0; + else + { + mapped_uc[0] = mapped_in_rule[0]; + if (mapped_in_rule[1] == 0) + mapped_count = 1; + else + { + mapped_uc[1] = mapped_in_rule[1]; + if (mapped_in_rule[2] == 0) + mapped_count = 2; + else + { + mapped_uc[2] = mapped_in_rule[2]; + mapped_count = 3; + } + } + } + goto found_mapping; + } + } + + /* Optimization: Save a hash table lookup in the next round. */ + if (!rule->has_next) + break; + } + } + + /* No special-cased mapping. So use the locale and context independent + mapping. */ + mapped_uc[0] = single_character_map (uc); + mapped_count = 1; found_mapping: - /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ - { - unsigned int i; - - for (i = 0; i < mapped_count; i++) - { - ucs4_t muc = mapped_uc[i]; - - /* Append muc to the result accumulator. */ - if (length < allocated) - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret >= 0) - { - length += ret; - goto done_appending; - } - } - { - size_t old_allocated = allocated; - size_t new_allocated = 2 * old_allocated; - if (new_allocated < 64) - new_allocated = 64; - if (new_allocated < old_allocated) /* integer overflow? */ - abort (); - { - UNIT *larger_result; - if (result == NULL) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - else if (result == resultbuf) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - U_CPY (larger_result, resultbuf, length); - } - else - { - larger_result = - (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - result = larger_result; - allocated = new_allocated; - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret < 0) - abort (); - length += ret; - goto done_appending; - } - } - } - done_appending: ; - } - } - - if (!uc_is_case_ignorable (uc)) - last_char_except_ignorable = uc; - - { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - last_char_normal_or_above = uc; - } - - s += count; + /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ + { + unsigned int i; + + for (i = 0; i < mapped_count; i++) + { + ucs4_t muc = mapped_uc[i]; + + /* Append muc to the result accumulator. */ + if (length < allocated) + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret >= 0) + { + length += ret; + goto done_appending; + } + } + { + size_t old_allocated = allocated; + size_t new_allocated = 2 * old_allocated; + if (new_allocated < 64) + new_allocated = 64; + if (new_allocated < old_allocated) /* integer overflow? */ + abort (); + { + UNIT *larger_result; + if (result == NULL) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + else if (result == resultbuf) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + U_CPY (larger_result, resultbuf, length); + } + else + { + larger_result = + (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + result = larger_result; + allocated = new_allocated; + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret < 0) + abort (); + length += ret; + goto done_appending; + } + } + } + done_appending: ; + } + } + + if (!uc_is_case_ignorable (uc)) + last_char_except_ignorable = uc; + + { + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + last_char_normal_or_above = uc; + } + + s += count; } } @@ -373,7 +373,7 @@ FUNC (const UNIT *s, size_t n, normalized_result = U_NORMALIZE (nf, result, length, resultbuf, lengthp); if (normalized_result == NULL) - goto fail; + goto fail; free (result); return normalized_result; @@ -382,15 +382,15 @@ FUNC (const UNIT *s, size_t n, if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - goto fail; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + goto fail; + } + } } else if (result != resultbuf && length < allocated) { @@ -399,7 +399,7 @@ FUNC (const UNIT *s, size_t n, memory = (UNIT *) realloc (result, length * sizeof (UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unicase/u-casexfrm.h b/lib/unicase/u-casexfrm.h index e36aff3b9..abb34d638 100644 --- a/lib/unicase/u-casexfrm.h +++ b/lib/unicase/u-casexfrm.h @@ -38,18 +38,18 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf, /* Convert it to locale encoding. */ convs_length = sizeof (convsbuf) - 1; convs = U_CONV_TO_ENCODING (locale_charset (), - iconveh_error, - foldeds, foldeds_length, - NULL, - convsbuf, &convs_length); + iconveh_error, + foldeds, foldeds_length, + NULL, + convsbuf, &convs_length); if (convs == NULL) { if (foldeds != foldedsbuf) - { - int saved_errno = errno; - free (foldeds); - errno = saved_errno; - } + { + int saved_errno = errno; + free (foldeds); + errno = saved_errno; + } return NULL; } @@ -61,11 +61,11 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf, { char *memory = (char *) realloc (convs, convs_length + 1); if (memory == NULL) - { - free (convs); - errno = ENOMEM; - return NULL; - } + { + free (convs); + errno = ENOMEM; + return NULL; + } convs = memory; } @@ -74,11 +74,11 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf, if (result == NULL) { if (convs != convsbuf) - { - int saved_errno = errno; - free (convs); - errno = saved_errno; - } + { + int saved_errno = errno; + free (convs); + errno = saved_errno; + } return NULL; } diff --git a/lib/unicase/u-ct-casefold.h b/lib/unicase/u-ct-casefold.h index d97be264b..1f4a18c82 100644 --- a/lib/unicase/u-ct-casefold.h +++ b/lib/unicase/u-ct-casefold.h @@ -36,14 +36,14 @@ FUNC (const UNIT *s, size_t n, if (nf == NULL) /* X -> toCasefold(X) */ return U_CASEMAP (s, n, prefix_context, suffix_context, iso639_language, - uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), - NULL, - resultbuf, lengthp); + uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), + NULL, + resultbuf, lengthp); else { uninorm_t nfd = uninorm_decomposing_form (nf); /* X -> nf(toCasefold(NFD(X))) or - X -> nf(toCasefold(nfd(toCasefold(NFD(X))))) */ + X -> nf(toCasefold(nfd(toCasefold(NFD(X))))) */ int repeat = (uninorm_is_compat_decomposing (nf) ? 2 : 1); UNIT tmpbuf1[2048 / sizeof (UNIT)]; UNIT tmpbuf2[2048 / sizeof (UNIT)]; @@ -55,51 +55,51 @@ FUNC (const UNIT *s, size_t n, tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT); tmp1 = U_NORMALIZE (UNINORM_NFD, s, n, tmpbuf1, &tmp1_length); if (tmp1 == NULL) - /* errno is set here. */ - return NULL; + /* errno is set here. */ + return NULL; do - { - tmp2_length = sizeof (tmpbuf2) / sizeof (UNIT); - tmp2 = U_CASEMAP (tmp1, tmp1_length, - prefix_context, suffix_context, iso639_language, - uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), - NULL, - tmpbuf2, &tmp2_length); - if (tmp2 == NULL) - { - int saved_errno = errno; - if (tmp1 != tmpbuf1) - free (tmp1); - errno = saved_errno; - return NULL; - } + { + tmp2_length = sizeof (tmpbuf2) / sizeof (UNIT); + tmp2 = U_CASEMAP (tmp1, tmp1_length, + prefix_context, suffix_context, iso639_language, + uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), + NULL, + tmpbuf2, &tmp2_length); + if (tmp2 == NULL) + { + int saved_errno = errno; + if (tmp1 != tmpbuf1) + free (tmp1); + errno = saved_errno; + return NULL; + } - if (tmp1 != tmpbuf1) - free (tmp1); + if (tmp1 != tmpbuf1) + free (tmp1); - if (repeat > 1) - { - tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT); - tmp1 = U_NORMALIZE (nfd, tmp2, tmp2_length, - tmpbuf1, &tmp1_length); - } - else - /* Last run through this loop. */ - tmp1 = U_NORMALIZE (nf, tmp2, tmp2_length, - resultbuf, lengthp); - if (tmp1 == NULL) - { - int saved_errno = errno; - if (tmp2 != tmpbuf2) - free (tmp2); - errno = saved_errno; - return NULL; - } + if (repeat > 1) + { + tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT); + tmp1 = U_NORMALIZE (nfd, tmp2, tmp2_length, + tmpbuf1, &tmp1_length); + } + else + /* Last run through this loop. */ + tmp1 = U_NORMALIZE (nf, tmp2, tmp2_length, + resultbuf, lengthp); + if (tmp1 == NULL) + { + int saved_errno = errno; + if (tmp2 != tmpbuf2) + free (tmp2); + errno = saved_errno; + return NULL; + } - if (tmp2 != tmpbuf2) - free (tmp2); - } + if (tmp2 != tmpbuf2) + free (tmp2); + } while (--repeat > 0); return tmp1; diff --git a/lib/unicase/u-ct-totitle.h b/lib/unicase/u-ct-totitle.h index f0d4fd773..b09dcfc6f 100644 --- a/lib/unicase/u-ct-totitle.h +++ b/lib/unicase/u-ct-totitle.h @@ -55,10 +55,10 @@ FUNC (const UNIT *s, size_t n, { wordbreaks = (char *) malloc (n); if (wordbreaks == NULL) - { - errno = ENOMEM; - goto fail2; - } + { + errno = ENOMEM; + goto fail2; + } U_WORDBREAKS (s, n, wordbreaks); } else @@ -70,12 +70,12 @@ FUNC (const UNIT *s, size_t n, /* When considering the string as segmented by word boundaries: For each such segment: - - In the first part, we are searching for the first cased character. - In this state, in_word_first_part = true, and no conversion takes - place. - - In the second part, we are converting every character: the first - among these characters to title case, the other ones to lower case. - In this state, in_word_first_part = false. */ + - In the first part, we are searching for the first cased character. + In this state, in_word_first_part = true, and no conversion takes + place. + - In the second part, we are converting every character: the first + among these characters to title case, the other ones to lower case. + In this state, in_word_first_part = false. */ bool in_word_first_part = true; /* Helper for evaluating the FINAL_SIGMA condition: @@ -90,356 +90,356 @@ FUNC (const UNIT *s, size_t n, while (s < s_end) { - /* Fetch the next character. */ - ucs4_t uc; - int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); - - ucs4_t (*single_character_map) (ucs4_t); - size_t offset_in_rule; /* offset in 'struct special_casing_rule' */ - - ucs4_t mapped_uc[3]; - unsigned int mapped_count; - - if (*wp) - /* Crossing a word boundary. */ - in_word_first_part = true; - - /* Determine single_character_map, offset_in_rule. - There are three possibilities: - - uc should not be converted. - - uc should be titlecased. - - uc should be lowercased. */ - if (in_word_first_part) - { - if (uc_is_cased (uc)) - { - /* uc is to be titlecased. */ - single_character_map = uc_totitle; - offset_in_rule = offsetof (struct special_casing_rule, title[0]); - in_word_first_part = false; - } - else - { - /* uc is not converted. */ - single_character_map = NULL; - offset_in_rule = 0; - } - } - else - { - /* uc is to be lowercased. */ - single_character_map = uc_tolower; - offset_in_rule = offsetof (struct special_casing_rule, lower[0]); - } - - /* Actually map uc. */ - if (single_character_map == NULL) - { - mapped_uc[0] = uc; - mapped_count = 1; - goto found_mapping; - } - - if (uc < 0x10000) - { - /* Look first in the special-casing table. */ - char code[3]; - - code[0] = (uc >> 8) & 0xff; - code[1] = uc & 0xff; - - for (code[2] = 0; ; code[2]++) - { - const struct special_casing_rule *rule = - gl_unicase_special_lookup (code, 3); - - if (rule == NULL) - break; - - /* Test if the condition applies. */ - /* Does the language apply? */ - if (rule->language[0] == '\0' - || (iso639_language != NULL - && iso639_language[0] == rule->language[0] - && iso639_language[1] == rule->language[1])) - { - /* Does the context apply? */ - int context = rule->context; - bool applies; - - if (context < 0) - context = - context; - switch (context) - { - case SCC_ALWAYS: - applies = true; - break; - - case SCC_FINAL_SIGMA: - /* "Before" condition: preceded by a sequence - consisting of a cased letter and a case-ignorable - sequence. - "After" condition: not followed by a sequence - consisting of a case-ignorable sequence and then a - cased letter. */ - /* Test the "before" condition. */ - applies = uc_is_cased (last_char_except_ignorable); - /* Test the "after" condition. */ - if (applies) - { - const UNIT *s2 = s + count; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - /* Our uc_is_case_ignorable function is - known to return false for all cased - characters. So we can call - uc_is_case_ignorable first. */ - if (!uc_is_case_ignorable (uc2)) - { - applies = ! uc_is_cased (uc2); - break; - } - s2 += count2; - } - else - { - applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); - break; - } - } - } - break; - - case SCC_AFTER_SOFT_DOTTED: - /* "Before" condition: There is a Soft_Dotted character - before it, with no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = uc_is_property_soft_dotted (last_char_normal_or_above); - break; - - case SCC_MORE_ABOVE: - /* "After" condition: followed by a character of - combining class 230 (Above) with no intervening - character of combining class 0 or 230 (Above). */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A) - { - applies = true; - break; - } - if (ccc == UC_CCC_NR) - break; - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); - break; - } - } - } - break; - - case SCC_BEFORE_DOT: - /* "After" condition: followed by COMBINING DOT ABOVE - (U+0307). Any sequence of characters with a - combining class that is neither 0 nor 230 may - intervene between the current character and the - combining dot above. */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ - { - applies = true; - break; - } - { - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - break; - } - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); - break; - } - } - } - break; - - case SCC_AFTER_I: - /* "Before" condition: There is an uppercase I before - it, and there is no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = (last_char_normal_or_above == 'I'); - break; - - default: - abort (); - } - if (rule->context < 0) - applies = !applies; - - if (applies) - { - /* The rule applies. - Look up the mapping (0 to 3 characters). */ - const unsigned short *mapped_in_rule = - (const unsigned short *)((const char *)rule + offset_in_rule); - - if (mapped_in_rule[0] == 0) - mapped_count = 0; - else - { - mapped_uc[0] = mapped_in_rule[0]; - if (mapped_in_rule[1] == 0) - mapped_count = 1; - else - { - mapped_uc[1] = mapped_in_rule[1]; - if (mapped_in_rule[2] == 0) - mapped_count = 2; - else - { - mapped_uc[2] = mapped_in_rule[2]; - mapped_count = 3; - } - } - } - goto found_mapping; - } - } - - /* Optimization: Save a hash table lookup in the next round. */ - if (!rule->has_next) - break; - } - } - - /* No special-cased mapping. So use the locale and context independent - mapping. */ - mapped_uc[0] = single_character_map (uc); - mapped_count = 1; + /* Fetch the next character. */ + ucs4_t uc; + int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); + + ucs4_t (*single_character_map) (ucs4_t); + size_t offset_in_rule; /* offset in 'struct special_casing_rule' */ + + ucs4_t mapped_uc[3]; + unsigned int mapped_count; + + if (*wp) + /* Crossing a word boundary. */ + in_word_first_part = true; + + /* Determine single_character_map, offset_in_rule. + There are three possibilities: + - uc should not be converted. + - uc should be titlecased. + - uc should be lowercased. */ + if (in_word_first_part) + { + if (uc_is_cased (uc)) + { + /* uc is to be titlecased. */ + single_character_map = uc_totitle; + offset_in_rule = offsetof (struct special_casing_rule, title[0]); + in_word_first_part = false; + } + else + { + /* uc is not converted. */ + single_character_map = NULL; + offset_in_rule = 0; + } + } + else + { + /* uc is to be lowercased. */ + single_character_map = uc_tolower; + offset_in_rule = offsetof (struct special_casing_rule, lower[0]); + } + + /* Actually map uc. */ + if (single_character_map == NULL) + { + mapped_uc[0] = uc; + mapped_count = 1; + goto found_mapping; + } + + if (uc < 0x10000) + { + /* Look first in the special-casing table. */ + char code[3]; + + code[0] = (uc >> 8) & 0xff; + code[1] = uc & 0xff; + + for (code[2] = 0; ; code[2]++) + { + const struct special_casing_rule *rule = + gl_unicase_special_lookup (code, 3); + + if (rule == NULL) + break; + + /* Test if the condition applies. */ + /* Does the language apply? */ + if (rule->language[0] == '\0' + || (iso639_language != NULL + && iso639_language[0] == rule->language[0] + && iso639_language[1] == rule->language[1])) + { + /* Does the context apply? */ + int context = rule->context; + bool applies; + + if (context < 0) + context = - context; + switch (context) + { + case SCC_ALWAYS: + applies = true; + break; + + case SCC_FINAL_SIGMA: + /* "Before" condition: preceded by a sequence + consisting of a cased letter and a case-ignorable + sequence. + "After" condition: not followed by a sequence + consisting of a case-ignorable sequence and then a + cased letter. */ + /* Test the "before" condition. */ + applies = uc_is_cased (last_char_except_ignorable); + /* Test the "after" condition. */ + if (applies) + { + const UNIT *s2 = s + count; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + /* Our uc_is_case_ignorable function is + known to return false for all cased + characters. So we can call + uc_is_case_ignorable first. */ + if (!uc_is_case_ignorable (uc2)) + { + applies = ! uc_is_cased (uc2); + break; + } + s2 += count2; + } + else + { + applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); + break; + } + } + } + break; + + case SCC_AFTER_SOFT_DOTTED: + /* "Before" condition: There is a Soft_Dotted character + before it, with no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = uc_is_property_soft_dotted (last_char_normal_or_above); + break; + + case SCC_MORE_ABOVE: + /* "After" condition: followed by a character of + combining class 230 (Above) with no intervening + character of combining class 0 or 230 (Above). */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A) + { + applies = true; + break; + } + if (ccc == UC_CCC_NR) + break; + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); + break; + } + } + } + break; + + case SCC_BEFORE_DOT: + /* "After" condition: followed by COMBINING DOT ABOVE + (U+0307). Any sequence of characters with a + combining class that is neither 0 nor 230 may + intervene between the current character and the + combining dot above. */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ + { + applies = true; + break; + } + { + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + break; + } + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); + break; + } + } + } + break; + + case SCC_AFTER_I: + /* "Before" condition: There is an uppercase I before + it, and there is no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = (last_char_normal_or_above == 'I'); + break; + + default: + abort (); + } + if (rule->context < 0) + applies = !applies; + + if (applies) + { + /* The rule applies. + Look up the mapping (0 to 3 characters). */ + const unsigned short *mapped_in_rule = + (const unsigned short *)((const char *)rule + offset_in_rule); + + if (mapped_in_rule[0] == 0) + mapped_count = 0; + else + { + mapped_uc[0] = mapped_in_rule[0]; + if (mapped_in_rule[1] == 0) + mapped_count = 1; + else + { + mapped_uc[1] = mapped_in_rule[1]; + if (mapped_in_rule[2] == 0) + mapped_count = 2; + else + { + mapped_uc[2] = mapped_in_rule[2]; + mapped_count = 3; + } + } + } + goto found_mapping; + } + } + + /* Optimization: Save a hash table lookup in the next round. */ + if (!rule->has_next) + break; + } + } + + /* No special-cased mapping. So use the locale and context independent + mapping. */ + mapped_uc[0] = single_character_map (uc); + mapped_count = 1; found_mapping: - /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ - { - unsigned int i; - - for (i = 0; i < mapped_count; i++) - { - ucs4_t muc = mapped_uc[i]; - - /* Append muc to the result accumulator. */ - if (length < allocated) - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail1; - } - if (ret >= 0) - { - length += ret; - goto done_appending; - } - } - { - size_t old_allocated = allocated; - size_t new_allocated = 2 * old_allocated; - if (new_allocated < 64) - new_allocated = 64; - if (new_allocated < old_allocated) /* integer overflow? */ - abort (); - { - UNIT *larger_result; - if (result == NULL) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail1; - } - } - else if (result == resultbuf) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail1; - } - U_CPY (larger_result, resultbuf, length); - } - else - { - larger_result = - (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail1; - } - } - result = larger_result; - allocated = new_allocated; - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail1; - } - if (ret < 0) - abort (); - length += ret; - goto done_appending; - } - } - } - done_appending: ; - } - } - - if (!uc_is_case_ignorable (uc)) - last_char_except_ignorable = uc; - - { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - last_char_normal_or_above = uc; - } - - s += count; - wp += count; + /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ + { + unsigned int i; + + for (i = 0; i < mapped_count; i++) + { + ucs4_t muc = mapped_uc[i]; + + /* Append muc to the result accumulator. */ + if (length < allocated) + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail1; + } + if (ret >= 0) + { + length += ret; + goto done_appending; + } + } + { + size_t old_allocated = allocated; + size_t new_allocated = 2 * old_allocated; + if (new_allocated < 64) + new_allocated = 64; + if (new_allocated < old_allocated) /* integer overflow? */ + abort (); + { + UNIT *larger_result; + if (result == NULL) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail1; + } + } + else if (result == resultbuf) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail1; + } + U_CPY (larger_result, resultbuf, length); + } + else + { + larger_result = + (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail1; + } + } + result = larger_result; + allocated = new_allocated; + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail1; + } + if (ret < 0) + abort (); + length += ret; + goto done_appending; + } + } + } + done_appending: ; + } + } + + if (!uc_is_case_ignorable (uc)) + last_char_except_ignorable = uc; + + { + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + last_char_normal_or_above = uc; + } + + s += count; + wp += count; } } @@ -452,7 +452,7 @@ FUNC (const UNIT *s, size_t n, normalized_result = U_NORMALIZE (nf, result, length, resultbuf, lengthp); if (normalized_result == NULL) - goto fail2; + goto fail2; free (result); return normalized_result; @@ -461,15 +461,15 @@ FUNC (const UNIT *s, size_t n, if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - goto fail2; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + goto fail2; + } + } } else if (result != resultbuf && length < allocated) { @@ -478,7 +478,7 @@ FUNC (const UNIT *s, size_t n, memory = (UNIT *) realloc (result, length * sizeof (UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unicase/u-is-cased.h b/lib/unicase/u-is-cased.h index b96a60f0c..de007f5a1 100644 --- a/lib/unicase/u-is-cased.h +++ b/lib/unicase/u-is-cased.h @@ -39,30 +39,30 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, /* Apply toupper mapping. */ mapped_toupper = U_TOUPPER (norms, norms_length, iso639_language, NULL, - mappedbuf, &mapped_length); + mappedbuf, &mapped_length); if (mapped_toupper == NULL) goto fail; /* Compare. */ if (!(mapped_length == norms_length - && U_CMP (mapped_toupper, norms, norms_length) == 0)) + && U_CMP (mapped_toupper, norms, norms_length) == 0)) { if (mapped_toupper != mappedbuf) - free (mapped_toupper); + free (mapped_toupper); goto yes; } /* Apply tolower mapping. */ mapped_tolower = U_TOLOWER (norms, norms_length, iso639_language, NULL, - mapped_toupper, &mapped_length); + mapped_toupper, &mapped_length); if (mapped_tolower == NULL) { if (mapped_toupper != mappedbuf) - { - int saved_errno = errno; - free (mapped_toupper); - errno = saved_errno; - } + { + int saved_errno = errno; + free (mapped_toupper); + errno = saved_errno; + } goto fail; } @@ -71,24 +71,24 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, /* Compare. */ if (!(mapped_length == norms_length - && U_CMP (mapped_tolower, norms, norms_length) == 0)) + && U_CMP (mapped_tolower, norms, norms_length) == 0)) { if (mapped_tolower != mappedbuf) - free (mapped_tolower); + free (mapped_tolower); goto yes; } /* Apply totitle mapping. */ mapped_totitle = U_TOTITLE (norms, norms_length, iso639_language, NULL, - mapped_tolower, &mapped_length); + mapped_tolower, &mapped_length); if (mapped_totitle == NULL) { if (mapped_tolower != mappedbuf) - { - int saved_errno = errno; - free (mapped_tolower); - errno = saved_errno; - } + { + int saved_errno = errno; + free (mapped_tolower); + errno = saved_errno; + } goto fail; } @@ -97,10 +97,10 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, /* Compare. */ if (!(mapped_length == norms_length - && U_CMP (mapped_totitle, norms, norms_length) == 0)) + && U_CMP (mapped_totitle, norms, norms_length) == 0)) { if (mapped_totitle != mappedbuf) - free (mapped_totitle); + free (mapped_totitle); goto yes; } diff --git a/lib/unicase/u-is-invariant.h b/lib/unicase/u-is-invariant.h index e6b7fbb41..33f23bcd4 100644 --- a/lib/unicase/u-is-invariant.h +++ b/lib/unicase/u-is-invariant.h @@ -18,8 +18,8 @@ int FUNC (const UNIT *s, size_t n, UNIT * (*mapping) (const UNIT *s, size_t n, const char *iso639_language, - uninorm_t nf, - UNIT *resultbuf, size_t *lengthp), + uninorm_t nf, + UNIT *resultbuf, size_t *lengthp), const char *iso639_language, bool *resultp) { @@ -40,21 +40,21 @@ FUNC (const UNIT *s, size_t n, /* Apply mapping. */ mapped_length = sizeof (mappedbuf) / sizeof (UNIT); mapped = mapping (norms, norms_length, iso639_language, NULL, - mappedbuf, &mapped_length); + mappedbuf, &mapped_length); if (mapped == NULL) { if (norms != normsbuf) - { - int saved_errno = errno; - free (norms); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms); + errno = saved_errno; + } return -1; } /* Compare. */ *resultp = (mapped_length == norms_length - && U_CMP (mapped, norms, norms_length) == 0); + && U_CMP (mapped, norms, norms_length) == 0); if (mapped != mappedbuf) free (mapped); diff --git a/lib/unicase/u-prefix-context.h b/lib/unicase/u-prefix-context.h index e58b4114e..85b9448d3 100644 --- a/lib/unicase/u-prefix-context.h +++ b/lib/unicase/u-prefix-context.h @@ -35,12 +35,12 @@ FUNC2 (const UNIT *s, size_t n, casing_prefix_context_t a_context) int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); if (!uc_is_case_ignorable (uc)) - context.last_char_except_ignorable = uc; + context.last_char_except_ignorable = uc; { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - context.last_char_normal_or_above = uc; + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + context.last_char_normal_or_above = uc; } s += count; @@ -59,24 +59,24 @@ FUNC2 (const UNIT *s, size_t n, casing_prefix_context_t a_context) ucs4_t uc; p = U_PREV (&uc, p, s); if (p == NULL) - break; + break; if (last_char_except_ignorable == (ucs4_t)(-1)) - { - if (!uc_is_case_ignorable (uc)) - last_char_except_ignorable = uc; - } + { + if (!uc_is_case_ignorable (uc)) + last_char_except_ignorable = uc; + } if (last_char_normal_or_above == (ucs4_t)(-1)) - { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - last_char_normal_or_above = uc; - } + { + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + last_char_normal_or_above = uc; + } if (last_char_except_ignorable != (ucs4_t)(-1) - && last_char_normal_or_above != (ucs4_t)(-1)) - break; + && last_char_normal_or_above != (ucs4_t)(-1)) + break; } context.last_char_except_ignorable = (last_char_except_ignorable != (ucs4_t)(-1) diff --git a/lib/unicase/u-suffix-context.h b/lib/unicase/u-suffix-context.h index a8880953b..37fc8ea13 100644 --- a/lib/unicase/u-suffix-context.h +++ b/lib/unicase/u-suffix-context.h @@ -39,36 +39,36 @@ FUNC2 (const UNIT *s, size_t n, casing_suffix_context_t a_context) int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); if (first_char_except_ignorable == (ucs4_t)(-1)) - { - if (!uc_is_case_ignorable (uc)) - first_char_except_ignorable = uc; - } + { + if (!uc_is_case_ignorable (uc)) + first_char_except_ignorable = uc; + } if (scc_MORE_ABOVE < 0) - { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A) - scc_MORE_ABOVE = SCC_MORE_ABOVE_MASK; - else if (ccc == UC_CCC_NR) - scc_MORE_ABOVE = 0; - } + { + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A) + scc_MORE_ABOVE = SCC_MORE_ABOVE_MASK; + else if (ccc == UC_CCC_NR) + scc_MORE_ABOVE = 0; + } if (scc_BEFORE_DOT < 0) - { - if (uc == 0x0307) /* COMBINING DOT ABOVE */ - scc_BEFORE_DOT = SCC_BEFORE_DOT_MASK; - else - { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - scc_BEFORE_DOT = 0; - } - } + { + if (uc == 0x0307) /* COMBINING DOT ABOVE */ + scc_BEFORE_DOT = SCC_BEFORE_DOT_MASK; + else + { + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + scc_BEFORE_DOT = 0; + } + } if (first_char_except_ignorable != (ucs4_t)(-1) - && (scc_MORE_ABOVE | scc_BEFORE_DOT) >= 0) - /* All conditions have been determined. */ - break; + && (scc_MORE_ABOVE | scc_BEFORE_DOT) >= 0) + /* All conditions have been determined. */ + break; s += count; } diff --git a/lib/unicase/u-totitle.h b/lib/unicase/u-totitle.h index 431f000ae..a02859f75 100644 --- a/lib/unicase/u-totitle.h +++ b/lib/unicase/u-totitle.h @@ -21,8 +21,8 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, UNIT *resultbuf, size_t *lengthp) { return U_CT_TOTITLE (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-ct-tolower.c b/lib/unicase/u16-ct-tolower.c index 36b34e040..c924009bb 100644 --- a/lib/unicase/u16-ct-tolower.c +++ b/lib/unicase/u16-ct-tolower.c @@ -27,14 +27,14 @@ uint16_t * u16_ct_tolower (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-ct-toupper.c b/lib/unicase/u16-ct-toupper.c index 029c74b46..8ffff9a07 100644 --- a/lib/unicase/u16-ct-toupper.c +++ b/lib/unicase/u16-ct-toupper.c @@ -27,14 +27,14 @@ uint16_t * u16_ct_toupper (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-is-casefolded.c b/lib/unicase/u16-is-casefolded.c index 64a4ec18e..8dca6f843 100644 --- a/lib/unicase/u16-is-casefolded.c +++ b/lib/unicase/u16-is-casefolded.c @@ -24,7 +24,7 @@ int u16_is_casefolded (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_casefold, iso639_language, resultp); } diff --git a/lib/unicase/u16-is-lowercase.c b/lib/unicase/u16-is-lowercase.c index 36a015125..f5dd971ba 100644 --- a/lib/unicase/u16-is-lowercase.c +++ b/lib/unicase/u16-is-lowercase.c @@ -24,7 +24,7 @@ int u16_is_lowercase (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_tolower, iso639_language, resultp); } diff --git a/lib/unicase/u16-is-titlecase.c b/lib/unicase/u16-is-titlecase.c index 19aacea1f..679b64fa1 100644 --- a/lib/unicase/u16-is-titlecase.c +++ b/lib/unicase/u16-is-titlecase.c @@ -24,7 +24,7 @@ int u16_is_titlecase (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_totitle, iso639_language, resultp); } diff --git a/lib/unicase/u16-is-uppercase.c b/lib/unicase/u16-is-uppercase.c index 53e697fd2..31620bbdb 100644 --- a/lib/unicase/u16-is-uppercase.c +++ b/lib/unicase/u16-is-uppercase.c @@ -24,7 +24,7 @@ int u16_is_uppercase (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_toupper, iso639_language, resultp); } diff --git a/lib/unicase/u16-tolower.c b/lib/unicase/u16-tolower.c index 0629cb4d2..7bf982019 100644 --- a/lib/unicase/u16-tolower.c +++ b/lib/unicase/u16-tolower.c @@ -27,13 +27,13 @@ uint16_t * u16_tolower (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-toupper.c b/lib/unicase/u16-toupper.c index f92989aa2..475f618e4 100644 --- a/lib/unicase/u16-toupper.c +++ b/lib/unicase/u16-toupper.c @@ -27,13 +27,13 @@ uint16_t * u16_toupper (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-ct-tolower.c b/lib/unicase/u32-ct-tolower.c index 83e9fa842..876219c4b 100644 --- a/lib/unicase/u32-ct-tolower.c +++ b/lib/unicase/u32-ct-tolower.c @@ -27,14 +27,14 @@ uint32_t * u32_ct_tolower (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-ct-toupper.c b/lib/unicase/u32-ct-toupper.c index 9043ddebe..d245b23dc 100644 --- a/lib/unicase/u32-ct-toupper.c +++ b/lib/unicase/u32-ct-toupper.c @@ -27,14 +27,14 @@ uint32_t * u32_ct_toupper (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-is-casefolded.c b/lib/unicase/u32-is-casefolded.c index a71c767da..3abb7f692 100644 --- a/lib/unicase/u32-is-casefolded.c +++ b/lib/unicase/u32-is-casefolded.c @@ -24,7 +24,7 @@ int u32_is_casefolded (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_casefold, iso639_language, resultp); } diff --git a/lib/unicase/u32-is-lowercase.c b/lib/unicase/u32-is-lowercase.c index 104afaae9..d4eb8b68e 100644 --- a/lib/unicase/u32-is-lowercase.c +++ b/lib/unicase/u32-is-lowercase.c @@ -24,7 +24,7 @@ int u32_is_lowercase (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_tolower, iso639_language, resultp); } diff --git a/lib/unicase/u32-is-titlecase.c b/lib/unicase/u32-is-titlecase.c index 5b07c8dd0..ad66edb2d 100644 --- a/lib/unicase/u32-is-titlecase.c +++ b/lib/unicase/u32-is-titlecase.c @@ -24,7 +24,7 @@ int u32_is_titlecase (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_totitle, iso639_language, resultp); } diff --git a/lib/unicase/u32-is-uppercase.c b/lib/unicase/u32-is-uppercase.c index bb38fc69d..c94c10ea8 100644 --- a/lib/unicase/u32-is-uppercase.c +++ b/lib/unicase/u32-is-uppercase.c @@ -24,7 +24,7 @@ int u32_is_uppercase (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_toupper, iso639_language, resultp); } diff --git a/lib/unicase/u32-tolower.c b/lib/unicase/u32-tolower.c index daa5c4d36..b22f9155e 100644 --- a/lib/unicase/u32-tolower.c +++ b/lib/unicase/u32-tolower.c @@ -27,13 +27,13 @@ uint32_t * u32_tolower (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-toupper.c b/lib/unicase/u32-toupper.c index 3430ad952..b7f857a88 100644 --- a/lib/unicase/u32-toupper.c +++ b/lib/unicase/u32-toupper.c @@ -27,13 +27,13 @@ uint32_t * u32_toupper (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u8-casefold.c b/lib/unicase/u8-casefold.c index 321081372..39254a096 100644 --- a/lib/unicase/u8-casefold.c +++ b/lib/unicase/u8-casefold.c @@ -47,28 +47,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -92,9 +92,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_casefold ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_casefold ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/u8-ct-tolower.c b/lib/unicase/u8-ct-tolower.c index 3755821e3..c212d732a 100644 --- a/lib/unicase/u8-ct-tolower.c +++ b/lib/unicase/u8-ct-tolower.c @@ -27,14 +27,14 @@ uint8_t * u8_ct_tolower (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u8-ct-toupper.c b/lib/unicase/u8-ct-toupper.c index 9dca2fcac..252b1a716 100644 --- a/lib/unicase/u8-ct-toupper.c +++ b/lib/unicase/u8-ct-toupper.c @@ -27,14 +27,14 @@ uint8_t * u8_ct_toupper (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u8-is-casefolded.c b/lib/unicase/u8-is-casefolded.c index 30122b785..66f261e83 100644 --- a/lib/unicase/u8-is-casefolded.c +++ b/lib/unicase/u8-is-casefolded.c @@ -24,7 +24,7 @@ int u8_is_casefolded (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_casefold, iso639_language, resultp); } diff --git a/lib/unicase/u8-is-lowercase.c b/lib/unicase/u8-is-lowercase.c index 5b0df8be7..018c495fa 100644 --- a/lib/unicase/u8-is-lowercase.c +++ b/lib/unicase/u8-is-lowercase.c @@ -24,7 +24,7 @@ int u8_is_lowercase (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_tolower, iso639_language, resultp); } diff --git a/lib/unicase/u8-is-titlecase.c b/lib/unicase/u8-is-titlecase.c index 474502a72..a0a339309 100644 --- a/lib/unicase/u8-is-titlecase.c +++ b/lib/unicase/u8-is-titlecase.c @@ -24,7 +24,7 @@ int u8_is_titlecase (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_totitle, iso639_language, resultp); } diff --git a/lib/unicase/u8-is-uppercase.c b/lib/unicase/u8-is-uppercase.c index 7f14f9249..2613c292b 100644 --- a/lib/unicase/u8-is-uppercase.c +++ b/lib/unicase/u8-is-uppercase.c @@ -24,7 +24,7 @@ int u8_is_uppercase (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_toupper, iso639_language, resultp); } diff --git a/lib/unicase/u8-tolower.c b/lib/unicase/u8-tolower.c index 1cd7cfa43..456d0f540 100644 --- a/lib/unicase/u8-tolower.c +++ b/lib/unicase/u8-tolower.c @@ -27,15 +27,15 @@ uint8_t * u8_tolower (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } @@ -60,28 +60,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -105,9 +105,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_tolower ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_tolower ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/u8-totitle.c b/lib/unicase/u8-totitle.c index cf29c1bab..925e23d7d 100644 --- a/lib/unicase/u8-totitle.c +++ b/lib/unicase/u8-totitle.c @@ -47,28 +47,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -92,9 +92,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_toupper ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_toupper ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/u8-toupper.c b/lib/unicase/u8-toupper.c index a97d98ce5..ad1061313 100644 --- a/lib/unicase/u8-toupper.c +++ b/lib/unicase/u8-toupper.c @@ -27,15 +27,15 @@ uint8_t * u8_toupper (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } @@ -60,28 +60,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -105,9 +105,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_toupper ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_toupper ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/ulc-casecmp.c b/lib/unicase/ulc-casecmp.c index e07102190..3fd8dfcd5 100644 --- a/lib/unicase/ulc-casecmp.c +++ b/lib/unicase/ulc-casecmp.c @@ -30,8 +30,8 @@ static uint8_t * ulc_u8_casefold (const char *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { uint8_t convbuf[2048 / sizeof (uint8_t)]; uint8_t *conv; @@ -42,22 +42,22 @@ ulc_u8_casefold (const char *s, size_t n, const char *iso639_language, conv_length = sizeof (convbuf) / sizeof (uint8_t); conv = u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL, - convbuf, &conv_length); + convbuf, &conv_length); if (conv == NULL) /* errno is set here. */ return NULL; /* Case-fold and normalize. */ result = u8_casefold (conv, conv_length, iso639_language, nf, - resultbuf, lengthp); + resultbuf, lengthp); if (result == NULL) { if (conv != convbuf) - { - int saved_errno = errno; - free (conv); - errno = saved_errno; - } + { + int saved_errno = errno; + free (conv); + errno = saved_errno; + } return NULL; } diff --git a/lib/unicase/ulc-casexfrm.c b/lib/unicase/ulc-casexfrm.c index aded556fe..883b98d96 100644 --- a/lib/unicase/ulc-casexfrm.c +++ b/lib/unicase/ulc-casexfrm.c @@ -27,8 +27,8 @@ char * ulc_casexfrm (const char *s, size_t n, const char *iso639_language, - uninorm_t nf, - char *resultbuf, size_t *lengthp) + uninorm_t nf, + char *resultbuf, size_t *lengthp) { uint8_t convbuf[2048 / sizeof (uint8_t)]; uint8_t *conv; @@ -39,22 +39,22 @@ ulc_casexfrm (const char *s, size_t n, const char *iso639_language, conv_length = sizeof (convbuf) / sizeof (uint8_t); conv = u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL, - convbuf, &conv_length); + convbuf, &conv_length); if (conv == NULL) /* errno is set here. */ return NULL; /* Case-fold and normalize. */ result = u8_casexfrm (conv, conv_length, iso639_language, nf, - resultbuf, lengthp); + resultbuf, lengthp); if (result == NULL) { if (conv != convbuf) - { - int saved_errno = errno; - free (conv); - errno = saved_errno; - } + { + int saved_errno = errno; + free (conv); + errno = saved_errno; + } return NULL; } diff --git a/lib/unicase/unicasemap.h b/lib/unicase/unicasemap.h index 8da8c51d2..14d1b467f 100644 --- a/lib/unicase/unicasemap.h +++ b/lib/unicase/unicasemap.h @@ -23,30 +23,30 @@ extern uint8_t * u8_casemap (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - ucs4_t (*single_character_map) (ucs4_t), - size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + ucs4_t (*single_character_map) (ucs4_t), + size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_casemap (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - ucs4_t (*single_character_map) (ucs4_t), - size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + ucs4_t (*single_character_map) (ucs4_t), + size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_casemap (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - ucs4_t (*single_character_map) (ucs4_t), - size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + ucs4_t (*single_character_map) (ucs4_t), + size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); diff --git a/lib/unicodeio.c b/lib/unicodeio.c index b6fd658ee..79cfbacaa 100644 --- a/lib/unicodeio.c +++ b/lib/unicodeio.c @@ -63,11 +63,11 @@ Assumes that the locale doesn't change between two calls. */ long unicode_to_mb (unsigned int code, - long (*success) (const char *buf, size_t buflen, - void *callback_arg), - long (*failure) (unsigned int code, const char *msg, - void *callback_arg), - void *callback_arg) + long (*success) (const char *buf, size_t buflen, + void *callback_arg), + long (*failure) (unsigned int code, const char *msg, + void *callback_arg), + void *callback_arg) { static int initialized; static int is_utf8; @@ -85,12 +85,12 @@ unicode_to_mb (unsigned int code, is_utf8 = !strcmp (charset, UTF8_NAME); #if HAVE_ICONV if (!is_utf8) - { - utf8_to_local = iconv_open (charset, UTF8_NAME); - if (utf8_to_local == (iconv_t)(-1)) - /* For an unknown encoding, assume ASCII. */ - utf8_to_local = iconv_open ("ASCII", UTF8_NAME); - } + { + utf8_to_local = iconv_open (charset, UTF8_NAME); + if (utf8_to_local == (iconv_t)(-1)) + /* For an unknown encoding, assume ASCII. */ + utf8_to_local = iconv_open ("ASCII", UTF8_NAME); + } #endif initialized = 1; } @@ -100,7 +100,7 @@ unicode_to_mb (unsigned int code, { #if HAVE_ICONV if (utf8_to_local == (iconv_t)(-1)) - return failure (code, N_("iconv function not usable"), callback_arg); + return failure (code, N_("iconv function not usable"), callback_arg); #else return failure (code, N_("iconv function not available"), callback_arg); #endif @@ -128,15 +128,15 @@ unicode_to_mb (unsigned int code, /* Convert the character from UTF-8 to the locale's charset. */ res = iconv (utf8_to_local, - (ICONV_CONST char **)&inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **)&inptr, &inbytesleft, + &outptr, &outbytesleft); if (inbytesleft > 0 || res == (size_t)(-1) - /* Irix iconv() inserts a NUL byte if it cannot convert. */ + /* Irix iconv() inserts a NUL byte if it cannot convert. */ # if !defined _LIBICONV_VERSION && (defined sgi || defined __sgi) - || (res > 0 && code != 0 && outptr - outbuf == 1 && *outbuf == '\0') + || (res > 0 && code != 0 && outptr - outbuf == 1 && *outbuf == '\0') # endif ) - return failure (code, NULL, callback_arg); + return failure (code, NULL, callback_arg); /* Avoid glibc-2.1 bug and Solaris 7 bug. */ # if defined _LIBICONV_VERSION \ @@ -145,7 +145,7 @@ unicode_to_mb (unsigned int code, /* Get back to the initial shift state. */ res = iconv (utf8_to_local, NULL, NULL, &outptr, &outbytesleft); if (res == (size_t)(-1)) - return failure (code, NULL, callback_arg); + return failure (code, NULL, callback_arg); # endif return success (outbuf, outptr - outbuf, callback_arg); @@ -174,13 +174,13 @@ fwrite_success_callback (const char *buf, size_t buflen, void *callback_arg) /* Simple failure callback that displays an error and exits. */ static long exit_failure_callback (unsigned int code, const char *msg, - void *callback_arg _UNUSED_PARAMETER_) + void *callback_arg _UNUSED_PARAMETER_) { if (msg == NULL) error (1, 0, _("cannot convert U+%04X to local character set"), code); else error (1, 0, _("cannot convert U+%04X to local character set: %s"), code, - gettext (msg)); + gettext (msg)); return -1; } @@ -188,8 +188,8 @@ exit_failure_callback (unsigned int code, const char *msg, ASCII, using the same notation as ISO C99 strings. */ static long fallback_failure_callback (unsigned int code, - const char *msg _UNUSED_PARAMETER_, - void *callback_arg) + const char *msg _UNUSED_PARAMETER_, + void *callback_arg) { FILE *stream = (FILE *) callback_arg; @@ -207,8 +207,8 @@ void print_unicode_char (FILE *stream, unsigned int code, int exit_on_error) { unicode_to_mb (code, fwrite_success_callback, - exit_on_error - ? exit_failure_callback - : fallback_failure_callback, - stream); + exit_on_error + ? exit_failure_callback + : fallback_failure_callback, + stream); } diff --git a/lib/unicodeio.h b/lib/unicodeio.h index 5a3400ddf..b9b0206ee 100644 --- a/lib/unicodeio.h +++ b/lib/unicodeio.h @@ -28,21 +28,21 @@ Returns whatever the callback returned. Assumes that the locale doesn't change between two calls. */ extern long unicode_to_mb (unsigned int code, - long (*success) (const char *buf, size_t buflen, - void *callback_arg), - long (*failure) (unsigned int code, const char *msg, - void *callback_arg), - void *callback_arg); + long (*success) (const char *buf, size_t buflen, + void *callback_arg), + long (*failure) (unsigned int code, const char *msg, + void *callback_arg), + void *callback_arg); /* Outputs the Unicode character CODE to the output stream STREAM. Upon failure, exit if exit_on_error is true, otherwise output a fallback notation. */ extern void print_unicode_char (FILE *stream, unsigned int code, - int exit_on_error); + int exit_on_error); /* Simple success callback that outputs the converted string. The STREAM is passed as callback_arg. */ extern long fwrite_success_callback (const char *buf, size_t buflen, - void *callback_arg); + void *callback_arg); #endif diff --git a/lib/uniconv.h b/lib/uniconv.h index c7d362a6e..13fbfb01c 100644 --- a/lib/uniconv.h +++ b/lib/uniconv.h @@ -58,22 +58,22 @@ extern "C" { values: EINVAL, EILSEQ, ENOMEM. */ extern uint8_t * u8_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint8_t *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint16_t *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint32_t *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint32_t *resultbuf, size_t *lengthp); /* Converts an entire Unicode string, possibly including NUL units, from a Unicode encoding to a given encoding. @@ -95,54 +95,54 @@ extern uint32_t * values: EINVAL, EILSEQ, ENOMEM. */ extern char * u8_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint8_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const uint8_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp); extern char * u16_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint16_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const uint16_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp); extern char * u32_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint32_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const uint32_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp); /* Converts a NUL terminated string from a given encoding. The result is malloc allocated, or NULL (with errno set) in case of error. Particular errno values: EILSEQ, ENOMEM. */ extern uint8_t * u8_strconv_from_encoding (const char *string, - const char *fromcode, - enum iconv_ilseq_handler handler); + const char *fromcode, + enum iconv_ilseq_handler handler); extern uint16_t * u16_strconv_from_encoding (const char *string, - const char *fromcode, - enum iconv_ilseq_handler handler); + const char *fromcode, + enum iconv_ilseq_handler handler); extern uint32_t * u32_strconv_from_encoding (const char *string, - const char *fromcode, - enum iconv_ilseq_handler handler); + const char *fromcode, + enum iconv_ilseq_handler handler); /* Converts a NUL terminated string to a given encoding. The result is malloc allocated, or NULL (with errno set) in case of error. Particular errno values: EILSEQ, ENOMEM. */ extern char * u8_strconv_to_encoding (const uint8_t *string, - const char *tocode, - enum iconv_ilseq_handler handler); + const char *tocode, + enum iconv_ilseq_handler handler); extern char * u16_strconv_to_encoding (const uint16_t *string, - const char *tocode, - enum iconv_ilseq_handler handler); + const char *tocode, + enum iconv_ilseq_handler handler); extern char * u32_strconv_to_encoding (const uint32_t *string, - const char *tocode, - enum iconv_ilseq_handler handler); + const char *tocode, + enum iconv_ilseq_handler handler); /* Converts a NUL terminated string from the locale encoding. The result is malloc allocated, or NULL (with errno set) in case of error. diff --git a/lib/uniconv/u-conv-from-enc.h b/lib/uniconv/u-conv-from-enc.h index fa0f0d3dc..aefade5bb 100644 --- a/lib/uniconv/u-conv-from-enc.h +++ b/lib/uniconv/u-conv-from-enc.h @@ -26,7 +26,7 @@ FUNC (const char *fromcode, size_t length = *lengthp * sizeof (UNIT); if (mem_iconveha (src, srclen, fromcode, UTF_NAME, true, handler, - offsets, &result, &length) < 0) + offsets, &result, &length) < 0) return NULL; if (offsets != NULL) { @@ -35,8 +35,8 @@ FUNC (const char *fromcode, size_t *o; for (o = offsets; o < offsets_end; o++) - if (*o != (size_t)(-1)) - *o = *o / sizeof (UNIT); + if (*o != (size_t)(-1)) + *o = *o / sizeof (UNIT); } if ((length % sizeof (UNIT)) != 0) abort (); @@ -49,7 +49,7 @@ FUNC (const char *fromcode, utf8_string = u8_conv_from_encoding (fromcode, handler, src, srclen, offsets, - NULL, &utf8_length); + NULL, &utf8_length); if (utf8_string == NULL) return NULL; result = U8_TO_U (utf8_string, utf8_length, resultbuf, lengthp); @@ -65,25 +65,25 @@ FUNC (const char *fromcode, size_t length = *lengthp; size_t *offsets_end = offsets + srclen; size_t *o; - size_t off8 = 0; /* offset into utf8_string */ - size_t offunit = 0; /* offset into result */ + size_t off8 = 0; /* offset into utf8_string */ + size_t offunit = 0; /* offset into result */ for (o = offsets; o < offsets_end; o++) - if (*o != (size_t)(-1)) - { - while (off8 < *o) - { - int count8 = u8_mblen (utf8_string + off8, utf8_length - off8); - int countunit = U_MBLEN (result + offunit, length - offunit); - if (count8 < 0 || countunit < 0) - abort (); - off8 += count8; - offunit += countunit; - } - if (*o != off8) - abort (); - *o = offunit; - } + if (*o != (size_t)(-1)) + { + while (off8 < *o) + { + int count8 = u8_mblen (utf8_string + off8, utf8_length - off8); + int countunit = U_MBLEN (result + offunit, length - offunit); + if (count8 < 0 || countunit < 0) + abort (); + off8 += count8; + offunit += countunit; + } + if (*o != off8) + abort (); + *o = offunit; + } } free (utf8_string); return result; diff --git a/lib/uniconv/u-conv-to-enc.h b/lib/uniconv/u-conv-to-enc.h index ed715482a..7478d94e5 100644 --- a/lib/uniconv/u-conv-to-enc.h +++ b/lib/uniconv/u-conv-to-enc.h @@ -29,12 +29,12 @@ FUNC (const char *tocode, if (offsets != NULL && srclen > 0) { scaled_offsets = - (size_t *) malloc (srclen * sizeof (UNIT) * sizeof (size_t)); + (size_t *) malloc (srclen * sizeof (UNIT) * sizeof (size_t)); if (scaled_offsets == NULL) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } } else scaled_offsets = NULL; @@ -42,9 +42,9 @@ FUNC (const char *tocode, result = resultbuf; length = *lengthp; if (mem_iconveha ((const char *) src, srclen * sizeof (UNIT), - UTF_NAME, tocode, - handler == iconveh_question_mark, handler, - scaled_offsets, &result, &length) < 0) + UTF_NAME, tocode, + handler == iconveh_question_mark, handler, + scaled_offsets, &result, &length) < 0) { int saved_errno = errno; free (scaled_offsets); @@ -55,11 +55,11 @@ FUNC (const char *tocode, if (offsets != NULL) { /* Convert scaled_offsets[srclen * sizeof (UNIT)] to - offsets[srclen]. */ + offsets[srclen]. */ size_t i; for (i = 0; i < srclen; i++) - offsets[i] = scaled_offsets[i * sizeof (UNIT)]; + offsets[i] = scaled_offsets[i * sizeof (UNIT)]; free (scaled_offsets); } @@ -67,10 +67,10 @@ FUNC (const char *tocode, { result = (char *) malloc (1); if (result == NULL) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } } *lengthp = length; return result; @@ -91,62 +91,62 @@ FUNC (const char *tocode, { scaled_offsets = (size_t *) malloc (utf8_srclen * sizeof (size_t)); if (scaled_offsets == NULL) - { - if (utf8_src != tmpbuf) - free (utf8_src); - errno = ENOMEM; - return NULL; - } + { + if (utf8_src != tmpbuf) + free (utf8_src); + errno = ENOMEM; + return NULL; + } } else scaled_offsets = NULL; result = u8_conv_to_encoding (tocode, handler, utf8_src, utf8_srclen, - scaled_offsets, resultbuf, lengthp); + scaled_offsets, resultbuf, lengthp); if (result == NULL) { int saved_errno = errno; free (scaled_offsets); if (utf8_src != tmpbuf) - free (utf8_src); + free (utf8_src); errno = saved_errno; return NULL; } if (offsets != NULL) { - size_t iunit; /* offset into src */ - size_t i8; /* offset into utf8_src */ + size_t iunit; /* offset into src */ + size_t i8; /* offset into utf8_src */ for (iunit = 0; iunit < srclen; iunit++) - offsets[iunit] = (size_t)(-1); + offsets[iunit] = (size_t)(-1); iunit = 0; i8 = 0; while (iunit < srclen && i8 < utf8_srclen) - { - int countunit; - int count8; - - offsets[iunit] = scaled_offsets[i8]; - - countunit = U_MBLEN (src + iunit, srclen - iunit); - count8 = u8_mblen (utf8_src + i8, utf8_srclen - i8); - if (countunit < 0 || count8 < 0) - abort (); - iunit += countunit; - i8 += count8; - } + { + int countunit; + int count8; + + offsets[iunit] = scaled_offsets[i8]; + + countunit = U_MBLEN (src + iunit, srclen - iunit); + count8 = u8_mblen (utf8_src + i8, utf8_srclen - i8); + if (countunit < 0 || count8 < 0) + abort (); + iunit += countunit; + i8 += count8; + } /* Check that utf8_src has been traversed entirely. */ if (i8 < utf8_srclen) - abort (); + abort (); /* Check that src has been traversed entirely, except possibly for an - incomplete sequence of units at the end. */ + incomplete sequence of units at the end. */ if (iunit < srclen) - { - offsets[iunit] = *lengthp; - if (!(U_MBLEN (src + iunit, srclen - iunit) < 0)) - abort (); - } + { + offsets[iunit] = *lengthp; + if (!(U_MBLEN (src + iunit, srclen - iunit) < 0)) + abort (); + } free (scaled_offsets); } if (utf8_src != tmpbuf) diff --git a/lib/uniconv/u-strconv-from-enc.h b/lib/uniconv/u-strconv-from-enc.h index 25813c76d..667f344ab 100644 --- a/lib/uniconv/u-strconv-from-enc.h +++ b/lib/uniconv/u-strconv-from-enc.h @@ -24,13 +24,13 @@ FUNC (const char *string, result = U_CONV_FROM_ENCODING (fromcode, handler, - string, strlen (string) + 1, NULL, - NULL, &length); + string, strlen (string) + 1, NULL, + NULL, &length); if (result == NULL) return NULL; /* Verify the result has exactly one NUL unit, at the end. */ if (!(length > 0 && result[length-1] == 0 - && U_STRLEN (result) == length-1)) + && U_STRLEN (result) == length-1)) { free (result); errno = EILSEQ; diff --git a/lib/uniconv/u-strconv-to-enc.h b/lib/uniconv/u-strconv-to-enc.h index b6e6ebb5d..d4f63905e 100644 --- a/lib/uniconv/u-strconv-to-enc.h +++ b/lib/uniconv/u-strconv-to-enc.h @@ -24,9 +24,9 @@ FUNC (const UNIT *string, size_t length = 0; if (mem_iconveha ((const char *) string, (U_STRLEN (string) + 1) * sizeof (UNIT), - UTF_NAME, tocode, - handler == iconveh_question_mark, handler, - NULL, &result, &length) < 0) + UTF_NAME, tocode, + handler == iconveh_question_mark, handler, + NULL, &result, &length) < 0) return NULL; /* Verify the result has exactly one NUL byte, at the end. */ if (!(length > 0 && result[length-1] == '\0' && strlen (result) == length-1)) @@ -49,11 +49,11 @@ FUNC (const UNIT *string, if (result == NULL) { if (utf8_string != tmpbuf) - { - int saved_errno = errno; - free (utf8_string); - errno = saved_errno; - } + { + int saved_errno = errno; + free (utf8_string); + errno = saved_errno; + } return NULL; } if (utf8_string != tmpbuf) diff --git a/lib/uniconv/u16-conv-to-enc.c b/lib/uniconv/u16-conv-to-enc.c index ba70736cf..4865a1ea6 100644 --- a/lib/uniconv/u16-conv-to-enc.c +++ b/lib/uniconv/u16-conv-to-enc.c @@ -81,69 +81,69 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ count = u16_mbtoucr (&uc, s, s_end - s); if (count < 0) - { - if (count == -2) - /* Incomplete sequence of units. */ - break; - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (count == -2) + /* Incomplete sequence of units. */ + break; + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ count = u8_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 6 > allocated) - allocated = length + 6; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u8_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 6 > allocated) + allocated = length + 6; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u8_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -152,7 +152,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/uniconv/u8-conv-from-enc.c b/lib/uniconv/u8-conv-from-enc.c index 7605e63e7..59248388c 100644 --- a/lib/uniconv/u8-conv-from-enc.c +++ b/lib/uniconv/u8-conv-from-enc.c @@ -31,10 +31,10 @@ uint8_t * u8_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint8_t *resultbuf, size_t *lengthp) + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint8_t *resultbuf, size_t *lengthp) { if (STRCASEEQ (fromcode, "UTF-8", 'U','T','F','-','8',0,0,0,0)) { @@ -42,40 +42,40 @@ u8_conv_from_encoding (const char *fromcode, uint8_t *result; if (u8_check ((const uint8_t *) src, srclen)) - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } if (offsets != NULL) - { - size_t i; - - for (i = 0; i < srclen; ) - { - int count = u8_mblen ((const uint8_t *) src + i, srclen - i); - /* We can rely on count > 0 because of the previous u8_check. */ - if (count <= 0) - abort (); - offsets[i] = i; - i++; - while (--count > 0) - offsets[i++] = (size_t)(-1); - } - } + { + size_t i; + + for (i = 0; i < srclen; ) + { + int count = u8_mblen ((const uint8_t *) src + i, srclen - i); + /* We can rely on count > 0 because of the previous u8_check. */ + if (count <= 0) + abort (); + offsets[i] = i; + i++; + while (--count > 0) + offsets[i++] = (size_t)(-1); + } + } /* Memory allocation. */ if (resultbuf != NULL && *lengthp >= srclen) - result = resultbuf; + result = resultbuf; else - { - result = (uint8_t *) malloc (srclen > 0 ? srclen : 1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (uint8_t *) malloc (srclen > 0 ? srclen : 1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } memcpy ((char *) result, src, srclen); *lengthp = srclen; @@ -87,18 +87,18 @@ u8_conv_from_encoding (const char *fromcode, size_t length = *lengthp; if (mem_iconveha (src, srclen, fromcode, "UTF-8", true, handler, - offsets, &result, &length) < 0) - return NULL; + offsets, &result, &length) < 0) + return NULL; if (result == NULL) /* when (resultbuf == NULL && length == 0) */ - { - result = (char *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (char *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } *lengthp = length; return (uint8_t *) result; } diff --git a/lib/uniconv/u8-conv-to-enc.c b/lib/uniconv/u8-conv-to-enc.c index 90acccec1..29a8a534d 100644 --- a/lib/uniconv/u8-conv-to-enc.c +++ b/lib/uniconv/u8-conv-to-enc.c @@ -31,10 +31,10 @@ char * u8_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint8_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp) + enum iconv_ilseq_handler handler, + const uint8_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp) { if (STRCASEEQ (tocode, "UTF-8", 'U','T','F','-','8',0,0,0,0)) { @@ -43,24 +43,24 @@ u8_conv_to_encoding (const char *tocode, /* Conversion from UTF-8 to UTF-8. No need to go through iconv(). */ #if CONFIG_UNICODE_SAFETY if (u8_check (src, srclen)) - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } #endif /* Memory allocation. */ if (resultbuf != NULL && *lengthp >= srclen) - result = resultbuf; + result = resultbuf; else - { - result = (char *) malloc (srclen > 0 ? srclen : 1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (char *) malloc (srclen > 0 ? srclen : 1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } memcpy (result, (const char *) src, srclen); *lengthp = srclen; @@ -72,20 +72,20 @@ u8_conv_to_encoding (const char *tocode, size_t length = *lengthp; if (mem_iconveha ((const char *) src, srclen, - "UTF-8", tocode, - handler == iconveh_question_mark, handler, - offsets, &result, &length) < 0) - return NULL; + "UTF-8", tocode, + handler == iconveh_question_mark, handler, + offsets, &result, &length) < 0) + return NULL; if (result == NULL) /* when (resultbuf == NULL && length == 0) */ - { - result = (char *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (char *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } *lengthp = length; return result; } diff --git a/lib/uniconv/u8-strconv-to-enc.c b/lib/uniconv/u8-strconv-to-enc.c index a3f12b6b1..082334843 100644 --- a/lib/uniconv/u8-strconv-to-enc.c +++ b/lib/uniconv/u8-strconv-to-enc.c @@ -31,8 +31,8 @@ char * u8_strconv_to_encoding (const uint8_t *string, - const char *tocode, - enum iconv_ilseq_handler handler) + const char *tocode, + enum iconv_ilseq_handler handler) { char *result; size_t length; @@ -43,17 +43,17 @@ u8_strconv_to_encoding (const uint8_t *string, length = u8_strlen (string) + 1; #if CONFIG_UNICODE_SAFETY if (u8_check (string, length)) - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } #endif result = (char *) malloc (length); if (result == NULL) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } memcpy (result, (const char *) string, length); return result; } @@ -62,18 +62,18 @@ u8_strconv_to_encoding (const uint8_t *string, result = NULL; length = 0; if (mem_iconveha ((const char *) string, u8_strlen (string) + 1, - "UTF-8", tocode, - handler == iconveh_question_mark, handler, - NULL, &result, &length) < 0) - return NULL; + "UTF-8", tocode, + handler == iconveh_question_mark, handler, + NULL, &result, &length) < 0) + return NULL; /* Verify the result has exactly one NUL byte, at the end. */ if (!(length > 0 && result[length-1] == '\0' - && strlen (result) == length-1)) - { - free (result); - errno = EILSEQ; - return NULL; - } + && strlen (result) == length-1)) + { + free (result); + errno = EILSEQ; + return NULL; + } return result; } } diff --git a/lib/unictype.h b/lib/unictype.h index ae47d1153..c75af057f 100644 --- a/lib/unictype.h +++ b/lib/unictype.h @@ -183,14 +183,14 @@ extern const uc_general_category_t _UC_CATEGORY_NONE; This corresponds to the unions of the two sets of characters. */ extern uc_general_category_t uc_general_category_or (uc_general_category_t category1, - uc_general_category_t category2); + uc_general_category_t category2); /* Return the intersection of two general categories as bit masks. This *does*not* correspond to the intersection of the two sets of characters. */ extern uc_general_category_t uc_general_category_and (uc_general_category_t category1, - uc_general_category_t category2); + uc_general_category_t category2); /* Return the intersection of a general category with the complement of a second general category, as bit masks. @@ -198,7 +198,7 @@ extern uc_general_category_t viewing the categories as sets of characters. */ extern uc_general_category_t uc_general_category_and_not (uc_general_category_t category1, - uc_general_category_t category2); + uc_general_category_t category2); /* Return the name of a general category. */ extern const char * diff --git a/lib/unictype/3level.h b/lib/unictype/3level.h index 426ad3b28..aa9455ace 100644 --- a/lib/unictype/3level.h +++ b/lib/unictype/3level.h @@ -39,7 +39,7 @@ ELEMENT TABLE_get (struct TABLE *t, uint32_t wc); void TABLE_add (struct TABLE *t, uint32_t wc, ELEMENT value); void TABLE_iterate (struct TABLE *t, - void (*fn) (uint32_t wc, ELEMENT value)); + void (*fn) (uint32_t wc, ELEMENT value)); void TABLE_finalize (struct TABLE *t); */ @@ -91,19 +91,19 @@ CONCAT(TABLE,_get) (struct TABLE *t, uint32_t wc) { uint32_t lookup1 = t->level1[index1]; if (lookup1 != EMPTY) - { - uint32_t index2 = ((wc >> t->p) & ((1 << t->q) - 1)) - + (lookup1 << t->q); - uint32_t lookup2 = t->level2[index2]; - if (lookup2 != EMPTY) - { - uint32_t index3 = (wc & ((1 << t->p) - 1)) - + (lookup2 << t->p); - ELEMENT lookup3 = t->level3[index3]; - - return lookup3; - } - } + { + uint32_t index2 = ((wc >> t->p) & ((1 << t->q) - 1)) + + (lookup1 << t->q); + uint32_t lookup2 = t->level2[index2]; + if (lookup2 != EMPTY) + { + uint32_t index3 = (wc & ((1 << t->p) - 1)) + + (lookup2 << t->p); + ELEMENT lookup3 = t->level3[index3]; + + return lookup3; + } + } } return DEFAULT; } @@ -123,31 +123,31 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value) if (index1 >= t->level1_size) { if (index1 >= t->level1_alloc) - { - size_t alloc = 2 * t->level1_alloc; - if (alloc <= index1) - alloc = index1 + 1; - t->level1 = (uint32_t *) xrealloc ((char *) t->level1, - alloc * sizeof (uint32_t)); - t->level1_alloc = alloc; - } + { + size_t alloc = 2 * t->level1_alloc; + if (alloc <= index1) + alloc = index1 + 1; + t->level1 = (uint32_t *) xrealloc ((char *) t->level1, + alloc * sizeof (uint32_t)); + t->level1_alloc = alloc; + } while (index1 >= t->level1_size) - t->level1[t->level1_size++] = EMPTY; + t->level1[t->level1_size++] = EMPTY; } if (t->level1[index1] == EMPTY) { if (t->level2_size == t->level2_alloc) - { - size_t alloc = 2 * t->level2_alloc + 1; - t->level2 = (uint32_t *) xrealloc ((char *) t->level2, - (alloc << t->q) * sizeof (uint32_t)); - t->level2_alloc = alloc; - } + { + size_t alloc = 2 * t->level2_alloc + 1; + t->level2 = (uint32_t *) xrealloc ((char *) t->level2, + (alloc << t->q) * sizeof (uint32_t)); + t->level2_alloc = alloc; + } i1 = t->level2_size << t->q; i2 = (t->level2_size + 1) << t->q; for (i = i1; i < i2; i++) - t->level2[i] = EMPTY; + t->level2[i] = EMPTY; t->level1[index1] = t->level2_size++; } @@ -156,16 +156,16 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value) if (t->level2[index2] == EMPTY) { if (t->level3_size == t->level3_alloc) - { - size_t alloc = 2 * t->level3_alloc + 1; - t->level3 = (ELEMENT *) xrealloc ((char *) t->level3, - (alloc << t->p) * sizeof (ELEMENT)); - t->level3_alloc = alloc; - } + { + size_t alloc = 2 * t->level3_alloc + 1; + t->level3 = (ELEMENT *) xrealloc ((char *) t->level3, + (alloc << t->p) * sizeof (ELEMENT)); + t->level3_alloc = alloc; + } i1 = t->level3_size << t->p; i2 = (t->level3_size + 1) << t->p; for (i = i1; i < i2; i++) - t->level3[i] = DEFAULT; + t->level3[i] = DEFAULT; t->level2[index2] = t->level3_size++; } @@ -178,33 +178,33 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc, ELEMENT value) /* Apply a function to all entries in the table. */ static void CONCAT(TABLE,_iterate) (struct TABLE *t, - void (*fn) (uint32_t wc, ELEMENT value)) + void (*fn) (uint32_t wc, ELEMENT value)) { uint32_t index1; for (index1 = 0; index1 < t->level1_size; index1++) { uint32_t lookup1 = t->level1[index1]; if (lookup1 != EMPTY) - { - uint32_t lookup1_shifted = lookup1 << t->q; - uint32_t index2; - for (index2 = 0; index2 < (1 << t->q); index2++) - { - uint32_t lookup2 = t->level2[index2 + lookup1_shifted]; - if (lookup2 != EMPTY) - { - uint32_t lookup2_shifted = lookup2 << t->p; - uint32_t index3; - for (index3 = 0; index3 < (1 << t->p); index3++) - { - ELEMENT lookup3 = t->level3[index3 + lookup2_shifted]; - if (lookup3 != DEFAULT) - fn ((((index1 << t->q) + index2) << t->p) + index3, - lookup3); - } - } - } - } + { + uint32_t lookup1_shifted = lookup1 << t->q; + uint32_t index2; + for (index2 = 0; index2 < (1 << t->q); index2++) + { + uint32_t lookup2 = t->level2[index2 + lookup1_shifted]; + if (lookup2 != EMPTY) + { + uint32_t lookup2_shifted = lookup2 << t->p; + uint32_t index3; + for (index3 = 0; index3 < (1 << t->p); index3++) + { + ELEMENT lookup3 = t->level3[index3 + lookup2_shifted]; + if (lookup3 != DEFAULT) + fn ((((index1 << t->q) + index2) << t->p) + index3, + lookup3); + } + } + } + } } } #endif @@ -224,18 +224,18 @@ CONCAT(TABLE,_finalize) (struct TABLE *t) for (j = 0; j < t->level3_size; j++) { for (i = 0; i < k; i++) - if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (ELEMENT)) == 0) - break; + if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p], + (1 << t->p) * sizeof (ELEMENT)) == 0) + break; /* Relocate block j to block i. */ reorder3[j] = i; if (i == k) - { - if (i != j) - memcpy (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (ELEMENT)); - k++; - } + { + if (i != j) + memcpy (&t->level3[i << t->p], &t->level3[j << t->p], + (1 << t->p) * sizeof (ELEMENT)); + k++; + } } t->level3_size = k; @@ -248,18 +248,18 @@ CONCAT(TABLE,_finalize) (struct TABLE *t) for (j = 0; j < t->level2_size; j++) { for (i = 0; i < k; i++) - if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)) == 0) - break; + if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q], + (1 << t->q) * sizeof (uint32_t)) == 0) + break; /* Relocate block j to block i. */ reorder2[j] = i; if (i == k) - { - if (i != j) - memcpy (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)); - k++; - } + { + if (i != j) + memcpy (&t->level2[i << t->q], &t->level2[j << t->q], + (1 << t->q) * sizeof (uint32_t)); + k++; + } } t->level2_size = k; diff --git a/lib/unictype/3levelbit.h b/lib/unictype/3levelbit.h index aa6105a14..e4df1ab00 100644 --- a/lib/unictype/3levelbit.h +++ b/lib/unictype/3levelbit.h @@ -88,20 +88,20 @@ CONCAT(TABLE,_get) (struct TABLE *t, uint32_t wc) { uint32_t lookup1 = t->level1[index1]; if (lookup1 != EMPTY) - { - uint32_t index2 = ((wc >> (t->p + 5)) & ((1 << t->q) - 1)) - + (lookup1 << t->q); - uint32_t lookup2 = t->level2[index2]; - if (lookup2 != EMPTY) - { - uint32_t index3 = ((wc >> 5) & ((1 << t->p) - 1)) - + (lookup2 << t->p); - uint32_t lookup3 = t->level3[index3]; - uint32_t index4 = wc & 0x1f; - - return (lookup3 >> index4) & 1; - } - } + { + uint32_t index2 = ((wc >> (t->p + 5)) & ((1 << t->q) - 1)) + + (lookup1 << t->q); + uint32_t lookup2 = t->level2[index2]; + if (lookup2 != EMPTY) + { + uint32_t index3 = ((wc >> 5) & ((1 << t->p) - 1)) + + (lookup2 << t->p); + uint32_t lookup3 = t->level3[index3]; + uint32_t index4 = wc & 0x1f; + + return (lookup3 >> index4) & 1; + } + } } return 0; } @@ -119,31 +119,31 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc) if (index1 >= t->level1_size) { if (index1 >= t->level1_alloc) - { - size_t alloc = 2 * t->level1_alloc; - if (alloc <= index1) - alloc = index1 + 1; - t->level1 = (uint32_t *) xrealloc ((char *) t->level1, - alloc * sizeof (uint32_t)); - t->level1_alloc = alloc; - } + { + size_t alloc = 2 * t->level1_alloc; + if (alloc <= index1) + alloc = index1 + 1; + t->level1 = (uint32_t *) xrealloc ((char *) t->level1, + alloc * sizeof (uint32_t)); + t->level1_alloc = alloc; + } while (index1 >= t->level1_size) - t->level1[t->level1_size++] = EMPTY; + t->level1[t->level1_size++] = EMPTY; } if (t->level1[index1] == EMPTY) { if (t->level2_size == t->level2_alloc) - { - size_t alloc = 2 * t->level2_alloc + 1; - t->level2 = (uint32_t *) xrealloc ((char *) t->level2, - (alloc << t->q) * sizeof (uint32_t)); - t->level2_alloc = alloc; - } + { + size_t alloc = 2 * t->level2_alloc + 1; + t->level2 = (uint32_t *) xrealloc ((char *) t->level2, + (alloc << t->q) * sizeof (uint32_t)); + t->level2_alloc = alloc; + } i1 = t->level2_size << t->q; i2 = (t->level2_size + 1) << t->q; for (i = i1; i < i2; i++) - t->level2[i] = EMPTY; + t->level2[i] = EMPTY; t->level1[index1] = t->level2_size++; } @@ -152,16 +152,16 @@ CONCAT(TABLE,_add) (struct TABLE *t, uint32_t wc) if (t->level2[index2] == EMPTY) { if (t->level3_size == t->level3_alloc) - { - size_t alloc = 2 * t->level3_alloc + 1; - t->level3 = (uint32_t *) xrealloc ((char *) t->level3, - (alloc << t->p) * sizeof (uint32_t)); - t->level3_alloc = alloc; - } + { + size_t alloc = 2 * t->level3_alloc + 1; + t->level3 = (uint32_t *) xrealloc ((char *) t->level3, + (alloc << t->p) * sizeof (uint32_t)); + t->level3_alloc = alloc; + } i1 = t->level3_size << t->p; i2 = (t->level3_size + 1) << t->p; for (i = i1; i < i2; i++) - t->level3[i] = 0; + t->level3[i] = 0; t->level2[index2] = t->level3_size++; } @@ -180,27 +180,27 @@ CONCAT(TABLE,_iterate) (struct TABLE *t, void (*fn) (uint32_t wc)) { uint32_t lookup1 = t->level1[index1]; if (lookup1 != EMPTY) - { - uint32_t lookup1_shifted = lookup1 << t->q; - uint32_t index2; - for (index2 = 0; index2 < (1 << t->q); index2++) - { - uint32_t lookup2 = t->level2[index2 + lookup1_shifted]; - if (lookup2 != EMPTY) - { - uint32_t lookup2_shifted = lookup2 << t->p; - uint32_t index3; - for (index3 = 0; index3 < (1 << t->p); index3++) - { - uint32_t lookup3 = t->level3[index3 + lookup2_shifted]; - uint32_t index4; - for (index4 = 0; index4 < 32; index4++) - if ((lookup3 >> index4) & 1) - fn ((((((index1 << t->q) + index2) << t->p) + index3) << 5) + index4); - } - } - } - } + { + uint32_t lookup1_shifted = lookup1 << t->q; + uint32_t index2; + for (index2 = 0; index2 < (1 << t->q); index2++) + { + uint32_t lookup2 = t->level2[index2 + lookup1_shifted]; + if (lookup2 != EMPTY) + { + uint32_t lookup2_shifted = lookup2 << t->p; + uint32_t index3; + for (index3 = 0; index3 < (1 << t->p); index3++) + { + uint32_t lookup3 = t->level3[index3 + lookup2_shifted]; + uint32_t index4; + for (index4 = 0; index4 < 32; index4++) + if ((lookup3 >> index4) & 1) + fn ((((((index1 << t->q) + index2) << t->p) + index3) << 5) + index4); + } + } + } + } } } #endif @@ -220,18 +220,18 @@ CONCAT(TABLE,_finalize) (struct TABLE *t) for (j = 0; j < t->level3_size; j++) { for (i = 0; i < k; i++) - if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (uint32_t)) == 0) - break; + if (memcmp (&t->level3[i << t->p], &t->level3[j << t->p], + (1 << t->p) * sizeof (uint32_t)) == 0) + break; /* Relocate block j to block i. */ reorder3[j] = i; if (i == k) - { - if (i != j) - memcpy (&t->level3[i << t->p], &t->level3[j << t->p], - (1 << t->p) * sizeof (uint32_t)); - k++; - } + { + if (i != j) + memcpy (&t->level3[i << t->p], &t->level3[j << t->p], + (1 << t->p) * sizeof (uint32_t)); + k++; + } } t->level3_size = k; @@ -244,18 +244,18 @@ CONCAT(TABLE,_finalize) (struct TABLE *t) for (j = 0; j < t->level2_size; j++) { for (i = 0; i < k; i++) - if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)) == 0) - break; + if (memcmp (&t->level2[i << t->q], &t->level2[j << t->q], + (1 << t->q) * sizeof (uint32_t)) == 0) + break; /* Relocate block j to block i. */ reorder2[j] = i; if (i == k) - { - if (i != j) - memcpy (&t->level2[i << t->q], &t->level2[j << t->q], - (1 << t->q) * sizeof (uint32_t)); - k++; - } + { + if (i != j) + memcpy (&t->level2[i << t->q], &t->level2[j << t->q], + (1 << t->q) * sizeof (uint32_t)); + k++; + } } t->level2_size = k; diff --git a/lib/unictype/bidi_byname.c b/lib/unictype/bidi_byname.c index 8a6cb71ac..13d76c8a9 100644 --- a/lib/unictype/bidi_byname.c +++ b/lib/unictype/bidi_byname.c @@ -27,143 +27,143 @@ uc_bidi_category_byname (const char *category_name) { case 'A': switch (category_name[1]) - { - case 'L': - if (category_name[2] == '\0') - return UC_BIDI_AL; - break; - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_AN; - break; - } + { + case 'L': + if (category_name[2] == '\0') + return UC_BIDI_AL; + break; + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_AN; + break; + } break; case 'B': switch (category_name[1]) - { - case '\0': - return UC_BIDI_B; - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_BN; - break; - } + { + case '\0': + return UC_BIDI_B; + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_BN; + break; + } break; case 'C': switch (category_name[1]) - { - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_CS; - break; - } + { + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_CS; + break; + } break; case 'E': switch (category_name[1]) - { - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_EN; - break; - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_ES; - break; - case 'T': - if (category_name[2] == '\0') - return UC_BIDI_ET; - break; - } + { + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_EN; + break; + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_ES; + break; + case 'T': + if (category_name[2] == '\0') + return UC_BIDI_ET; + break; + } break; case 'L': switch (category_name[1]) - { - case '\0': - return UC_BIDI_L; - case 'R': - switch (category_name[2]) - { - case 'E': - if (category_name[3] == '\0') - return UC_BIDI_LRE; - break; - case 'O': - if (category_name[3] == '\0') - return UC_BIDI_LRO; - break; - } - break; - } + { + case '\0': + return UC_BIDI_L; + case 'R': + switch (category_name[2]) + { + case 'E': + if (category_name[3] == '\0') + return UC_BIDI_LRE; + break; + case 'O': + if (category_name[3] == '\0') + return UC_BIDI_LRO; + break; + } + break; + } break; case 'N': switch (category_name[1]) - { - case 'S': - switch (category_name[2]) - { - case 'M': - if (category_name[3] == '\0') - return UC_BIDI_NSM; - break; - } - break; - } + { + case 'S': + switch (category_name[2]) + { + case 'M': + if (category_name[3] == '\0') + return UC_BIDI_NSM; + break; + } + break; + } break; case 'O': switch (category_name[1]) - { - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_ON; - break; - } + { + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_ON; + break; + } break; case 'P': switch (category_name[1]) - { - case 'D': - switch (category_name[2]) - { - case 'F': - if (category_name[3] == '\0') - return UC_BIDI_PDF; - break; - } - break; - } + { + case 'D': + switch (category_name[2]) + { + case 'F': + if (category_name[3] == '\0') + return UC_BIDI_PDF; + break; + } + break; + } break; case 'R': switch (category_name[1]) - { - case '\0': - return UC_BIDI_R; - case 'L': - switch (category_name[2]) - { - case 'E': - if (category_name[3] == '\0') - return UC_BIDI_RLE; - break; - case 'O': - if (category_name[3] == '\0') - return UC_BIDI_RLO; - break; - } - break; - } + { + case '\0': + return UC_BIDI_R; + case 'L': + switch (category_name[2]) + { + case 'E': + if (category_name[3] == '\0') + return UC_BIDI_RLE; + break; + case 'O': + if (category_name[3] == '\0') + return UC_BIDI_RLO; + break; + } + break; + } break; case 'S': if (category_name[1] == '\0') - return UC_BIDI_S; + return UC_BIDI_S; break; case 'W': switch (category_name[1]) - { - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_WS; - break; - } + { + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_WS; + break; + } break; } /* Invalid category name. */ diff --git a/lib/unictype/bidi_of.c b/lib/unictype/bidi_of.c index 93fc7a8b5..af9fa4885 100644 --- a/lib/unictype/bidi_of.c +++ b/lib/unictype/bidi_of.c @@ -31,22 +31,22 @@ uc_bidi_category (ucs4_t uc) { int lookup1 = u_bidi_category.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> bidi_category_header_2) & bidi_category_header_3; - int lookup2 = u_bidi_category.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = ((uc & bidi_category_header_4) + lookup2) * 5; - /* level3 contains 5-bit values, packed into 16-bit words. */ - unsigned int lookup3 = - ((u_bidi_category.level3[index3>>4] - | (u_bidi_category.level3[(index3>>4)+1] << 16)) - >> (index3 % 16)) - & 0x1f; - - return lookup3; - } - } + { + unsigned int index2 = (uc >> bidi_category_header_2) & bidi_category_header_3; + int lookup2 = u_bidi_category.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = ((uc & bidi_category_header_4) + lookup2) * 5; + /* level3 contains 5-bit values, packed into 16-bit words. */ + unsigned int lookup3 = + ((u_bidi_category.level3[index3>>4] + | (u_bidi_category.level3[(index3>>4)+1] << 16)) + >> (index3 % 16)) + & 0x1f; + + return lookup3; + } + } } return UC_BIDI_L; } diff --git a/lib/unictype/bitmap.h b/lib/unictype/bitmap.h index 280b29855..d8bbfd5d4 100644 --- a/lib/unictype/bitmap.h +++ b/lib/unictype/bitmap.h @@ -31,17 +31,17 @@ bitmap_lookup (const void *table, ucs4_t uc) { int lookup1 = ((const int *) table)[1 + index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> header_2) & header_3; - int lookup2 = ((const short *) table)[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc >> 5) & header_4; - unsigned int lookup3 = ((const int *) table)[lookup2 + index3]; + { + unsigned int index2 = (uc >> header_2) & header_3; + int lookup2 = ((const short *) table)[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc >> 5) & header_4; + unsigned int lookup3 = ((const int *) table)[lookup2 + index3]; - return (lookup3 >> (uc & 0x1f)) & 1; - } - } + return (lookup3 >> (uc & 0x1f)) & 1; + } + } } return 0; } diff --git a/lib/unictype/blocks.c b/lib/unictype/blocks.c index a20bbcee7..7e3206537 100644 --- a/lib/unictype/blocks.c +++ b/lib/unictype/blocks.c @@ -45,11 +45,11 @@ uc_block (ucs4_t uc) { unsigned int mid_index = (first_index + last_index) / 2; if (blocks[mid_index].end < uc) - first_index = mid_index + 1; + first_index = mid_index + 1; else if (uc < blocks[mid_index].start) - last_index = mid_index; + last_index = mid_index; else - return &blocks[mid_index]; + return &blocks[mid_index]; } return NULL; } diff --git a/lib/unictype/categ_and.c b/lib/unictype/categ_and.c index 2101f94e9..f408ae665 100644 --- a/lib/unictype/categ_and.c +++ b/lib/unictype/categ_and.c @@ -22,7 +22,7 @@ uc_general_category_t uc_general_category_and (uc_general_category_t category1, - uc_general_category_t category2) + uc_general_category_t category2) { uint32_t bitmask; uc_general_category_t result; diff --git a/lib/unictype/categ_and_not.c b/lib/unictype/categ_and_not.c index 6cc27596c..e631191c6 100644 --- a/lib/unictype/categ_and_not.c +++ b/lib/unictype/categ_and_not.c @@ -22,7 +22,7 @@ uc_general_category_t uc_general_category_and_not (uc_general_category_t category1, - uc_general_category_t category2) + uc_general_category_t category2) { uint32_t bitmask; uc_general_category_t result; diff --git a/lib/unictype/categ_byname.c b/lib/unictype/categ_byname.c index a175dd15e..e6120f188 100644 --- a/lib/unictype/categ_byname.c +++ b/lib/unictype/categ_byname.c @@ -28,77 +28,77 @@ uc_general_category_byname (const char *category_name) switch (category_name[0]) { case 'L': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_L; - case 'u': return UC_CATEGORY_Lu; - case 'l': return UC_CATEGORY_Ll; - case 't': return UC_CATEGORY_Lt; - case 'm': return UC_CATEGORY_Lm; - case 'o': return UC_CATEGORY_Lo; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_L; + case 'u': return UC_CATEGORY_Lu; + case 'l': return UC_CATEGORY_Ll; + case 't': return UC_CATEGORY_Lt; + case 'm': return UC_CATEGORY_Lm; + case 'o': return UC_CATEGORY_Lo; + } + break; case 'M': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_M; - case 'n': return UC_CATEGORY_Mn; - case 'c': return UC_CATEGORY_Mc; - case 'e': return UC_CATEGORY_Me; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_M; + case 'n': return UC_CATEGORY_Mn; + case 'c': return UC_CATEGORY_Mc; + case 'e': return UC_CATEGORY_Me; + } + break; case 'N': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_N; - case 'd': return UC_CATEGORY_Nd; - case 'l': return UC_CATEGORY_Nl; - case 'o': return UC_CATEGORY_No; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_N; + case 'd': return UC_CATEGORY_Nd; + case 'l': return UC_CATEGORY_Nl; + case 'o': return UC_CATEGORY_No; + } + break; case 'P': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_P; - case 'c': return UC_CATEGORY_Pc; - case 'd': return UC_CATEGORY_Pd; - case 's': return UC_CATEGORY_Ps; - case 'e': return UC_CATEGORY_Pe; - case 'i': return UC_CATEGORY_Pi; - case 'f': return UC_CATEGORY_Pf; - case 'o': return UC_CATEGORY_Po; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_P; + case 'c': return UC_CATEGORY_Pc; + case 'd': return UC_CATEGORY_Pd; + case 's': return UC_CATEGORY_Ps; + case 'e': return UC_CATEGORY_Pe; + case 'i': return UC_CATEGORY_Pi; + case 'f': return UC_CATEGORY_Pf; + case 'o': return UC_CATEGORY_Po; + } + break; case 'S': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_S; - case 'm': return UC_CATEGORY_Sm; - case 'c': return UC_CATEGORY_Sc; - case 'k': return UC_CATEGORY_Sk; - case 'o': return UC_CATEGORY_So; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_S; + case 'm': return UC_CATEGORY_Sm; + case 'c': return UC_CATEGORY_Sc; + case 'k': return UC_CATEGORY_Sk; + case 'o': return UC_CATEGORY_So; + } + break; case 'Z': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_Z; - case 's': return UC_CATEGORY_Zs; - case 'l': return UC_CATEGORY_Zl; - case 'p': return UC_CATEGORY_Zp; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_Z; + case 's': return UC_CATEGORY_Zs; + case 'l': return UC_CATEGORY_Zl; + case 'p': return UC_CATEGORY_Zp; + } + break; case 'C': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_C; - case 'c': return UC_CATEGORY_Cc; - case 'f': return UC_CATEGORY_Cf; - case 's': return UC_CATEGORY_Cs; - case 'o': return UC_CATEGORY_Co; - case 'n': return UC_CATEGORY_Cn; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_C; + case 'c': return UC_CATEGORY_Cc; + case 'f': return UC_CATEGORY_Cf; + case 's': return UC_CATEGORY_Cs; + case 'o': return UC_CATEGORY_Co; + case 'n': return UC_CATEGORY_Cn; + } + break; } /* Invalid category name. */ return _UC_CATEGORY_NONE; diff --git a/lib/unictype/categ_name.c b/lib/unictype/categ_name.c index 10421efcd..ee9f8b108 100644 --- a/lib/unictype/categ_name.c +++ b/lib/unictype/categ_name.c @@ -35,43 +35,43 @@ uc_general_category_name (uc_general_category_t category) if (bitmask != 0) { if ((bitmask & (bitmask - 1)) == 0) - { - int bit; - /* Take log2 using a variant of Robert Harley's method. - Found by Bruno Haible 1996. */ - uint32_t n = bitmask; - static const char ord2_tab[64] = - { - -1, 0, 1, 12, 2, 6, -1, 13, 3, -1, 7, -1, -1, -1, -1, 14, - 10, 4, -1, -1, 8, -1, -1, 25, -1, -1, -1, -1, -1, 21, 27, 15, - 31, 11, 5, -1, -1, -1, -1, -1, 9, -1, -1, 24, -1, -1, 20, 26, - 30, -1, -1, -1, -1, 23, -1, 19, 29, -1, 22, 18, 28, 17, 16, -1 - }; - n += n << 4; - n += n << 6; - n = (n << 16) - n; - bit = ord2_tab[n >> 26]; + { + int bit; + /* Take log2 using a variant of Robert Harley's method. + Found by Bruno Haible 1996. */ + uint32_t n = bitmask; + static const char ord2_tab[64] = + { + -1, 0, 1, 12, 2, 6, -1, 13, 3, -1, 7, -1, -1, -1, -1, 14, + 10, 4, -1, -1, 8, -1, -1, 25, -1, -1, -1, -1, -1, 21, 27, 15, + 31, 11, 5, -1, -1, -1, -1, -1, 9, -1, -1, 24, -1, -1, 20, 26, + 30, -1, -1, -1, -1, 23, -1, 19, 29, -1, 22, 18, 28, 17, 16, -1 + }; + n += n << 4; + n += n << 6; + n = (n << 16) - n; + bit = ord2_tab[n >> 26]; - if (bit < sizeof (u_category_name) / sizeof (u_category_name[0])) - return u_category_name[bit]; - } + if (bit < sizeof (u_category_name) / sizeof (u_category_name[0])) + return u_category_name[bit]; + } else - { - if (bitmask == UC_CATEGORY_MASK_L) - return "L"; - if (bitmask == UC_CATEGORY_MASK_M) - return "M"; - if (bitmask == UC_CATEGORY_MASK_N) - return "N"; - if (bitmask == UC_CATEGORY_MASK_P) - return "P"; - if (bitmask == UC_CATEGORY_MASK_S) - return "S"; - if (bitmask == UC_CATEGORY_MASK_Z) - return "Z"; - if (bitmask == UC_CATEGORY_MASK_C) - return "C"; - } + { + if (bitmask == UC_CATEGORY_MASK_L) + return "L"; + if (bitmask == UC_CATEGORY_MASK_M) + return "M"; + if (bitmask == UC_CATEGORY_MASK_N) + return "N"; + if (bitmask == UC_CATEGORY_MASK_P) + return "P"; + if (bitmask == UC_CATEGORY_MASK_S) + return "S"; + if (bitmask == UC_CATEGORY_MASK_Z) + return "Z"; + if (bitmask == UC_CATEGORY_MASK_C) + return "C"; + } } return NULL; } diff --git a/lib/unictype/categ_of.c b/lib/unictype/categ_of.c index 85b694f48..311c565a7 100644 --- a/lib/unictype/categ_of.c +++ b/lib/unictype/categ_of.c @@ -31,22 +31,22 @@ lookup_withtable (ucs4_t uc) { int lookup1 = u_category.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> category_header_2) & category_header_3; - int lookup2 = u_category.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = ((uc & category_header_4) + lookup2) * 5; - /* level3 contains 5-bit values, packed into 16-bit words. */ - unsigned int lookup3 = - ((u_category.level3[index3>>4] - | (u_category.level3[(index3>>4)+1] << 16)) - >> (index3 % 16)) - & 0x1f; + { + unsigned int index2 = (uc >> category_header_2) & category_header_3; + int lookup2 = u_category.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = ((uc & category_header_4) + lookup2) * 5; + /* level3 contains 5-bit values, packed into 16-bit words. */ + unsigned int lookup3 = + ((u_category.level3[index3>>4] + | (u_category.level3[(index3>>4)+1] << 16)) + >> (index3 % 16)) + & 0x1f; - return lookup3; - } - } + return lookup3; + } + } return 29; /* = log2(UC_CATEGORY_MASK_Cn) */ } return -1; diff --git a/lib/unictype/categ_or.c b/lib/unictype/categ_or.c index 9864210c8..140d80271 100644 --- a/lib/unictype/categ_or.c +++ b/lib/unictype/categ_or.c @@ -22,7 +22,7 @@ uc_general_category_t uc_general_category_or (uc_general_category_t category1, - uc_general_category_t category2) + uc_general_category_t category2) { uint32_t bitmask; uc_general_category_t result; diff --git a/lib/unictype/combining.c b/lib/unictype/combining.c index d2e33e63c..921a31a39 100644 --- a/lib/unictype/combining.c +++ b/lib/unictype/combining.c @@ -31,17 +31,17 @@ uc_combining_class (ucs4_t uc) { int lookup1 = u_combclass.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> combclass_header_2) & combclass_header_3; - int lookup2 = u_combclass.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & combclass_header_4); - unsigned int lookup3 = u_combclass.level3[lookup2 + index3]; - - return lookup3; - } - } + { + unsigned int index2 = (uc >> combclass_header_2) & combclass_header_3; + int lookup2 = u_combclass.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & combclass_header_4); + unsigned int lookup3 = u_combclass.level3[lookup2 + index3]; + + return lookup3; + } + } } return 0; } diff --git a/lib/unictype/decdigit.c b/lib/unictype/decdigit.c index 48b059258..73a311c7a 100644 --- a/lib/unictype/decdigit.c +++ b/lib/unictype/decdigit.c @@ -31,19 +31,19 @@ uc_decimal_value (ucs4_t uc) { int lookup1 = u_decdigit.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> decdigit_header_2) & decdigit_header_3; - int lookup2 = u_decdigit.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & decdigit_header_4) + lookup2; - /* level3 contains 4-bit values. */ - unsigned int lookup3 = - (u_decdigit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; - - return (int) lookup3 - 1; - } - } + { + unsigned int index2 = (uc >> decdigit_header_2) & decdigit_header_3; + int lookup2 = u_decdigit.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & decdigit_header_4) + lookup2; + /* level3 contains 4-bit values. */ + unsigned int lookup3 = + (u_decdigit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; + + return (int) lookup3 - 1; + } + } } return -1; } diff --git a/lib/unictype/digit.c b/lib/unictype/digit.c index 21545c7b0..0523f788a 100644 --- a/lib/unictype/digit.c +++ b/lib/unictype/digit.c @@ -31,19 +31,19 @@ uc_digit_value (ucs4_t uc) { int lookup1 = u_digit.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> digit_header_2) & digit_header_3; - int lookup2 = u_digit.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & digit_header_4) + lookup2; - /* level3 contains 4-bit values. */ - unsigned int lookup3 = - (u_digit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; - - return (int) lookup3 - 1; - } - } + { + unsigned int index2 = (uc >> digit_header_2) & digit_header_3; + int lookup2 = u_digit.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & digit_header_4) + lookup2; + /* level3 contains 4-bit values. */ + unsigned int lookup3 = + (u_digit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; + + return (int) lookup3 - 1; + } + } } return -1; } diff --git a/lib/unictype/identsyntaxmap.h b/lib/unictype/identsyntaxmap.h index 5d9db3959..4a8af96e6 100644 --- a/lib/unictype/identsyntaxmap.h +++ b/lib/unictype/identsyntaxmap.h @@ -25,18 +25,18 @@ identsyntax_lookup (ucs4_t uc) { int lookup1 = TABLE.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> identsyntax_header_2) & identsyntax_header_3; - int lookup2 = TABLE.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & identsyntax_header_4) + lookup2; - /* level3 contains 2-bit values. */ - unsigned int lookup3 = TABLE.level3[index3 >> 3]; + { + unsigned int index2 = (uc >> identsyntax_header_2) & identsyntax_header_3; + int lookup2 = TABLE.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & identsyntax_header_4) + lookup2; + /* level3 contains 2-bit values. */ + unsigned int lookup3 = TABLE.level3[index3 >> 3]; - return (lookup3 >> (2 * (index3 & 7))) & 3; - } - } + return (lookup3 >> (2 * (index3 & 7))) & 3; + } + } } return UC_IDENTIFIER_INVALID; } diff --git a/lib/unictype/mirror.c b/lib/unictype/mirror.c index 75775447a..fcaffd8bb 100644 --- a/lib/unictype/mirror.c +++ b/lib/unictype/mirror.c @@ -31,18 +31,18 @@ uc_mirror_char (ucs4_t uc, ucs4_t *puc) { int lookup1 = u_mirror.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> mirror_header_2) & mirror_header_3; - int lookup2 = u_mirror.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & mirror_header_4); - int lookup3 = u_mirror.level3[lookup2 + index3]; - - *puc = uc + lookup3; - return (lookup3 != 0); - } - } + { + unsigned int index2 = (uc >> mirror_header_2) & mirror_header_3; + int lookup2 = u_mirror.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & mirror_header_4); + int lookup3 = u_mirror.level3[lookup2 + index3]; + + *puc = uc + lookup3; + return (lookup3 != 0); + } + } } *puc = uc; return false; diff --git a/lib/unictype/numeric.c b/lib/unictype/numeric.c index fb1512ebe..6edf3d27e 100644 --- a/lib/unictype/numeric.c +++ b/lib/unictype/numeric.c @@ -31,22 +31,22 @@ uc_numeric_value (ucs4_t uc) { int lookup1 = u_numeric.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> numeric_header_2) & numeric_header_3; - int lookup2 = u_numeric.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 7; - /* level3 contains 7-bit values, packed into 16-bit words. */ - unsigned int lookup3 = - ((u_numeric.level3[index3>>4] - | (u_numeric.level3[(index3>>4)+1] << 16)) - >> (index3 % 16)) - & 0x7f; - - return u_numeric_values[lookup3]; - } - } + { + unsigned int index2 = (uc >> numeric_header_2) & numeric_header_3; + int lookup2 = u_numeric.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 7; + /* level3 contains 7-bit values, packed into 16-bit words. */ + unsigned int lookup3 = + ((u_numeric.level3[index3>>4] + | (u_numeric.level3[(index3>>4)+1] << 16)) + >> (index3 % 16)) + & 0x7f; + + return u_numeric_values[lookup3]; + } + } } { const uc_fraction_t default_value = { 0, 0 }; diff --git a/lib/unictype/pr_bidi_embedding_or_override.c b/lib/unictype/pr_bidi_embedding_or_override.c index 702652233..f9f0c5c69 100644 --- a/lib/unictype/pr_bidi_embedding_or_override.c +++ b/lib/unictype/pr_bidi_embedding_or_override.c @@ -40,7 +40,7 @@ uc_is_property_bidi_embedding_or_override (ucs4_t uc) { int category = uc_bidi_category (uc); return (category == UC_BIDI_LRE || category == UC_BIDI_LRO - || category == UC_BIDI_RLE || category == UC_BIDI_RLO); + || category == UC_BIDI_RLE || category == UC_BIDI_RLO); } #endif diff --git a/lib/unictype/pr_byname.c b/lib/unictype/pr_byname.c index cb6e553dc..0d4fab107 100644 --- a/lib/unictype/pr_byname.c +++ b/lib/unictype/pr_byname.c @@ -40,16 +40,16 @@ uc_property_byname (const char *property_name) { unsigned char c = (unsigned char) *cp; if (c >= 0x80) - goto invalid; + goto invalid; if (c >= 'A' && c <= 'Z') - c += 'a' - 'A'; + c += 'a' - 'A'; else if (c == ' ' || c == '-') - c = '_'; + c = '_'; *bp = c; if (c == '\0') - break; + break; if (--count == 0) - goto invalid; + goto invalid; } found = uc_property_lookup (buf, bp - buf); if (found != NULL) diff --git a/lib/unictype/pr_private_use.c b/lib/unictype/pr_private_use.c index 64a28c784..328a20a21 100644 --- a/lib/unictype/pr_private_use.c +++ b/lib/unictype/pr_private_use.c @@ -39,8 +39,8 @@ bool uc_is_property_private_use (ucs4_t uc) { return (uc >= 0xE000 && uc <= 0xF8FF) - || (uc >= 0xF0000 && uc <= 0xFFFFD) - || (uc >= 0x100000 && uc <= 0x10FFFD); + || (uc >= 0xF0000 && uc <= 0xFFFFD) + || (uc >= 0x100000 && uc <= 0x10FFFD); } #endif diff --git a/lib/unictype/scripts.c b/lib/unictype/scripts.c index 092009dbf..83a2117e2 100644 --- a/lib/unictype/scripts.c +++ b/lib/unictype/scripts.c @@ -33,18 +33,18 @@ uc_script (ucs4_t uc) { int lookup1 = u_script.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> script_header_2) & script_header_3; - int lookup2 = u_script.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & script_header_4); - unsigned char lookup3 = u_script.level3[lookup2 + index3]; + { + unsigned int index2 = (uc >> script_header_2) & script_header_3; + int lookup2 = u_script.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & script_header_4); + unsigned char lookup3 = u_script.level3[lookup2 + index3]; - if (lookup3 != 0xff) - return &scripts[lookup3]; - } - } + if (lookup3 != 0xff) + return &scripts[lookup3]; + } + } } return NULL; } diff --git a/lib/unilbrk.h b/lib/unilbrk.h index 4668e7369..529c86c1a 100644 --- a/lib/unilbrk.h +++ b/lib/unilbrk.h @@ -58,16 +58,16 @@ enum */ extern void u8_possible_linebreaks (const uint8_t *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); extern void u16_possible_linebreaks (const uint16_t *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); extern void u32_possible_linebreaks (const uint32_t *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); extern void ulc_possible_linebreaks (const char *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); /* Choose the best line breaks, assuming the uc_width function. The string is s[0..n-1]. The maximum number of columns per line is given @@ -82,24 +82,24 @@ extern void */ extern int u8_width_linebreaks (const uint8_t *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); extern int u16_width_linebreaks (const uint16_t *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); extern int u32_width_linebreaks (const uint32_t *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); extern int ulc_width_linebreaks (const char *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); #ifdef __cplusplus diff --git a/lib/unilbrk/lbrktables.c b/lib/unilbrk/lbrktables.c index ae3ebf4fe..695fa2d1a 100644 --- a/lib/unilbrk/lbrktables.c +++ b/lib/unilbrk/lbrktables.c @@ -25,8 +25,8 @@ const unsigned char unilbrk_table[24][24] = { - /* after */ - /* WJ GL B2 BA BB HY CL EX IN NS OP QU IS NU PO PR SY AL H2 H3 ID JL JV JT */ + /* after */ + /* WJ GL B2 BA BB HY CL EX IN NS OP QU IS NU PO PR SY AL H2 H3 ID JL JV JT */ /* WJ */ { P, I, I, I, I, I, P, P, I, I, I, I, P, I, I, I, P, I, I, I, I, I, I, I, }, /* GL */ { P, I, I, I, I, I, P, P, I, I, I, I, P, I, I, I, P, I, I, I, I, I, I, I, }, /* B2 */ { P, I, P, I, D, I, P, P, D, I, D, I, P, D, D, D, P, D, D, D, D, D, D, D, }, diff --git a/lib/unilbrk/lbrktables.h b/lib/unilbrk/lbrktables.h index 33b525be2..849a7bfc2 100644 --- a/lib/unilbrk/lbrktables.h +++ b/lib/unilbrk/lbrktables.h @@ -70,15 +70,15 @@ unilbrkprop_lookup (ucs4_t uc) { int lookup1 = unilbrkprop.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> lbrkprop_header_2) & lbrkprop_header_3; - int lookup2 = unilbrkprop.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = uc & lbrkprop_header_4; - return unilbrkprop.level3[lookup2 + index3]; - } - } + { + unsigned int index2 = (uc >> lbrkprop_header_2) & lbrkprop_header_3; + int lookup2 = unilbrkprop.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = uc & lbrkprop_header_4; + return unilbrkprop.level3[lookup2 + index3]; + } + } } return LBP_XX; } diff --git a/lib/unilbrk/u16-possible-linebreaks.c b/lib/unilbrk/u16-possible-linebreaks.c index f5b699210..cd27b2561 100644 --- a/lib/unilbrk/u16-possible-linebreaks.c +++ b/lib/unilbrk/u16-possible-linebreaks.c @@ -46,117 +46,117 @@ u16_possible_linebreaks (const uint16_t *s, size_t n, const char *encoding, char int prop = unilbrkprop_lookup (uc); if (prop == LBP_BK) - { - /* Mandatory break. */ - *p = UC_BREAK_MANDATORY; - last_prop = LBP_BK; - seen_space = NULL; - seen_space2 = NULL; - } + { + /* Mandatory break. */ + *p = UC_BREAK_MANDATORY; + last_prop = LBP_BK; + seen_space = NULL; + seen_space2 = NULL; + } else - { - char *q; + { + char *q; - /* Resolve property values whose behaviour is not fixed. */ - switch (prop) - { - case LBP_AI: - /* Resolve ambiguous. */ - prop = LBP_AI_REPLACEMENT; - break; - case LBP_CB: - /* This is arbitrary. */ - prop = LBP_ID; - break; - case LBP_SA: - /* We don't handle complex scripts yet. - Treat LBP_SA like LBP_XX. */ - case LBP_XX: - /* This is arbitrary. */ - prop = LBP_AL; - break; - } + /* Resolve property values whose behaviour is not fixed. */ + switch (prop) + { + case LBP_AI: + /* Resolve ambiguous. */ + prop = LBP_AI_REPLACEMENT; + break; + case LBP_CB: + /* This is arbitrary. */ + prop = LBP_ID; + break; + case LBP_SA: + /* We don't handle complex scripts yet. + Treat LBP_SA like LBP_XX. */ + case LBP_XX: + /* This is arbitrary. */ + prop = LBP_AL; + break; + } - /* Deal with spaces and combining characters. */ - q = p; - if (prop == LBP_SP) - { - /* Don't break just before a space. */ - *p = UC_BREAK_PROHIBITED; - seen_space2 = seen_space; - seen_space = p; - } - else if (prop == LBP_ZW) - { - /* Don't break just before a zero-width space. */ - *p = UC_BREAK_PROHIBITED; - last_prop = LBP_ZW; - seen_space = NULL; - seen_space2 = NULL; - } - else if (prop == LBP_CM) - { - /* Don't break just before a combining character, except immediately after a - zero-width space. */ - if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *p = UC_BREAK_POSSIBLE; - /* A combining character turns a preceding space into LBP_ID. */ - last_prop = LBP_ID; - } - else - { - *p = UC_BREAK_PROHIBITED; - /* A combining character turns a preceding space into LBP_ID. */ - if (seen_space != NULL) - { - q = seen_space; - seen_space = seen_space2; - prop = LBP_ID; - goto lookup_via_table; - } - } - } - else - { - lookup_via_table: - /* prop must be usable as an index for table 7.3 of UTR #14. */ - if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) - abort (); + /* Deal with spaces and combining characters. */ + q = p; + if (prop == LBP_SP) + { + /* Don't break just before a space. */ + *p = UC_BREAK_PROHIBITED; + seen_space2 = seen_space; + seen_space = p; + } + else if (prop == LBP_ZW) + { + /* Don't break just before a zero-width space. */ + *p = UC_BREAK_PROHIBITED; + last_prop = LBP_ZW; + seen_space = NULL; + seen_space2 = NULL; + } + else if (prop == LBP_CM) + { + /* Don't break just before a combining character, except immediately after a + zero-width space. */ + if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *p = UC_BREAK_POSSIBLE; + /* A combining character turns a preceding space into LBP_ID. */ + last_prop = LBP_ID; + } + else + { + *p = UC_BREAK_PROHIBITED; + /* A combining character turns a preceding space into LBP_ID. */ + if (seen_space != NULL) + { + q = seen_space; + seen_space = seen_space2; + prop = LBP_ID; + goto lookup_via_table; + } + } + } + else + { + lookup_via_table: + /* prop must be usable as an index for table 7.3 of UTR #14. */ + if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) + abort (); - if (last_prop == LBP_BK) - { - /* Don't break at the beginning of a line. */ - *q = UC_BREAK_PROHIBITED; - } - else if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *q = UC_BREAK_POSSIBLE; - } - else - { - switch (unilbrk_table [last_prop] [prop]) - { - case D: - *q = UC_BREAK_POSSIBLE; - break; - case I: - *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); - break; - case P: - *q = UC_BREAK_PROHIBITED; - break; - default: - abort (); - } - } - last_prop = prop; - seen_space = NULL; - seen_space2 = NULL; - } - } + if (last_prop == LBP_BK) + { + /* Don't break at the beginning of a line. */ + *q = UC_BREAK_PROHIBITED; + } + else if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *q = UC_BREAK_POSSIBLE; + } + else + { + switch (unilbrk_table [last_prop] [prop]) + { + case D: + *q = UC_BREAK_POSSIBLE; + break; + case I: + *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); + break; + case P: + *q = UC_BREAK_PROHIBITED; + break; + default: + abort (); + } + } + last_prop = prop; + seen_space = NULL; + seen_space2 = NULL; + } + } s += count; p += count; diff --git a/lib/unilbrk/u16-width-linebreaks.c b/lib/unilbrk/u16-width-linebreaks.c index 644455906..c6f729e7d 100644 --- a/lib/unilbrk/u16-width-linebreaks.c +++ b/lib/unilbrk/u16-width-linebreaks.c @@ -25,9 +25,9 @@ int u16_width_linebreaks (const uint16_t *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { const uint16_t *s_end; char *last_p; @@ -47,53 +47,53 @@ u16_width_linebreaks (const uint16_t *s, size_t n, /* Respect the override. */ if (o != NULL && *o != UC_BREAK_UNDEFINED) - *p = *o; + *p = *o; if (*p == UC_BREAK_POSSIBLE || *p == UC_BREAK_MANDATORY) - { - /* An atomic piece of text ends here. */ - if (last_p != NULL && last_column + piece_width > width) - { - /* Insert a line break. */ - *last_p = UC_BREAK_POSSIBLE; - last_column = 0; - } - } + { + /* An atomic piece of text ends here. */ + if (last_p != NULL && last_column + piece_width > width) + { + /* Insert a line break. */ + *last_p = UC_BREAK_POSSIBLE; + last_column = 0; + } + } if (*p == UC_BREAK_MANDATORY) - { - /* uc is a line break character. */ - /* Start a new piece at column 0. */ - last_p = NULL; - last_column = 0; - piece_width = 0; - } + { + /* uc is a line break character. */ + /* Start a new piece at column 0. */ + last_p = NULL; + last_column = 0; + piece_width = 0; + } else - { - /* uc is not a line break character. */ - int w; - - if (*p == UC_BREAK_POSSIBLE) - { - /* Start a new piece. */ - last_p = p; - last_column += piece_width; - piece_width = 0; - /* No line break for the moment, may be turned into - UC_BREAK_POSSIBLE later, via last_p. */ - } - - *p = UC_BREAK_PROHIBITED; - - w = uc_width (uc, encoding); - if (w >= 0) /* ignore control characters in the string */ - piece_width += w; - } + { + /* uc is not a line break character. */ + int w; + + if (*p == UC_BREAK_POSSIBLE) + { + /* Start a new piece. */ + last_p = p; + last_column += piece_width; + piece_width = 0; + /* No line break for the moment, may be turned into + UC_BREAK_POSSIBLE later, via last_p. */ + } + + *p = UC_BREAK_PROHIBITED; + + w = uc_width (uc, encoding); + if (w >= 0) /* ignore control characters in the string */ + piece_width += w; + } s += count; p += count; if (o != NULL) - o += count; + o += count; } /* The last atomic piece of text ends here. */ diff --git a/lib/unilbrk/u32-possible-linebreaks.c b/lib/unilbrk/u32-possible-linebreaks.c index c843e12b0..29f72f2b1 100644 --- a/lib/unilbrk/u32-possible-linebreaks.c +++ b/lib/unilbrk/u32-possible-linebreaks.c @@ -40,117 +40,117 @@ u32_possible_linebreaks (const uint32_t *s, size_t n, const char *encoding, char int prop = unilbrkprop_lookup (uc); if (prop == LBP_BK) - { - /* Mandatory break. */ - *p = UC_BREAK_MANDATORY; - last_prop = LBP_BK; - seen_space = NULL; - seen_space2 = NULL; - } + { + /* Mandatory break. */ + *p = UC_BREAK_MANDATORY; + last_prop = LBP_BK; + seen_space = NULL; + seen_space2 = NULL; + } else - { - char *q; + { + char *q; - /* Resolve property values whose behaviour is not fixed. */ - switch (prop) - { - case LBP_AI: - /* Resolve ambiguous. */ - prop = LBP_AI_REPLACEMENT; - break; - case LBP_CB: - /* This is arbitrary. */ - prop = LBP_ID; - break; - case LBP_SA: - /* We don't handle complex scripts yet. - Treat LBP_SA like LBP_XX. */ - case LBP_XX: - /* This is arbitrary. */ - prop = LBP_AL; - break; - } + /* Resolve property values whose behaviour is not fixed. */ + switch (prop) + { + case LBP_AI: + /* Resolve ambiguous. */ + prop = LBP_AI_REPLACEMENT; + break; + case LBP_CB: + /* This is arbitrary. */ + prop = LBP_ID; + break; + case LBP_SA: + /* We don't handle complex scripts yet. + Treat LBP_SA like LBP_XX. */ + case LBP_XX: + /* This is arbitrary. */ + prop = LBP_AL; + break; + } - /* Deal with spaces and combining characters. */ - q = p; - if (prop == LBP_SP) - { - /* Don't break just before a space. */ - *p = UC_BREAK_PROHIBITED; - seen_space2 = seen_space; - seen_space = p; - } - else if (prop == LBP_ZW) - { - /* Don't break just before a zero-width space. */ - *p = UC_BREAK_PROHIBITED; - last_prop = LBP_ZW; - seen_space = NULL; - seen_space2 = NULL; - } - else if (prop == LBP_CM) - { - /* Don't break just before a combining character, except immediately after a - zero-width space. */ - if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *p = UC_BREAK_POSSIBLE; - /* A combining character turns a preceding space into LBP_ID. */ - last_prop = LBP_ID; - } - else - { - *p = UC_BREAK_PROHIBITED; - /* A combining character turns a preceding space into LBP_ID. */ - if (seen_space != NULL) - { - q = seen_space; - seen_space = seen_space2; - prop = LBP_ID; - goto lookup_via_table; - } - } - } - else - { - lookup_via_table: - /* prop must be usable as an index for table 7.3 of UTR #14. */ - if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) - abort (); + /* Deal with spaces and combining characters. */ + q = p; + if (prop == LBP_SP) + { + /* Don't break just before a space. */ + *p = UC_BREAK_PROHIBITED; + seen_space2 = seen_space; + seen_space = p; + } + else if (prop == LBP_ZW) + { + /* Don't break just before a zero-width space. */ + *p = UC_BREAK_PROHIBITED; + last_prop = LBP_ZW; + seen_space = NULL; + seen_space2 = NULL; + } + else if (prop == LBP_CM) + { + /* Don't break just before a combining character, except immediately after a + zero-width space. */ + if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *p = UC_BREAK_POSSIBLE; + /* A combining character turns a preceding space into LBP_ID. */ + last_prop = LBP_ID; + } + else + { + *p = UC_BREAK_PROHIBITED; + /* A combining character turns a preceding space into LBP_ID. */ + if (seen_space != NULL) + { + q = seen_space; + seen_space = seen_space2; + prop = LBP_ID; + goto lookup_via_table; + } + } + } + else + { + lookup_via_table: + /* prop must be usable as an index for table 7.3 of UTR #14. */ + if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) + abort (); - if (last_prop == LBP_BK) - { - /* Don't break at the beginning of a line. */ - *q = UC_BREAK_PROHIBITED; - } - else if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *q = UC_BREAK_POSSIBLE; - } - else - { - switch (unilbrk_table [last_prop] [prop]) - { - case D: - *q = UC_BREAK_POSSIBLE; - break; - case I: - *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); - break; - case P: - *q = UC_BREAK_PROHIBITED; - break; - default: - abort (); - } - } - last_prop = prop; - seen_space = NULL; - seen_space2 = NULL; - } - } + if (last_prop == LBP_BK) + { + /* Don't break at the beginning of a line. */ + *q = UC_BREAK_PROHIBITED; + } + else if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *q = UC_BREAK_POSSIBLE; + } + else + { + switch (unilbrk_table [last_prop] [prop]) + { + case D: + *q = UC_BREAK_POSSIBLE; + break; + case I: + *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); + break; + case P: + *q = UC_BREAK_PROHIBITED; + break; + default: + abort (); + } + } + last_prop = prop; + seen_space = NULL; + seen_space2 = NULL; + } + } s++; p++; diff --git a/lib/unilbrk/u32-width-linebreaks.c b/lib/unilbrk/u32-width-linebreaks.c index 2d3625609..6ffbda9e2 100644 --- a/lib/unilbrk/u32-width-linebreaks.c +++ b/lib/unilbrk/u32-width-linebreaks.c @@ -24,9 +24,9 @@ int u32_width_linebreaks (const uint32_t *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { const uint32_t *s_end; char *last_p; @@ -45,53 +45,53 @@ u32_width_linebreaks (const uint32_t *s, size_t n, /* Respect the override. */ if (o != NULL && *o != UC_BREAK_UNDEFINED) - *p = *o; + *p = *o; if (*p == UC_BREAK_POSSIBLE || *p == UC_BREAK_MANDATORY) - { - /* An atomic piece of text ends here. */ - if (last_p != NULL && last_column + piece_width > width) - { - /* Insert a line break. */ - *last_p = UC_BREAK_POSSIBLE; - last_column = 0; - } - } + { + /* An atomic piece of text ends here. */ + if (last_p != NULL && last_column + piece_width > width) + { + /* Insert a line break. */ + *last_p = UC_BREAK_POSSIBLE; + last_column = 0; + } + } if (*p == UC_BREAK_MANDATORY) - { - /* uc is a line break character. */ - /* Start a new piece at column 0. */ - last_p = NULL; - last_column = 0; - piece_width = 0; - } + { + /* uc is a line break character. */ + /* Start a new piece at column 0. */ + last_p = NULL; + last_column = 0; + piece_width = 0; + } else - { - /* uc is not a line break character. */ - int w; - - if (*p == UC_BREAK_POSSIBLE) - { - /* Start a new piece. */ - last_p = p; - last_column += piece_width; - piece_width = 0; - /* No line break for the moment, may be turned into - UC_BREAK_POSSIBLE later, via last_p. */ - } - - *p = UC_BREAK_PROHIBITED; - - w = uc_width (uc, encoding); - if (w >= 0) /* ignore control characters in the string */ - piece_width += w; - } + { + /* uc is not a line break character. */ + int w; + + if (*p == UC_BREAK_POSSIBLE) + { + /* Start a new piece. */ + last_p = p; + last_column += piece_width; + piece_width = 0; + /* No line break for the moment, may be turned into + UC_BREAK_POSSIBLE later, via last_p. */ + } + + *p = UC_BREAK_PROHIBITED; + + w = uc_width (uc, encoding); + if (w >= 0) /* ignore control characters in the string */ + piece_width += w; + } s++; p++; if (o != NULL) - o++; + o++; } /* The last atomic piece of text ends here. */ diff --git a/lib/unilbrk/u8-possible-linebreaks.c b/lib/unilbrk/u8-possible-linebreaks.c index 94e14f40b..483b36192 100644 --- a/lib/unilbrk/u8-possible-linebreaks.c +++ b/lib/unilbrk/u8-possible-linebreaks.c @@ -46,117 +46,117 @@ u8_possible_linebreaks (const uint8_t *s, size_t n, const char *encoding, char * int prop = unilbrkprop_lookup (uc); if (prop == LBP_BK) - { - /* Mandatory break. */ - *p = UC_BREAK_MANDATORY; - last_prop = LBP_BK; - seen_space = NULL; - seen_space2 = NULL; - } + { + /* Mandatory break. */ + *p = UC_BREAK_MANDATORY; + last_prop = LBP_BK; + seen_space = NULL; + seen_space2 = NULL; + } else - { - char *q; + { + char *q; - /* Resolve property values whose behaviour is not fixed. */ - switch (prop) - { - case LBP_AI: - /* Resolve ambiguous. */ - prop = LBP_AI_REPLACEMENT; - break; - case LBP_CB: - /* This is arbitrary. */ - prop = LBP_ID; - break; - case LBP_SA: - /* We don't handle complex scripts yet. - Treat LBP_SA like LBP_XX. */ - case LBP_XX: - /* This is arbitrary. */ - prop = LBP_AL; - break; - } + /* Resolve property values whose behaviour is not fixed. */ + switch (prop) + { + case LBP_AI: + /* Resolve ambiguous. */ + prop = LBP_AI_REPLACEMENT; + break; + case LBP_CB: + /* This is arbitrary. */ + prop = LBP_ID; + break; + case LBP_SA: + /* We don't handle complex scripts yet. + Treat LBP_SA like LBP_XX. */ + case LBP_XX: + /* This is arbitrary. */ + prop = LBP_AL; + break; + } - /* Deal with spaces and combining characters. */ - q = p; - if (prop == LBP_SP) - { - /* Don't break just before a space. */ - *p = UC_BREAK_PROHIBITED; - seen_space2 = seen_space; - seen_space = p; - } - else if (prop == LBP_ZW) - { - /* Don't break just before a zero-width space. */ - *p = UC_BREAK_PROHIBITED; - last_prop = LBP_ZW; - seen_space = NULL; - seen_space2 = NULL; - } - else if (prop == LBP_CM) - { - /* Don't break just before a combining character, except immediately after a - zero-width space. */ - if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *p = UC_BREAK_POSSIBLE; - /* A combining character turns a preceding space into LBP_ID. */ - last_prop = LBP_ID; - } - else - { - *p = UC_BREAK_PROHIBITED; - /* A combining character turns a preceding space into LBP_ID. */ - if (seen_space != NULL) - { - q = seen_space; - seen_space = seen_space2; - prop = LBP_ID; - goto lookup_via_table; - } - } - } - else - { - lookup_via_table: - /* prop must be usable as an index for table 7.3 of UTR #14. */ - if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) - abort (); + /* Deal with spaces and combining characters. */ + q = p; + if (prop == LBP_SP) + { + /* Don't break just before a space. */ + *p = UC_BREAK_PROHIBITED; + seen_space2 = seen_space; + seen_space = p; + } + else if (prop == LBP_ZW) + { + /* Don't break just before a zero-width space. */ + *p = UC_BREAK_PROHIBITED; + last_prop = LBP_ZW; + seen_space = NULL; + seen_space2 = NULL; + } + else if (prop == LBP_CM) + { + /* Don't break just before a combining character, except immediately after a + zero-width space. */ + if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *p = UC_BREAK_POSSIBLE; + /* A combining character turns a preceding space into LBP_ID. */ + last_prop = LBP_ID; + } + else + { + *p = UC_BREAK_PROHIBITED; + /* A combining character turns a preceding space into LBP_ID. */ + if (seen_space != NULL) + { + q = seen_space; + seen_space = seen_space2; + prop = LBP_ID; + goto lookup_via_table; + } + } + } + else + { + lookup_via_table: + /* prop must be usable as an index for table 7.3 of UTR #14. */ + if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) + abort (); - if (last_prop == LBP_BK) - { - /* Don't break at the beginning of a line. */ - *q = UC_BREAK_PROHIBITED; - } - else if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *q = UC_BREAK_POSSIBLE; - } - else - { - switch (unilbrk_table [last_prop] [prop]) - { - case D: - *q = UC_BREAK_POSSIBLE; - break; - case I: - *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); - break; - case P: - *q = UC_BREAK_PROHIBITED; - break; - default: - abort (); - } - } - last_prop = prop; - seen_space = NULL; - seen_space2 = NULL; - } - } + if (last_prop == LBP_BK) + { + /* Don't break at the beginning of a line. */ + *q = UC_BREAK_PROHIBITED; + } + else if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *q = UC_BREAK_POSSIBLE; + } + else + { + switch (unilbrk_table [last_prop] [prop]) + { + case D: + *q = UC_BREAK_POSSIBLE; + break; + case I: + *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); + break; + case P: + *q = UC_BREAK_PROHIBITED; + break; + default: + abort (); + } + } + last_prop = prop; + seen_space = NULL; + seen_space2 = NULL; + } + } s += count; p += count; @@ -183,28 +183,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -231,24 +231,24 @@ main (int argc, char * argv[]) u8_possible_linebreaks ((uint8_t *) input, length, "UTF-8", breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - /* U+2027 in UTF-8 encoding */ - putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); - break; - case UC_BREAK_MANDATORY: - /* U+21B2 (or U+21B5) in UTF-8 encoding */ - putc (0xe2, stdout); putc (0x86, stdout); putc (0xb2, stdout); - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + /* U+2027 in UTF-8 encoding */ + putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); + break; + case UC_BREAK_MANDATORY: + /* U+21B2 (or U+21B5) in UTF-8 encoding */ + putc (0xe2, stdout); putc (0x86, stdout); putc (0xb2, stdout); + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/unilbrk/u8-width-linebreaks.c b/lib/unilbrk/u8-width-linebreaks.c index 7e7f2e97d..35ac8bf15 100644 --- a/lib/unilbrk/u8-width-linebreaks.c +++ b/lib/unilbrk/u8-width-linebreaks.c @@ -25,9 +25,9 @@ int u8_width_linebreaks (const uint8_t *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { const uint8_t *s_end; char *last_p; @@ -47,53 +47,53 @@ u8_width_linebreaks (const uint8_t *s, size_t n, /* Respect the override. */ if (o != NULL && *o != UC_BREAK_UNDEFINED) - *p = *o; + *p = *o; if (*p == UC_BREAK_POSSIBLE || *p == UC_BREAK_MANDATORY) - { - /* An atomic piece of text ends here. */ - if (last_p != NULL && last_column + piece_width > width) - { - /* Insert a line break. */ - *last_p = UC_BREAK_POSSIBLE; - last_column = 0; - } - } + { + /* An atomic piece of text ends here. */ + if (last_p != NULL && last_column + piece_width > width) + { + /* Insert a line break. */ + *last_p = UC_BREAK_POSSIBLE; + last_column = 0; + } + } if (*p == UC_BREAK_MANDATORY) - { - /* uc is a line break character. */ - /* Start a new piece at column 0. */ - last_p = NULL; - last_column = 0; - piece_width = 0; - } + { + /* uc is a line break character. */ + /* Start a new piece at column 0. */ + last_p = NULL; + last_column = 0; + piece_width = 0; + } else - { - /* uc is not a line break character. */ - int w; - - if (*p == UC_BREAK_POSSIBLE) - { - /* Start a new piece. */ - last_p = p; - last_column += piece_width; - piece_width = 0; - /* No line break for the moment, may be turned into - UC_BREAK_POSSIBLE later, via last_p. */ - } - - *p = UC_BREAK_PROHIBITED; - - w = uc_width (uc, encoding); - if (w >= 0) /* ignore control characters in the string */ - piece_width += w; - } + { + /* uc is not a line break character. */ + int w; + + if (*p == UC_BREAK_POSSIBLE) + { + /* Start a new piece. */ + last_p = p; + last_column += piece_width; + piece_width = 0; + /* No line break for the moment, may be turned into + UC_BREAK_POSSIBLE later, via last_p. */ + } + + *p = UC_BREAK_PROHIBITED; + + w = uc_width (uc, encoding); + if (w >= 0) /* ignore control characters in the string */ + piece_width += w; + } s += count; p += count; if (o != NULL) - o += count; + o += count; } /* The last atomic piece of text ends here. */ @@ -128,28 +128,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -177,21 +177,21 @@ main (int argc, char * argv[]) u8_width_linebreaks ((uint8_t *) input, length, width, 0, 0, NULL, "UTF-8", breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - putc ('\n', stdout); - break; - case UC_BREAK_MANDATORY: - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + putc ('\n', stdout); + break; + case UC_BREAK_MANDATORY: + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/unilbrk/ulc-common.c b/lib/unilbrk/ulc-common.c index d035ded72..7ee7713ba 100644 --- a/lib/unilbrk/ulc-common.c +++ b/lib/unilbrk/ulc-common.c @@ -43,7 +43,7 @@ is_all_ascii (const char *s, size_t n) unsigned char c = (unsigned char) *s; if (!(c_isprint (c) || c_isspace (c))) - return 0; + return 0; } return 1; } diff --git a/lib/unilbrk/ulc-possible-linebreaks.c b/lib/unilbrk/ulc-possible-linebreaks.c index cb952419b..8fc863515 100644 --- a/lib/unilbrk/ulc-possible-linebreaks.c +++ b/lib/unilbrk/ulc-possible-linebreaks.c @@ -42,76 +42,76 @@ void ulc_possible_linebreaks (const char *s, size_t n, const char *encoding, - char *p) + char *p) { if (n > 0) { if (is_utf8_encoding (encoding)) - u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); + u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); else - { - /* Convert the string to UTF-8 and build a translation table - from offsets into s to offsets into the translated string. */ - size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); - - if (offsets != NULL) - { - uint8_t *t; - size_t m; - - t = u8_conv_from_encoding (encoding, iconveh_question_mark, - s, n, offsets, NULL, &m); - if (t != NULL) - { - char *q = (char *) (m > 0 ? malloc (m) : NULL); - - if (m == 0 || q != NULL) - { - size_t i; - - /* Determine the possible line breaks of the UTF-8 - string. */ - u8_possible_linebreaks (t, m, encoding, q); - - /* Translate the result back to the original string. */ - memset (p, UC_BREAK_PROHIBITED, n); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - p[i] = q[offsets[i]]; - - free (q); - free (t); - free (offsets); - return; - } - free (t); - } - free (offsets); - } - - /* Impossible to convert. */ + { + /* Convert the string to UTF-8 and build a translation table + from offsets into s to offsets into the translated string. */ + size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); + + if (offsets != NULL) + { + uint8_t *t; + size_t m; + + t = u8_conv_from_encoding (encoding, iconveh_question_mark, + s, n, offsets, NULL, &m); + if (t != NULL) + { + char *q = (char *) (m > 0 ? malloc (m) : NULL); + + if (m == 0 || q != NULL) + { + size_t i; + + /* Determine the possible line breaks of the UTF-8 + string. */ + u8_possible_linebreaks (t, m, encoding, q); + + /* Translate the result back to the original string. */ + memset (p, UC_BREAK_PROHIBITED, n); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + p[i] = q[offsets[i]]; + + free (q); + free (t); + free (offsets); + return; + } + free (t); + } + free (offsets); + } + + /* Impossible to convert. */ #if C_CTYPE_ASCII - if (is_all_ascii (s, n)) - { - /* ASCII is a subset of UTF-8. */ - u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); - return; - } + if (is_all_ascii (s, n)) + { + /* ASCII is a subset of UTF-8. */ + u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); + return; + } #endif - /* We have a non-ASCII string and cannot convert it. - Don't produce line breaks except those already present in the - input string. All we assume here is that the encoding is - minimally ASCII compatible. */ - { - const char *s_end = s + n; - while (s < s_end) - { - *p = (*s == '\n' ? UC_BREAK_MANDATORY : UC_BREAK_PROHIBITED); - s++; - p++; - } - } - } + /* We have a non-ASCII string and cannot convert it. + Don't produce line breaks except those already present in the + input string. All we assume here is that the encoding is + minimally ASCII compatible. */ + { + const char *s_end = s + n; + while (s < s_end) + { + *p = (*s == '\n' ? UC_BREAK_MANDATORY : UC_BREAK_PROHIBITED); + s++; + p++; + } + } + } } } @@ -136,28 +136,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -185,21 +185,21 @@ main (int argc, char * argv[]) ulc_possible_linebreaks (input, length, locale_charset (), breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - putc ('|', stdout); - break; - case UC_BREAK_MANDATORY: - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + putc ('|', stdout); + break; + case UC_BREAK_MANDATORY: + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/unilbrk/ulc-width-linebreaks.c b/lib/unilbrk/ulc-width-linebreaks.c index 3b091bf2e..5b81b8df6 100644 --- a/lib/unilbrk/ulc-width-linebreaks.c +++ b/lib/unilbrk/ulc-width-linebreaks.c @@ -42,94 +42,94 @@ int ulc_width_linebreaks (const char *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { if (n > 0) { if (is_utf8_encoding (encoding)) - return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); + return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); else - { - /* Convert the string to UTF-8 and build a translation table - from offsets into s to offsets into the translated string. */ - size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); - - if (offsets != NULL) - { - uint8_t *t; - size_t m; - - t = u8_conv_from_encoding (encoding, iconveh_question_mark, - s, n, offsets, NULL, &m); - if (t != NULL) - { - char *memory = - (char *) (m > 0 ? malloc (m + (o != NULL ? m : 0)) : NULL); - - if (m == 0 || memory != NULL) - { - char *q = (char *) memory; - char *o8 = (o != NULL ? (char *) (q + m) : NULL); - int res_column; - size_t i; - - /* Translate the overrides to the UTF-8 string. */ - if (o != NULL) - { - memset (o8, UC_BREAK_UNDEFINED, m); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - o8[offsets[i]] = o[i]; - } - - /* Determine the line breaks of the UTF-8 string. */ - res_column = - u8_width_linebreaks (t, m, width, start_column, at_end_columns, o8, encoding, q); - - /* Translate the result back to the original string. */ - memset (p, UC_BREAK_PROHIBITED, n); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - p[i] = q[offsets[i]]; - - free (memory); - free (t); - free (offsets); - return res_column; - } - free (t); - } - free (offsets); - } - /* Impossible to convert. */ + { + /* Convert the string to UTF-8 and build a translation table + from offsets into s to offsets into the translated string. */ + size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); + + if (offsets != NULL) + { + uint8_t *t; + size_t m; + + t = u8_conv_from_encoding (encoding, iconveh_question_mark, + s, n, offsets, NULL, &m); + if (t != NULL) + { + char *memory = + (char *) (m > 0 ? malloc (m + (o != NULL ? m : 0)) : NULL); + + if (m == 0 || memory != NULL) + { + char *q = (char *) memory; + char *o8 = (o != NULL ? (char *) (q + m) : NULL); + int res_column; + size_t i; + + /* Translate the overrides to the UTF-8 string. */ + if (o != NULL) + { + memset (o8, UC_BREAK_UNDEFINED, m); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + o8[offsets[i]] = o[i]; + } + + /* Determine the line breaks of the UTF-8 string. */ + res_column = + u8_width_linebreaks (t, m, width, start_column, at_end_columns, o8, encoding, q); + + /* Translate the result back to the original string. */ + memset (p, UC_BREAK_PROHIBITED, n); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + p[i] = q[offsets[i]]; + + free (memory); + free (t); + free (offsets); + return res_column; + } + free (t); + } + free (offsets); + } + /* Impossible to convert. */ #if C_CTYPE_ASCII - if (is_all_ascii (s, n)) - { - /* ASCII is a subset of UTF-8. */ - return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); - } + if (is_all_ascii (s, n)) + { + /* ASCII is a subset of UTF-8. */ + return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); + } #endif - /* We have a non-ASCII string and cannot convert it. - Don't produce line breaks except those already present in the - input string. All we assume here is that the encoding is - minimally ASCII compatible. */ - { - const char *s_end = s + n; - while (s < s_end) - { - *p = ((o != NULL && *o == UC_BREAK_MANDATORY) || *s == '\n' - ? UC_BREAK_MANDATORY - : UC_BREAK_PROHIBITED); - s++; - p++; - if (o != NULL) - o++; - } - /* We cannot compute widths in this case. */ - } - } + /* We have a non-ASCII string and cannot convert it. + Don't produce line breaks except those already present in the + input string. All we assume here is that the encoding is + minimally ASCII compatible. */ + { + const char *s_end = s + n; + while (s < s_end) + { + *p = ((o != NULL && *o == UC_BREAK_MANDATORY) || *s == '\n' + ? UC_BREAK_MANDATORY + : UC_BREAK_PROHIBITED); + s++; + p++; + if (o != NULL) + o++; + } + /* We cannot compute widths in this case. */ + } + } } return start_column; } @@ -154,28 +154,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -204,21 +204,21 @@ main (int argc, char * argv[]) ulc_width_linebreaks (input, length, width, 0, 0, NULL, locale_charset (), breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - putc ('\n', stdout); - break; - case UC_BREAK_MANDATORY: - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + putc ('\n', stdout); + break; + case UC_BREAK_MANDATORY: + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/uniname/uniname.c b/lib/uniname/uniname.c index bef58af31..04938fe9c 100644 --- a/lib/uniname/uniname.c +++ b/lib/uniname/uniname.c @@ -73,16 +73,16 @@ unicode_name_word (unsigned int index, unsigned int *lengthp) { unsigned int i = (i1 + i2) >> 1; if (unicode_name_by_length[i].ind_offset <= index) - i1 = i; + i1 = i; else - i2 = i; + i2 = i; } i = i1; assert (unicode_name_by_length[i].ind_offset <= index - && index < unicode_name_by_length[i+1].ind_offset); + && index < unicode_name_by_length[i+1].ind_offset); *lengthp = i; return &unicode_name_words[unicode_name_by_length[i].extra_offset - + (index-unicode_name_by_length[i].ind_offset)*i]; + + (index-unicode_name_by_length[i].ind_offset)*i]; } /* Looks up the index of a word. */ @@ -97,32 +97,32 @@ unicode_name_word_lookup (const char *word, unsigned int length) unsigned int i1 = i0; unsigned int i2 = unicode_name_by_length[length+1].ind_offset; while (i2 - i1 > 0) - { - unsigned int i = (i1 + i2) >> 1; - const char *p = &unicode_name_words[extra_offset + (i-i0)*length]; - const char *w = word; - unsigned int n = length; - for (;;) - { - if (*p < *w) - { - if (i1 == i) - return -1; - /* Note here: i1 < i < i2. */ - i1 = i; - break; - } - if (*p > *w) - { - /* Note here: i1 <= i < i2. */ - i2 = i; - break; - } - p++; w++; n--; - if (n == 0) - return i; - } - } + { + unsigned int i = (i1 + i2) >> 1; + const char *p = &unicode_name_words[extra_offset + (i-i0)*length]; + const char *w = word; + unsigned int n = length; + for (;;) + { + if (*p < *w) + { + if (i1 == i) + return -1; + /* Note here: i1 < i < i2. */ + i1 = i; + break; + } + if (*p > *w) + { + /* Note here: i1 <= i < i2. */ + i2 = i; + break; + } + p++; w++; n--; + if (n == 0) + return i; + } + } } return -1; } @@ -171,21 +171,21 @@ unicode_character_name (ucs4_t c, char *buf) q = jamo_initial_short_name[index1]; while (*q != '\0') - *ptr++ = *q++; + *ptr++ = *q++; q = jamo_medial_short_name[index2]; while (*q != '\0') - *ptr++ = *q++; + *ptr++ = *q++; q = jamo_final_short_name[index3]; while (*q != '\0') - *ptr++ = *q++; + *ptr++ = *q++; *ptr = '\0'; return buf; } else if ((c >= 0xF900 && c <= 0xFA2D) || (c >= 0xFA30 && c <= 0xFA6A) - || (c >= 0xFA70 && c <= 0xFAD9) || (c >= 0x2F800 && c <= 0x2FA1D)) + || (c >= 0xFA70 && c <= 0xFAD9) || (c >= 0x2F800 && c <= 0x2FA1D)) { /* Special case for CJK compatibility ideographs. Keeps the tables - small. */ + small. */ char *ptr; int i; @@ -194,10 +194,10 @@ unicode_character_name (ucs4_t c, char *buf) ptr = buf + 28; for (i = (c < 0x10000 ? 12 : 16); i >= 0; i -= 4) - { - unsigned int x = (c >> i) & 0xf; - *ptr++ = (x < 10 ? '0' : 'A' - 10) + x; - } + { + unsigned int x = (c >> i) & 0xf; + *ptr++ = (x < 10 ? '0' : 'A' - 10) + x; + } *ptr = '\0'; return buf; } @@ -207,91 +207,91 @@ unicode_character_name (ucs4_t c, char *buf) /* Transform the code so that it fits in 16 bits. */ switch (c >> 12) - { - case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: - break; - case 0x0A: - c -= 0x05000; - break; - case 0x0F: - c -= 0x09000; - break; - case 0x10: - c -= 0x09000; - break; - case 0x12: - c -= 0x0A000; - break; - case 0x1D: - c -= 0x14000; - break; - case 0x1F: - c -= 0x15000; - break; - case 0x2F: - c -= 0x24000; - break; - case 0xE0: - c -= 0xD4000; - break; - default: - return NULL; - } + { + case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: + break; + case 0x0A: + c -= 0x05000; + break; + case 0x0F: + c -= 0x09000; + break; + case 0x10: + c -= 0x09000; + break; + case 0x12: + c -= 0x0A000; + break; + case 0x1D: + c -= 0x14000; + break; + case 0x1F: + c -= 0x15000; + break; + case 0x2F: + c -= 0x24000; + break; + case 0xE0: + c -= 0xD4000; + break; + default: + return NULL; + } { - /* Binary search in unicode_code_to_name. */ - unsigned int i1 = 0; - unsigned int i2 = SIZEOF (unicode_code_to_name); - for (;;) - { - unsigned int i = (i1 + i2) >> 1; - if (unicode_code_to_name[i].code == c) - { - words = &unicode_names[unicode_code_to_name[i].name]; - break; - } - else if (unicode_code_to_name[i].code < c) - { - if (i1 == i) - { - words = NULL; - break; - } - /* Note here: i1 < i < i2. */ - i1 = i; - } - else if (unicode_code_to_name[i].code > c) - { - if (i2 == i) - { - words = NULL; - break; - } - /* Note here: i1 <= i < i2. */ - i2 = i; - } - } + /* Binary search in unicode_code_to_name. */ + unsigned int i1 = 0; + unsigned int i2 = SIZEOF (unicode_code_to_name); + for (;;) + { + unsigned int i = (i1 + i2) >> 1; + if (unicode_code_to_name[i].code == c) + { + words = &unicode_names[unicode_code_to_name[i].name]; + break; + } + else if (unicode_code_to_name[i].code < c) + { + if (i1 == i) + { + words = NULL; + break; + } + /* Note here: i1 < i < i2. */ + i1 = i; + } + else if (unicode_code_to_name[i].code > c) + { + if (i2 == i) + { + words = NULL; + break; + } + /* Note here: i1 <= i < i2. */ + i2 = i; + } + } } if (words != NULL) - { - /* Found it in unicode_code_to_name. Now concatenate the words. */ - /* buf needs to have at least UNICODE_CHARNAME_MAX_LENGTH bytes. */ - char *ptr = buf; - for (;;) - { - unsigned int wordlen; - const char *word = unicode_name_word (*words>>1, &wordlen); - do - *ptr++ = *word++; - while (--wordlen > 0); - if ((*words & 1) == 0) - break; - *ptr++ = ' '; - words++; - } - *ptr = '\0'; - return buf; - } + { + /* Found it in unicode_code_to_name. Now concatenate the words. */ + /* buf needs to have at least UNICODE_CHARNAME_MAX_LENGTH bytes. */ + char *ptr = buf; + for (;;) + { + unsigned int wordlen; + const char *word = unicode_name_word (*words>>1, &wordlen); + do + *ptr++ = *word++; + while (--wordlen > 0); + if ((*words & 1) == 0) + break; + *ptr++ = ' '; + words++; + } + *ptr = '\0'; + return buf; + } return NULL; } } @@ -308,209 +308,209 @@ unicode_name_character (const char *name) char buf[UNICODE_CHARNAME_MAX_LENGTH]; char *ptr = buf; for (;;) - { - char c = *name++; - if (!(c >= ' ' && c <= '~')) - break; - *ptr++ = (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); - if (--len == 0) - goto filled_buf; - } + { + char c = *name++; + if (!(c >= ' ' && c <= '~')) + break; + *ptr++ = (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); + if (--len == 0) + goto filled_buf; + } if (false) filled_buf: - { - /* Convert the constituents to uint16_t words. */ - uint16_t words[UNICODE_CHARNAME_MAX_WORDS]; - uint16_t *wordptr = words; - { - const char *p1 = buf; - for (;;) - { - { - int word; - const char *p2 = p1; - while (p2 < ptr && *p2 != ' ') - p2++; - word = unicode_name_word_lookup (p1, p2 - p1); - if (word < 0) - break; - if (wordptr == &words[UNICODE_CHARNAME_MAX_WORDS]) - break; - *wordptr++ = word; - if (p2 == ptr) - goto filled_words; - p1 = p2 + 1; - } - /* Special case for Hangul syllables. Keeps the tables small. */ - if (wordptr == &words[2] - && words[0] == UNICODE_CHARNAME_WORD_HANGUL - && words[1] == UNICODE_CHARNAME_WORD_SYLLABLE) - { - /* Split the last word [p1..ptr) into three parts: - 1) [BCDGHJKMNPRST] - 2) [AEIOUWY] - 3) [BCDGHIJKLMNPST] - */ - const char *p2; - const char *p3; - const char *p4; - - p2 = p1; - while (p2 < ptr - && (*p2 == 'B' || *p2 == 'C' || *p2 == 'D' - || *p2 == 'G' || *p2 == 'H' || *p2 == 'J' - || *p2 == 'K' || *p2 == 'M' || *p2 == 'N' - || *p2 == 'P' || *p2 == 'R' || *p2 == 'S' - || *p2 == 'T')) - p2++; - p3 = p2; - while (p3 < ptr - && (*p3 == 'A' || *p3 == 'E' || *p3 == 'I' - || *p3 == 'O' || *p3 == 'U' || *p3 == 'W' - || *p3 == 'Y')) - p3++; - p4 = p3; - while (p4 < ptr - && (*p4 == 'B' || *p4 == 'C' || *p4 == 'D' - || *p4 == 'G' || *p4 == 'H' || *p4 == 'I' - || *p4 == 'J' || *p4 == 'K' || *p4 == 'L' - || *p4 == 'M' || *p4 == 'N' || *p4 == 'P' - || *p4 == 'S' || *p4 == 'T')) - p4++; - if (p4 == ptr) - { - unsigned int n1 = p2 - p1; - unsigned int n2 = p3 - p2; - unsigned int n3 = p4 - p3; - - if (n1 <= 2 && (n2 >= 1 && n2 <= 3) && n3 <= 2) - { - unsigned int index1; - - for (index1 = 0; index1 < 19; index1++) - if (memcmp(jamo_initial_short_name[index1], p1, n1) == 0 - && jamo_initial_short_name[index1][n1] == '\0') - { - unsigned int index2; - - for (index2 = 0; index2 < 21; index2++) - if (memcmp(jamo_medial_short_name[index2], p2, n2) == 0 - && jamo_medial_short_name[index2][n2] == '\0') - { - unsigned int index3; - - for (index3 = 0; index3 < 28; index3++) - if (memcmp(jamo_final_short_name[index3], p3, n3) == 0 - && jamo_final_short_name[index3][n3] == '\0') - { - return 0xAC00 + (index1 * 21 + index2) * 28 + index3; - } - break; - } - break; - } - } - } - } - /* Special case for CJK compatibility ideographs. Keeps the - tables small. */ - if (wordptr == &words[2] - && words[0] == UNICODE_CHARNAME_WORD_CJK - && words[1] == UNICODE_CHARNAME_WORD_COMPATIBILITY - && p1 + 14 <= ptr - && p1 + 15 >= ptr - && memcmp (p1, "IDEOGRAPH-", 10) == 0) - { - const char *p2 = p1 + 10; - - if (*p2 != '0') - { - unsigned int c = 0; - - for (;;) - { - if (*p2 >= '0' && *p2 <= '9') - c += (*p2 - '0'); - else if (*p2 >= 'A' && *p2 <= 'F') - c += (*p2 - 'A' + 10); - else - break; - p2++; - if (p2 == ptr) - { - if ((c >= 0xF900 && c <= 0xFA2D) - || (c >= 0xFA30 && c <= 0xFA6A) - || (c >= 0xFA70 && c <= 0xFAD9) - || (c >= 0x2F800 && c <= 0x2FA1D)) - return c; - else - break; - } - c = c << 4; - } - } - } - } - } - if (false) - filled_words: - { - /* Multiply by 2, to simplify later comparisons. */ - unsigned int words_length = wordptr - words; - { - int i = words_length - 1; - words[i] = 2 * words[i]; - for (; --i >= 0; ) - words[i] = 2 * words[i] + 1; - } - /* Binary search in unicode_name_to_code. */ - { - unsigned int i1 = 0; - unsigned int i2 = SIZEOF (unicode_name_to_code); - for (;;) - { - unsigned int i = (i1 + i2) >> 1; - const uint16_t *w = words; - const uint16_t *p = &unicode_names[unicode_name_to_code[i].name]; - unsigned int n = words_length; - for (;;) - { - if (*p < *w) - { - if (i1 == i) - goto name_not_found; - /* Note here: i1 < i < i2. */ - i1 = i; - break; - } - else if (*p > *w) - { - if (i2 == i) - goto name_not_found; - /* Note here: i1 <= i < i2. */ - i2 = i; - break; - } - p++; w++; n--; - if (n == 0) - { - unsigned int c = unicode_name_to_code[i].code; - - /* Undo the transformation to 16-bit space. */ - static const unsigned int offset[13] = - { - 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, - 0x05000, 0x09000, 0x09000, 0x0A000, 0x14000, - 0x15000, 0x24000, 0xD4000 - }; - return c + offset[c >> 12]; - } - } - } - } - name_not_found: ; - } - } + { + /* Convert the constituents to uint16_t words. */ + uint16_t words[UNICODE_CHARNAME_MAX_WORDS]; + uint16_t *wordptr = words; + { + const char *p1 = buf; + for (;;) + { + { + int word; + const char *p2 = p1; + while (p2 < ptr && *p2 != ' ') + p2++; + word = unicode_name_word_lookup (p1, p2 - p1); + if (word < 0) + break; + if (wordptr == &words[UNICODE_CHARNAME_MAX_WORDS]) + break; + *wordptr++ = word; + if (p2 == ptr) + goto filled_words; + p1 = p2 + 1; + } + /* Special case for Hangul syllables. Keeps the tables small. */ + if (wordptr == &words[2] + && words[0] == UNICODE_CHARNAME_WORD_HANGUL + && words[1] == UNICODE_CHARNAME_WORD_SYLLABLE) + { + /* Split the last word [p1..ptr) into three parts: + 1) [BCDGHJKMNPRST] + 2) [AEIOUWY] + 3) [BCDGHIJKLMNPST] + */ + const char *p2; + const char *p3; + const char *p4; + + p2 = p1; + while (p2 < ptr + && (*p2 == 'B' || *p2 == 'C' || *p2 == 'D' + || *p2 == 'G' || *p2 == 'H' || *p2 == 'J' + || *p2 == 'K' || *p2 == 'M' || *p2 == 'N' + || *p2 == 'P' || *p2 == 'R' || *p2 == 'S' + || *p2 == 'T')) + p2++; + p3 = p2; + while (p3 < ptr + && (*p3 == 'A' || *p3 == 'E' || *p3 == 'I' + || *p3 == 'O' || *p3 == 'U' || *p3 == 'W' + || *p3 == 'Y')) + p3++; + p4 = p3; + while (p4 < ptr + && (*p4 == 'B' || *p4 == 'C' || *p4 == 'D' + || *p4 == 'G' || *p4 == 'H' || *p4 == 'I' + || *p4 == 'J' || *p4 == 'K' || *p4 == 'L' + || *p4 == 'M' || *p4 == 'N' || *p4 == 'P' + || *p4 == 'S' || *p4 == 'T')) + p4++; + if (p4 == ptr) + { + unsigned int n1 = p2 - p1; + unsigned int n2 = p3 - p2; + unsigned int n3 = p4 - p3; + + if (n1 <= 2 && (n2 >= 1 && n2 <= 3) && n3 <= 2) + { + unsigned int index1; + + for (index1 = 0; index1 < 19; index1++) + if (memcmp(jamo_initial_short_name[index1], p1, n1) == 0 + && jamo_initial_short_name[index1][n1] == '\0') + { + unsigned int index2; + + for (index2 = 0; index2 < 21; index2++) + if (memcmp(jamo_medial_short_name[index2], p2, n2) == 0 + && jamo_medial_short_name[index2][n2] == '\0') + { + unsigned int index3; + + for (index3 = 0; index3 < 28; index3++) + if (memcmp(jamo_final_short_name[index3], p3, n3) == 0 + && jamo_final_short_name[index3][n3] == '\0') + { + return 0xAC00 + (index1 * 21 + index2) * 28 + index3; + } + break; + } + break; + } + } + } + } + /* Special case for CJK compatibility ideographs. Keeps the + tables small. */ + if (wordptr == &words[2] + && words[0] == UNICODE_CHARNAME_WORD_CJK + && words[1] == UNICODE_CHARNAME_WORD_COMPATIBILITY + && p1 + 14 <= ptr + && p1 + 15 >= ptr + && memcmp (p1, "IDEOGRAPH-", 10) == 0) + { + const char *p2 = p1 + 10; + + if (*p2 != '0') + { + unsigned int c = 0; + + for (;;) + { + if (*p2 >= '0' && *p2 <= '9') + c += (*p2 - '0'); + else if (*p2 >= 'A' && *p2 <= 'F') + c += (*p2 - 'A' + 10); + else + break; + p2++; + if (p2 == ptr) + { + if ((c >= 0xF900 && c <= 0xFA2D) + || (c >= 0xFA30 && c <= 0xFA6A) + || (c >= 0xFA70 && c <= 0xFAD9) + || (c >= 0x2F800 && c <= 0x2FA1D)) + return c; + else + break; + } + c = c << 4; + } + } + } + } + } + if (false) + filled_words: + { + /* Multiply by 2, to simplify later comparisons. */ + unsigned int words_length = wordptr - words; + { + int i = words_length - 1; + words[i] = 2 * words[i]; + for (; --i >= 0; ) + words[i] = 2 * words[i] + 1; + } + /* Binary search in unicode_name_to_code. */ + { + unsigned int i1 = 0; + unsigned int i2 = SIZEOF (unicode_name_to_code); + for (;;) + { + unsigned int i = (i1 + i2) >> 1; + const uint16_t *w = words; + const uint16_t *p = &unicode_names[unicode_name_to_code[i].name]; + unsigned int n = words_length; + for (;;) + { + if (*p < *w) + { + if (i1 == i) + goto name_not_found; + /* Note here: i1 < i < i2. */ + i1 = i; + break; + } + else if (*p > *w) + { + if (i2 == i) + goto name_not_found; + /* Note here: i1 <= i < i2. */ + i2 = i; + break; + } + p++; w++; n--; + if (n == 0) + { + unsigned int c = unicode_name_to_code[i].code; + + /* Undo the transformation to 16-bit space. */ + static const unsigned int offset[13] = + { + 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, + 0x05000, 0x09000, 0x09000, 0x0A000, 0x14000, + 0x15000, 0x24000, 0xD4000 + }; + return c + offset[c >> 12]; + } + } + } + } + name_not_found: ; + } + } } return UNINAME_INVALID; } diff --git a/lib/uninorm.h b/lib/uninorm.h index 42a6dc17b..4f28a523b 100644 --- a/lib/uninorm.h +++ b/lib/uninorm.h @@ -140,13 +140,13 @@ extern uninorm_t uninorm_decomposing_form (uninorm_t nf); /* Return the specified normalization form of a string. */ extern uint8_t * u8_normalize (uninorm_t nf, const uint8_t *s, size_t n, - uint8_t *resultbuf, size_t *lengthp); + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_normalize (uninorm_t nf, const uint16_t *s, size_t n, - uint16_t *resultbuf, size_t *lengthp); + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_normalize (uninorm_t nf, const uint32_t *s, size_t n, - uint32_t *resultbuf, size_t *lengthp); + uint32_t *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in normalization. @@ -155,13 +155,13 @@ extern uint32_t * return 0. Upon failure, return -1 with errno set. */ extern int u8_normcmp (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u16_normcmp (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u32_normcmp (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); /* Converts the string S of length N to a NUL-terminated byte sequence, in such @@ -170,13 +170,13 @@ extern int NF must be either UNINORM_NFC or UNINORM_NFKC. */ extern char * u8_normxfrm (const uint8_t *s, size_t n, uninorm_t nf, - char *resultbuf, size_t *lengthp); + char *resultbuf, size_t *lengthp); extern char * u16_normxfrm (const uint16_t *s, size_t n, uninorm_t nf, - char *resultbuf, size_t *lengthp); + char *resultbuf, size_t *lengthp); extern char * u32_normxfrm (const uint32_t *s, size_t n, uninorm_t nf, - char *resultbuf, size_t *lengthp); + char *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in normalization, using the @@ -186,13 +186,13 @@ extern char * return 0. Upon failure, return -1 with errno set. */ extern int u8_normcoll (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u16_normcoll (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u32_normcoll (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); /* Normalization of a stream of Unicode characters. @@ -213,8 +213,8 @@ struct uninorm_filter; Return the new filter, or NULL with errno set upon failure. */ extern struct uninorm_filter * uninorm_filter_create (uninorm_t nf, - int (*stream_func) (void *stream_data, ucs4_t uc), - void *stream_data); + int (*stream_func) (void *stream_data, ucs4_t uc), + void *stream_data); /* Stuff a Unicode character into a normalizing filter. Return 0 if successful, or -1 with errno set upon failure. */ diff --git a/lib/uninorm/canonical-decomposition.c b/lib/uninorm/canonical-decomposition.c index 210b74b9c..f66e3d40f 100644 --- a/lib/uninorm/canonical-decomposition.c +++ b/lib/uninorm/canonical-decomposition.c @@ -31,77 +31,77 @@ uc_canonical_decomposition (ucs4_t uc, ucs4_t *decomposition) { /* Hangul syllable. See Unicode standard, chapter 3, section "Hangul Syllable Decomposition", See also the clarification at - , section - "Clarification of Hangul Jamo Handling". */ + , section + "Clarification of Hangul Jamo Handling". */ unsigned int t; uc -= 0xAC00; t = uc % 28; if (t == 0) - { - unsigned int v, l; + { + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - return 2; - } + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + return 2; + } else - { + { #if 1 /* Return the pairwise decomposition, not the full decomposition. */ - decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ - decomposition[1] = 0x11A7 + t; - return 2; + decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ + decomposition[1] = 0x11A7 + t; + return 2; #else - unsigned int v, l; + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - decomposition[2] = 0x11A7 + t; - return 3; + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + decomposition[2] = 0x11A7 + t; + return 3; #endif - } + } } else if (uc < 0x110000) { unsigned short entry = decomp_index (uc); /* An entry of (unsigned short)(-1) denotes an absent entry. - Otherwise, bit 15 of the entry tells whether the decomposition - is a canonical one. */ + Otherwise, bit 15 of the entry tells whether the decomposition + is a canonical one. */ if (entry < 0x8000) - { - const unsigned char *p; - unsigned int element; - unsigned int length; - - p = &gl_uninorm_decomp_chars_table[3 * entry]; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - /* The first element has 5 bits for the decomposition type. */ - if (((element >> 18) & 0x1f) != UC_DECOMP_CANONICAL) - abort (); - length = 1; - for (;;) - { - /* Every element has an 18 bits wide Unicode code point. */ - *decomposition = element & 0x3ffff; - /* Bit 23 tells whether there are more elements, */ - if ((element & (1 << 23)) == 0) - break; - p += 3; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - decomposition++; - length++; - } - return length; - } + { + const unsigned char *p; + unsigned int element; + unsigned int length; + + p = &gl_uninorm_decomp_chars_table[3 * entry]; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + /* The first element has 5 bits for the decomposition type. */ + if (((element >> 18) & 0x1f) != UC_DECOMP_CANONICAL) + abort (); + length = 1; + for (;;) + { + /* Every element has an 18 bits wide Unicode code point. */ + *decomposition = element & 0x3ffff; + /* Bit 23 tells whether there are more elements, */ + if ((element & (1 << 23)) == 0) + break; + p += 3; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + decomposition++; + length++; + } + return length; + } } return -1; } diff --git a/lib/uninorm/composition.c b/lib/uninorm/composition.c index 4caf9a06c..bed8df5ff 100644 --- a/lib/uninorm/composition.c +++ b/lib/uninorm/composition.c @@ -32,54 +32,54 @@ uc_composition (ucs4_t uc1, ucs4_t uc2) if (uc1 < 0x10000 && uc2 < 0x10000) { if (uc2 >= 0x1161 && uc2 < 0x1161 + 21 - && uc1 >= 0x1100 && uc1 < 0x1100 + 19) - { - /* Hangul: Combine single letter L and single letter V to form - two-letter syllable LV. */ - return 0xAC00 + ((uc1 - 0x1100) * 21 + (uc2 - 0x1161)) * 28; - } + && uc1 >= 0x1100 && uc1 < 0x1100 + 19) + { + /* Hangul: Combine single letter L and single letter V to form + two-letter syllable LV. */ + return 0xAC00 + ((uc1 - 0x1100) * 21 + (uc2 - 0x1161)) * 28; + } else if (uc2 > 0x11A7 && uc2 < 0x11A7 + 28 - && uc1 >= 0xAC00 && uc1 < 0xD7A4 && ((uc1 - 0xAC00) % 28) == 0) - { - /* Hangul: Combine two-letter syllable LV with single-letter T - to form three-letter syllable LVT. */ - return uc1 + (uc2 - 0x11A7); - } + && uc1 >= 0xAC00 && uc1 < 0xD7A4 && ((uc1 - 0xAC00) % 28) == 0) + { + /* Hangul: Combine two-letter syllable LV with single-letter T + to form three-letter syllable LVT. */ + return uc1 + (uc2 - 0x11A7); + } else - { + { #if 0 - unsigned int uc = MUL1 * uc1 * MUL2 * uc2; - unsigned int index1 = uc >> composition_header_0; - if (index1 < composition_header_1) - { - int lookup1 = u_composition.level1[index1]; - if (lookup1 >= 0) - { - unsigned int index2 = (uc >> composition_header_2) & composition_header_3; - int lookup2 = u_composition.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & composition_header_4); - unsigned int lookup3 = u_composition.level3[lookup2 + index3]; - if ((lookup3 >> 16) == uc2) - return lookup3 & ((1U << 16) - 1); - } - } - } + unsigned int uc = MUL1 * uc1 * MUL2 * uc2; + unsigned int index1 = uc >> composition_header_0; + if (index1 < composition_header_1) + { + int lookup1 = u_composition.level1[index1]; + if (lookup1 >= 0) + { + unsigned int index2 = (uc >> composition_header_2) & composition_header_3; + int lookup2 = u_composition.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & composition_header_4); + unsigned int lookup3 = u_composition.level3[lookup2 + index3]; + if ((lookup3 >> 16) == uc2) + return lookup3 & ((1U << 16) - 1); + } + } + } #else - char codes[4]; - const struct composition_rule *rule; + char codes[4]; + const struct composition_rule *rule; - codes[0] = (uc1 >> 8) & 0xff; - codes[1] = uc1 & 0xff; - codes[2] = (uc2 >> 8) & 0xff; - codes[3] = uc2 & 0xff; + codes[0] = (uc1 >> 8) & 0xff; + codes[1] = uc1 & 0xff; + codes[2] = (uc2 >> 8) & 0xff; + codes[3] = uc2 & 0xff; - rule = gl_uninorm_compose_lookup (codes, 4); - if (rule != NULL) - return rule->combined; + rule = gl_uninorm_compose_lookup (codes, 4); + if (rule != NULL) + return rule->combined; #endif - } + } } return 0; } diff --git a/lib/uninorm/decompose-internal.h b/lib/uninorm/decompose-internal.h index c1bf1258a..f8ca74d8a 100644 --- a/lib/uninorm/decompose-internal.h +++ b/lib/uninorm/decompose-internal.h @@ -27,10 +27,10 @@ extern int struct ucs4_with_ccc { ucs4_t code; - int ccc; /* range 0..255 */ + int ccc; /* range 0..255 */ }; /* Stable-sort an array of 'struct ucs4_with_ccc'. */ extern void gl_uninorm_decompose_merge_sort_inplace (struct ucs4_with_ccc *src, size_t n, - struct ucs4_with_ccc *tmp); + struct ucs4_with_ccc *tmp); diff --git a/lib/uninorm/decomposition-table.h b/lib/uninorm/decomposition-table.h index ad0e1a3fa..b261f9e62 100644 --- a/lib/uninorm/decomposition-table.h +++ b/lib/uninorm/decomposition-table.h @@ -34,15 +34,15 @@ decomp_index (ucs4_t uc) { int lookup1 = gl_uninorm_decomp_index_table.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> decomp_header_2) & decomp_header_3; - int lookup2 = gl_uninorm_decomp_index_table.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = uc & decomp_header_4; - return gl_uninorm_decomp_index_table.level3[lookup2 + index3]; - } - } + { + unsigned int index2 = (uc >> decomp_header_2) & decomp_header_3; + int lookup2 = gl_uninorm_decomp_index_table.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = uc & decomp_header_4; + return gl_uninorm_decomp_index_table.level3[lookup2 + index3]; + } + } } return (unsigned short)(-1); } diff --git a/lib/uninorm/decomposition.c b/lib/uninorm/decomposition.c index af0301822..8ba0364ce 100644 --- a/lib/uninorm/decomposition.c +++ b/lib/uninorm/decomposition.c @@ -29,8 +29,8 @@ uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition) { /* Hangul syllable. See Unicode standard, chapter 3, section "Hangul Syllable Decomposition", See also the clarification at - , section - "Clarification of Hangul Jamo Handling". */ + , section + "Clarification of Hangul Jamo Handling". */ unsigned int t; uc -= 0xAC00; @@ -38,65 +38,65 @@ uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition) *decomp_tag = UC_DECOMP_CANONICAL; if (t == 0) - { - unsigned int v, l; + { + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - return 2; - } + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + return 2; + } else - { + { #if 1 /* Return the pairwise decomposition, not the full decomposition. */ - decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ - decomposition[1] = 0x11A7 + t; - return 2; + decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ + decomposition[1] = 0x11A7 + t; + return 2; #else - unsigned int v, l; + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - decomposition[2] = 0x11A7 + t; - return 3; + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + decomposition[2] = 0x11A7 + t; + return 3; #endif - } + } } else if (uc < 0x110000) { unsigned short entry = decomp_index (uc); if (entry != (unsigned short)(-1)) - { - const unsigned char *p; - unsigned int element; - unsigned int length; + { + const unsigned char *p; + unsigned int element; + unsigned int length; - p = &gl_uninorm_decomp_chars_table[3 * (entry & 0x7FFF)]; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - /* The first element has 5 bits for the decomposition type. */ - *decomp_tag = (element >> 18) & 0x1f; - length = 1; - for (;;) - { - /* Every element has an 18 bits wide Unicode code point. */ - *decomposition = element & 0x3ffff; - /* Bit 23 tells whether there are more elements, */ - if ((element & (1 << 23)) == 0) - break; - p += 3; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - decomposition++; - length++; - } - return length; - } + p = &gl_uninorm_decomp_chars_table[3 * (entry & 0x7FFF)]; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + /* The first element has 5 bits for the decomposition type. */ + *decomp_tag = (element >> 18) & 0x1f; + length = 1; + for (;;) + { + /* Every element has an 18 bits wide Unicode code point. */ + *decomposition = element & 0x3ffff; + /* Bit 23 tells whether there are more elements, */ + if ((element & (1 << 23)) == 0) + break; + p += 3; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + decomposition++; + length++; + } + return length; + } } return -1; } diff --git a/lib/uninorm/u-normalize-internal.h b/lib/uninorm/u-normalize-internal.h index 70c325513..5feb27b3e 100644 --- a/lib/uninorm/u-normalize-internal.h +++ b/lib/uninorm/u-normalize-internal.h @@ -56,293 +56,293 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n, for (;;) { - int count; - ucs4_t decomposed[UC_DECOMPOSITION_MAX_LENGTH]; - int decomposed_count; - int i; - - if (s < s_end) - { - /* Fetch the next character. */ - count = U_MBTOUC_UNSAFE (&decomposed[0], s, s_end - s); - decomposed_count = 1; - - /* Decompose it, recursively. - It would be possible to precompute the recursive decomposition - and store it in a table. But this would significantly increase - the size of the decomposition tables, because for example for - U+1FC1 the recursive canonical decomposition and the recursive - compatibility decomposition are different. */ - { - int curr; - - for (curr = 0; curr < decomposed_count; ) - { - /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. - all elements are atomic. */ - ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; - int curr_decomposed_count; - - curr_decomposed_count = decomposer (decomposed[curr], curr_decomposed); - if (curr_decomposed_count >= 0) - { - /* Move curr_decomposed[0..curr_decomposed_count-1] over - decomposed[curr], making room. It's not worth using - memcpy() here, since the counts are so small. */ - int shift = curr_decomposed_count - 1; - - if (shift < 0) - abort (); - if (shift > 0) - { - int j; - - decomposed_count += shift; - if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) - abort (); - for (j = decomposed_count - 1 - shift; j > curr; j--) - decomposed[j + shift] = decomposed[j]; - } - for (; shift >= 0; shift--) - decomposed[curr + shift] = curr_decomposed[shift]; - } - else - { - /* decomposed[curr] is atomic. */ - curr++; - } - } - } - } - else - { - count = 0; - decomposed_count = 0; - } - - i = 0; - for (;;) - { - ucs4_t uc; - int ccc; - - if (s < s_end) - { - /* Fetch the next character from the decomposition. */ - if (i == decomposed_count) - break; - uc = decomposed[i]; - ccc = uc_combining_class (uc); - } - else - { - /* End of string reached. */ - uc = 0; - ccc = 0; - } - - if (ccc == 0) - { - size_t j; - - /* Apply the canonical ordering algorithm to the accumulated - sequence of characters. */ - if (sortbuf_count > 1) - gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, - sortbuf + sortbuf_count); - - if (composer != NULL) - { - /* Attempt to combine decomposed characters, as specified - in the Unicode Standard Annex #15 "Unicode Normalization - Forms". We need to check - 1. whether the first accumulated character is a - "starter" (i.e. has ccc = 0). This is usually the - case. But when the string starts with a - non-starter, the sortbuf also starts with a - non-starter. Btw, this check could also be - omitted, because the composition table has only - entries (code1, code2) for which code1 is a - starter; if the first accumulated character is not - a starter, no lookup will succeed. - 2. If the sortbuf has more than one character, check - for each of these characters that are not "blocked" - from the starter (i.e. have a ccc that is higher - than the ccc of the previous character) whether it - can be combined with the first character. - 3. If only one character is left in sortbuf, check - whether it can be combined with the next character - (also a starter). */ - if (sortbuf_count > 0 && sortbuf[0].ccc == 0) - { - for (j = 1; j < sortbuf_count; ) - { - if (sortbuf[j].ccc > sortbuf[j - 1].ccc) - { - ucs4_t combined = - composer (sortbuf[0].code, sortbuf[j].code); - if (combined) - { - size_t k; - - sortbuf[0].code = combined; - /* sortbuf[0].ccc = 0, still valid. */ - for (k = j + 1; k < sortbuf_count; k++) - sortbuf[k - 1] = sortbuf[k]; - sortbuf_count--; - continue; - } - } - j++; - } - if (s < s_end && sortbuf_count == 1) - { - ucs4_t combined = - composer (sortbuf[0].code, uc); - if (combined) - { - uc = combined; - ccc = 0; - /* uc could be further combined with subsequent - characters. So don't put it into sortbuf[0] in - this round, only in the next round. */ - sortbuf_count = 0; - } - } - } - } - - for (j = 0; j < sortbuf_count; j++) - { - ucs4_t muc = sortbuf[j].code; - - /* Append muc to the result accumulator. */ - if (length < allocated) - { - int ret = - U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret >= 0) - { - length += ret; - goto done_appending; - } - } - { - size_t old_allocated = allocated; - size_t new_allocated = 2 * old_allocated; - if (new_allocated < 64) - new_allocated = 64; - if (new_allocated < old_allocated) /* integer overflow? */ - abort (); - { - UNIT *larger_result; - if (result == NULL) - { - larger_result = - (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - else if (result == resultbuf) - { - larger_result = - (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - U_CPY (larger_result, resultbuf, length); - } - else - { - larger_result = - (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - result = larger_result; - allocated = new_allocated; - { - int ret = - U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret < 0) - abort (); - length += ret; - goto done_appending; - } - } - } - done_appending: ; - } - - /* sortbuf is now empty. */ - sortbuf_count = 0; - } - - if (!(s < s_end)) - /* End of string reached. */ - break; - - /* Append (uc, ccc) to sortbuf. */ - if (sortbuf_count == sortbuf_allocated) - { - struct ucs4_with_ccc *new_sortbuf; - - sortbuf_allocated = 2 * sortbuf_allocated; - if (sortbuf_allocated < sortbuf_count) /* integer overflow? */ - abort (); - new_sortbuf = - (struct ucs4_with_ccc *) malloc (2 * sortbuf_allocated * sizeof (struct ucs4_with_ccc)); - memcpy (new_sortbuf, sortbuf, - sortbuf_count * sizeof (struct ucs4_with_ccc)); - if (sortbuf != sortbuf_preallocated) - free (sortbuf); - sortbuf = new_sortbuf; - } - sortbuf[sortbuf_count].code = uc; - sortbuf[sortbuf_count].ccc = ccc; - sortbuf_count++; - - i++; - } - - if (!(s < s_end)) - /* End of string reached. */ - break; - - s += count; + int count; + ucs4_t decomposed[UC_DECOMPOSITION_MAX_LENGTH]; + int decomposed_count; + int i; + + if (s < s_end) + { + /* Fetch the next character. */ + count = U_MBTOUC_UNSAFE (&decomposed[0], s, s_end - s); + decomposed_count = 1; + + /* Decompose it, recursively. + It would be possible to precompute the recursive decomposition + and store it in a table. But this would significantly increase + the size of the decomposition tables, because for example for + U+1FC1 the recursive canonical decomposition and the recursive + compatibility decomposition are different. */ + { + int curr; + + for (curr = 0; curr < decomposed_count; ) + { + /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. + all elements are atomic. */ + ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; + int curr_decomposed_count; + + curr_decomposed_count = decomposer (decomposed[curr], curr_decomposed); + if (curr_decomposed_count >= 0) + { + /* Move curr_decomposed[0..curr_decomposed_count-1] over + decomposed[curr], making room. It's not worth using + memcpy() here, since the counts are so small. */ + int shift = curr_decomposed_count - 1; + + if (shift < 0) + abort (); + if (shift > 0) + { + int j; + + decomposed_count += shift; + if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) + abort (); + for (j = decomposed_count - 1 - shift; j > curr; j--) + decomposed[j + shift] = decomposed[j]; + } + for (; shift >= 0; shift--) + decomposed[curr + shift] = curr_decomposed[shift]; + } + else + { + /* decomposed[curr] is atomic. */ + curr++; + } + } + } + } + else + { + count = 0; + decomposed_count = 0; + } + + i = 0; + for (;;) + { + ucs4_t uc; + int ccc; + + if (s < s_end) + { + /* Fetch the next character from the decomposition. */ + if (i == decomposed_count) + break; + uc = decomposed[i]; + ccc = uc_combining_class (uc); + } + else + { + /* End of string reached. */ + uc = 0; + ccc = 0; + } + + if (ccc == 0) + { + size_t j; + + /* Apply the canonical ordering algorithm to the accumulated + sequence of characters. */ + if (sortbuf_count > 1) + gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, + sortbuf + sortbuf_count); + + if (composer != NULL) + { + /* Attempt to combine decomposed characters, as specified + in the Unicode Standard Annex #15 "Unicode Normalization + Forms". We need to check + 1. whether the first accumulated character is a + "starter" (i.e. has ccc = 0). This is usually the + case. But when the string starts with a + non-starter, the sortbuf also starts with a + non-starter. Btw, this check could also be + omitted, because the composition table has only + entries (code1, code2) for which code1 is a + starter; if the first accumulated character is not + a starter, no lookup will succeed. + 2. If the sortbuf has more than one character, check + for each of these characters that are not "blocked" + from the starter (i.e. have a ccc that is higher + than the ccc of the previous character) whether it + can be combined with the first character. + 3. If only one character is left in sortbuf, check + whether it can be combined with the next character + (also a starter). */ + if (sortbuf_count > 0 && sortbuf[0].ccc == 0) + { + for (j = 1; j < sortbuf_count; ) + { + if (sortbuf[j].ccc > sortbuf[j - 1].ccc) + { + ucs4_t combined = + composer (sortbuf[0].code, sortbuf[j].code); + if (combined) + { + size_t k; + + sortbuf[0].code = combined; + /* sortbuf[0].ccc = 0, still valid. */ + for (k = j + 1; k < sortbuf_count; k++) + sortbuf[k - 1] = sortbuf[k]; + sortbuf_count--; + continue; + } + } + j++; + } + if (s < s_end && sortbuf_count == 1) + { + ucs4_t combined = + composer (sortbuf[0].code, uc); + if (combined) + { + uc = combined; + ccc = 0; + /* uc could be further combined with subsequent + characters. So don't put it into sortbuf[0] in + this round, only in the next round. */ + sortbuf_count = 0; + } + } + } + } + + for (j = 0; j < sortbuf_count; j++) + { + ucs4_t muc = sortbuf[j].code; + + /* Append muc to the result accumulator. */ + if (length < allocated) + { + int ret = + U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret >= 0) + { + length += ret; + goto done_appending; + } + } + { + size_t old_allocated = allocated; + size_t new_allocated = 2 * old_allocated; + if (new_allocated < 64) + new_allocated = 64; + if (new_allocated < old_allocated) /* integer overflow? */ + abort (); + { + UNIT *larger_result; + if (result == NULL) + { + larger_result = + (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + else if (result == resultbuf) + { + larger_result = + (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + U_CPY (larger_result, resultbuf, length); + } + else + { + larger_result = + (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + result = larger_result; + allocated = new_allocated; + { + int ret = + U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret < 0) + abort (); + length += ret; + goto done_appending; + } + } + } + done_appending: ; + } + + /* sortbuf is now empty. */ + sortbuf_count = 0; + } + + if (!(s < s_end)) + /* End of string reached. */ + break; + + /* Append (uc, ccc) to sortbuf. */ + if (sortbuf_count == sortbuf_allocated) + { + struct ucs4_with_ccc *new_sortbuf; + + sortbuf_allocated = 2 * sortbuf_allocated; + if (sortbuf_allocated < sortbuf_count) /* integer overflow? */ + abort (); + new_sortbuf = + (struct ucs4_with_ccc *) malloc (2 * sortbuf_allocated * sizeof (struct ucs4_with_ccc)); + memcpy (new_sortbuf, sortbuf, + sortbuf_count * sizeof (struct ucs4_with_ccc)); + if (sortbuf != sortbuf_preallocated) + free (sortbuf); + sortbuf = new_sortbuf; + } + sortbuf[sortbuf_count].code = uc; + sortbuf[sortbuf_count].ccc = ccc; + sortbuf_count++; + + i++; + } + + if (!(s < s_end)) + /* End of string reached. */ + break; + + s += count; } } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - goto fail; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + goto fail; + } + } } else if (result != resultbuf && length < allocated) { @@ -351,7 +351,7 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n, memory = (UNIT *) realloc (result, length * sizeof (UNIT)); if (memory != NULL) - result = memory; + result = memory; } if (sortbuf_count > 0) diff --git a/lib/uninorm/u-normcmp.h b/lib/uninorm/u-normcmp.h index 66164406f..21a617f1e 100644 --- a/lib/uninorm/u-normcmp.h +++ b/lib/uninorm/u-normcmp.h @@ -40,11 +40,11 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2, if (norms2 == NULL) { if (norms1 != buf1) - { - int saved_errno = errno; - free (norms1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms1); + errno = saved_errno; + } return -1; } diff --git a/lib/uninorm/u-normcoll.h b/lib/uninorm/u-normcoll.h index e30880b02..6ae107f40 100644 --- a/lib/uninorm/u-normcoll.h +++ b/lib/uninorm/u-normcoll.h @@ -40,17 +40,17 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2, if (transformed2 == NULL) { if (transformed1 != buf1) - { - int saved_errno = errno; - free (transformed1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (transformed1); + errno = saved_errno; + } return -1; } /* Compare the transformed strings. */ cmp = memcmp2 (transformed1, transformed1_length, - transformed2, transformed2_length); + transformed2, transformed2_length); if (cmp < 0) cmp = -1; else if (cmp > 0) diff --git a/lib/uninorm/u-normxfrm.h b/lib/uninorm/u-normxfrm.h index 6ed1e3c36..ee11f9152 100644 --- a/lib/uninorm/u-normxfrm.h +++ b/lib/uninorm/u-normxfrm.h @@ -37,18 +37,18 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf, /* Convert it to locale encoding. */ convs_length = sizeof (convsbuf) - 1; convs = U_CONV_TO_ENCODING (locale_charset (), - iconveh_error, - norms, norms_length, - NULL, - convsbuf, &convs_length); + iconveh_error, + norms, norms_length, + NULL, + convsbuf, &convs_length); if (convs == NULL) { if (norms != normsbuf) - { - int saved_errno = errno; - free (norms); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms); + errno = saved_errno; + } return NULL; } @@ -60,11 +60,11 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf, { char *memory = (char *) realloc (convs, convs_length + 1); if (memory == NULL) - { - free (convs); - errno = ENOMEM; - return NULL; - } + { + free (convs); + errno = ENOMEM; + return NULL; + } convs = memory; } @@ -73,11 +73,11 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf, if (result == NULL) { if (convs != convsbuf) - { - int saved_errno = errno; - free (convs); - errno = saved_errno; - } + { + int saved_errno = errno; + free (convs); + errno = saved_errno; + } return NULL; } diff --git a/lib/uninorm/uninorm-filter.c b/lib/uninorm/uninorm-filter.c index 1d03cfaf7..14de562ea 100644 --- a/lib/uninorm/uninorm-filter.c +++ b/lib/uninorm/uninorm-filter.c @@ -50,8 +50,8 @@ struct uninorm_filter struct uninorm_filter * uninorm_filter_create (uninorm_t nf, - int (*stream_func) (void *stream_data, ucs4_t uc), - void *stream_data) + int (*stream_func) (void *stream_data, ucs4_t uc), + void *stream_data) { struct uninorm_filter *filter = (struct uninorm_filter *) malloc (sizeof (struct uninorm_filter)); @@ -92,40 +92,40 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg) for (curr = 0; curr < decomposed_count; ) { - /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. - all elements are atomic. */ - ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; - int curr_decomposed_count; - - curr_decomposed_count = - filter->decomposer (decomposed[curr], curr_decomposed); - if (curr_decomposed_count >= 0) - { - /* Move curr_decomposed[0..curr_decomposed_count-1] over - decomposed[curr], making room. It's not worth using - memcpy() here, since the counts are so small. */ - int shift = curr_decomposed_count - 1; - - if (shift < 0) - abort (); - if (shift > 0) - { - int j; - - decomposed_count += shift; - if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) - abort (); - for (j = decomposed_count - 1 - shift; j > curr; j--) - decomposed[j + shift] = decomposed[j]; - } - for (; shift >= 0; shift--) - decomposed[curr + shift] = curr_decomposed[shift]; - } - else - { - /* decomposed[curr] is atomic. */ - curr++; - } + /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. + all elements are atomic. */ + ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; + int curr_decomposed_count; + + curr_decomposed_count = + filter->decomposer (decomposed[curr], curr_decomposed); + if (curr_decomposed_count >= 0) + { + /* Move curr_decomposed[0..curr_decomposed_count-1] over + decomposed[curr], making room. It's not worth using + memcpy() here, since the counts are so small. */ + int shift = curr_decomposed_count - 1; + + if (shift < 0) + abort (); + if (shift > 0) + { + int j; + + decomposed_count += shift; + if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) + abort (); + for (j = decomposed_count - 1 - shift; j > curr; j--) + decomposed[j + shift] = decomposed[j]; + } + for (; shift >= 0; shift--) + decomposed[curr + shift] = curr_decomposed[shift]; + } + else + { + /* decomposed[curr] is atomic. */ + curr++; + } } } @@ -137,119 +137,119 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg) for (i = 0; i < decomposed_count; i++) { - /* Fetch the next character from the decomposition. */ - ucs4_t uc = decomposed[i]; - int ccc = uc_combining_class (uc); - - if (ccc == 0) - { - size_t j; - - /* Apply the canonical ordering algorithm to the accumulated - sequence of characters. */ - if (sortbuf_count > 1) - gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, - sortbuf + sortbuf_count); - - if (filter->composer != NULL) - { - /* Attempt to combine decomposed characters, as specified - in the Unicode Standard Annex #15 "Unicode Normalization - Forms". We need to check - 1. whether the first accumulated character is a - "starter" (i.e. has ccc = 0). This is usually the - case. But when the string starts with a - non-starter, the sortbuf also starts with a - non-starter. Btw, this check could also be - omitted, because the composition table has only - entries (code1, code2) for which code1 is a - starter; if the first accumulated character is not - a starter, no lookup will succeed. - 2. If the sortbuf has more than one character, check - for each of these characters that are not "blocked" - from the starter (i.e. have a ccc that is higher - than the ccc of the previous character) whether it - can be combined with the first character. - 3. If only one character is left in sortbuf, check - whether it can be combined with the next character - (also a starter). */ - if (sortbuf_count > 0 && sortbuf[0].ccc == 0) - { - for (j = 1; j < sortbuf_count; ) - { - if (sortbuf[j].ccc > sortbuf[j - 1].ccc) - { - ucs4_t combined = - filter->composer (sortbuf[0].code, sortbuf[j].code); - if (combined) - { - size_t k; - - sortbuf[0].code = combined; - /* sortbuf[0].ccc = 0, still valid. */ - for (k = j + 1; k < sortbuf_count; k++) - sortbuf[k - 1] = sortbuf[k]; - sortbuf_count--; - continue; - } - } - j++; - } - if (sortbuf_count == 1) - { - ucs4_t combined = - filter->composer (sortbuf[0].code, uc); - if (combined) - { - uc = combined; - ccc = 0; - /* uc could be further combined with subsequent - characters. So don't put it into sortbuf[0] in - this round, only in the next round. */ - sortbuf_count = 0; - } - } - } - } - - for (j = 0; j < sortbuf_count; j++) - { - ucs4_t muc = sortbuf[j].code; - - /* Output muc to the encapsulated stream. */ - int ret = filter->stream_func (filter->stream_data, muc); - if (ret < 0) - { - /* errno is set here. */ - filter->sortbuf_count = 0; - return -1; - } - } - - /* sortbuf is now empty. */ - sortbuf_count = 0; - } - - /* Append (uc, ccc) to sortbuf. */ - if (sortbuf_count == filter->sortbuf_allocated) - { - struct ucs4_with_ccc *new_sortbuf; - - filter->sortbuf_allocated = 2 * filter->sortbuf_allocated; - if (filter->sortbuf_allocated < sortbuf_count) /* integer overflow? */ - abort (); - new_sortbuf = - (struct ucs4_with_ccc *) - malloc (2 * filter->sortbuf_allocated * sizeof (struct ucs4_with_ccc)); - memcpy (new_sortbuf, filter->sortbuf, - sortbuf_count * sizeof (struct ucs4_with_ccc)); - if (filter->sortbuf != filter->sortbuf_preallocated) - free (filter->sortbuf); - filter->sortbuf = new_sortbuf; - } - filter->sortbuf[sortbuf_count].code = uc; - filter->sortbuf[sortbuf_count].ccc = ccc; - sortbuf_count++; + /* Fetch the next character from the decomposition. */ + ucs4_t uc = decomposed[i]; + int ccc = uc_combining_class (uc); + + if (ccc == 0) + { + size_t j; + + /* Apply the canonical ordering algorithm to the accumulated + sequence of characters. */ + if (sortbuf_count > 1) + gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, + sortbuf + sortbuf_count); + + if (filter->composer != NULL) + { + /* Attempt to combine decomposed characters, as specified + in the Unicode Standard Annex #15 "Unicode Normalization + Forms". We need to check + 1. whether the first accumulated character is a + "starter" (i.e. has ccc = 0). This is usually the + case. But when the string starts with a + non-starter, the sortbuf also starts with a + non-starter. Btw, this check could also be + omitted, because the composition table has only + entries (code1, code2) for which code1 is a + starter; if the first accumulated character is not + a starter, no lookup will succeed. + 2. If the sortbuf has more than one character, check + for each of these characters that are not "blocked" + from the starter (i.e. have a ccc that is higher + than the ccc of the previous character) whether it + can be combined with the first character. + 3. If only one character is left in sortbuf, check + whether it can be combined with the next character + (also a starter). */ + if (sortbuf_count > 0 && sortbuf[0].ccc == 0) + { + for (j = 1; j < sortbuf_count; ) + { + if (sortbuf[j].ccc > sortbuf[j - 1].ccc) + { + ucs4_t combined = + filter->composer (sortbuf[0].code, sortbuf[j].code); + if (combined) + { + size_t k; + + sortbuf[0].code = combined; + /* sortbuf[0].ccc = 0, still valid. */ + for (k = j + 1; k < sortbuf_count; k++) + sortbuf[k - 1] = sortbuf[k]; + sortbuf_count--; + continue; + } + } + j++; + } + if (sortbuf_count == 1) + { + ucs4_t combined = + filter->composer (sortbuf[0].code, uc); + if (combined) + { + uc = combined; + ccc = 0; + /* uc could be further combined with subsequent + characters. So don't put it into sortbuf[0] in + this round, only in the next round. */ + sortbuf_count = 0; + } + } + } + } + + for (j = 0; j < sortbuf_count; j++) + { + ucs4_t muc = sortbuf[j].code; + + /* Output muc to the encapsulated stream. */ + int ret = filter->stream_func (filter->stream_data, muc); + if (ret < 0) + { + /* errno is set here. */ + filter->sortbuf_count = 0; + return -1; + } + } + + /* sortbuf is now empty. */ + sortbuf_count = 0; + } + + /* Append (uc, ccc) to sortbuf. */ + if (sortbuf_count == filter->sortbuf_allocated) + { + struct ucs4_with_ccc *new_sortbuf; + + filter->sortbuf_allocated = 2 * filter->sortbuf_allocated; + if (filter->sortbuf_allocated < sortbuf_count) /* integer overflow? */ + abort (); + new_sortbuf = + (struct ucs4_with_ccc *) + malloc (2 * filter->sortbuf_allocated * sizeof (struct ucs4_with_ccc)); + memcpy (new_sortbuf, filter->sortbuf, + sortbuf_count * sizeof (struct ucs4_with_ccc)); + if (filter->sortbuf != filter->sortbuf_preallocated) + free (filter->sortbuf); + filter->sortbuf = new_sortbuf; + } + filter->sortbuf[sortbuf_count].code = uc; + filter->sortbuf[sortbuf_count].ccc = ccc; + sortbuf_count++; } filter->sortbuf_count = sortbuf_count; @@ -276,53 +276,53 @@ uninorm_filter_flush (struct uninorm_filter *filter) sequence of characters. */ if (sortbuf_count > 1) gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, - sortbuf + sortbuf_count); + sortbuf + sortbuf_count); if (filter->composer != NULL) { /* Attempt to combine decomposed characters, as specified - in the Unicode Standard Annex #15 "Unicode Normalization - Forms". We need to check - 1. whether the first accumulated character is a - "starter" (i.e. has ccc = 0). This is usually the - case. But when the string starts with a - non-starter, the sortbuf also starts with a - non-starter. Btw, this check could also be - omitted, because the composition table has only - entries (code1, code2) for which code1 is a - starter; if the first accumulated character is not - a starter, no lookup will succeed. - 2. If the sortbuf has more than one character, check - for each of these characters that are not "blocked" - from the starter (i.e. have a ccc that is higher - than the ccc of the previous character) whether it - can be combined with the first character. - 3. If only one character is left in sortbuf, check - whether it can be combined with the next character - (also a starter). */ + in the Unicode Standard Annex #15 "Unicode Normalization + Forms". We need to check + 1. whether the first accumulated character is a + "starter" (i.e. has ccc = 0). This is usually the + case. But when the string starts with a + non-starter, the sortbuf also starts with a + non-starter. Btw, this check could also be + omitted, because the composition table has only + entries (code1, code2) for which code1 is a + starter; if the first accumulated character is not + a starter, no lookup will succeed. + 2. If the sortbuf has more than one character, check + for each of these characters that are not "blocked" + from the starter (i.e. have a ccc that is higher + than the ccc of the previous character) whether it + can be combined with the first character. + 3. If only one character is left in sortbuf, check + whether it can be combined with the next character + (also a starter). */ if (sortbuf_count > 0 && sortbuf[0].ccc == 0) - { - for (j = 1; j < sortbuf_count; ) - { - if (sortbuf[j].ccc > sortbuf[j - 1].ccc) - { - ucs4_t combined = - filter->composer (sortbuf[0].code, sortbuf[j].code); - if (combined) - { - size_t k; - - sortbuf[0].code = combined; - /* sortbuf[0].ccc = 0, still valid. */ - for (k = j + 1; k < sortbuf_count; k++) - sortbuf[k - 1] = sortbuf[k]; - sortbuf_count--; - continue; - } - } - j++; - } - } + { + for (j = 1; j < sortbuf_count; ) + { + if (sortbuf[j].ccc > sortbuf[j - 1].ccc) + { + ucs4_t combined = + filter->composer (sortbuf[0].code, sortbuf[j].code); + if (combined) + { + size_t k; + + sortbuf[0].code = combined; + /* sortbuf[0].ccc = 0, still valid. */ + for (k = j + 1; k < sortbuf_count; k++) + sortbuf[k - 1] = sortbuf[k]; + sortbuf_count--; + continue; + } + } + j++; + } + } } for (j = 0; j < sortbuf_count; j++) @@ -332,11 +332,11 @@ uninorm_filter_flush (struct uninorm_filter *filter) /* Output muc to the encapsulated stream. */ int ret = filter->stream_func (filter->stream_data, muc); if (ret < 0) - { - /* errno is set here. */ - filter->sortbuf_count = 0; - return -1; - } + { + /* errno is set here. */ + filter->sortbuf_count = 0; + return -1; + } } /* sortbuf is now empty. */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index ba178e508..bc2410e9f 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -59,37 +59,37 @@ # include # if !defined _GL_SYS_SOCKET_H # undef socket -# define socket socket_used_without_including_sys_socket_h +# define socket socket_used_without_including_sys_socket_h # undef connect -# define connect connect_used_without_including_sys_socket_h +# define connect connect_used_without_including_sys_socket_h # undef accept -# define accept accept_used_without_including_sys_socket_h +# define accept accept_used_without_including_sys_socket_h # undef bind -# define bind bind_used_without_including_sys_socket_h +# define bind bind_used_without_including_sys_socket_h # undef getpeername -# define getpeername getpeername_used_without_including_sys_socket_h +# define getpeername getpeername_used_without_including_sys_socket_h # undef getsockname -# define getsockname getsockname_used_without_including_sys_socket_h +# define getsockname getsockname_used_without_including_sys_socket_h # undef getsockopt -# define getsockopt getsockopt_used_without_including_sys_socket_h +# define getsockopt getsockopt_used_without_including_sys_socket_h # undef listen -# define listen listen_used_without_including_sys_socket_h +# define listen listen_used_without_including_sys_socket_h # undef recv -# define recv recv_used_without_including_sys_socket_h +# define recv recv_used_without_including_sys_socket_h # undef send -# define send send_used_without_including_sys_socket_h +# define send send_used_without_including_sys_socket_h # undef recvfrom -# define recvfrom recvfrom_used_without_including_sys_socket_h +# define recvfrom recvfrom_used_without_including_sys_socket_h # undef sendto -# define sendto sendto_used_without_including_sys_socket_h +# define sendto sendto_used_without_including_sys_socket_h # undef setsockopt -# define setsockopt setsockopt_used_without_including_sys_socket_h +# define setsockopt setsockopt_used_without_including_sys_socket_h # undef shutdown -# define shutdown shutdown_used_without_including_sys_socket_h +# define shutdown shutdown_used_without_including_sys_socket_h # endif # if !defined _GL_SYS_SELECT_H # undef select -# define select select_used_without_including_sys_select_h +# define select select_used_without_including_sys_select_h # endif # endif #endif @@ -256,7 +256,7 @@ int faccessat (int fd, char const *file, int mode, int flag); # endif #elif defined GNULIB_POSIXCHECK # undef faccessat -# define faccessat(d,n,m,f) \ +# define faccessat(d,n,m,f) \ (GL_LINK_WARNING ("faccessat is not portable - " \ "use gnulib module faccessat for portability"), \ faccessat (d, n, m, f)) @@ -298,7 +298,7 @@ extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int fla # endif #elif defined GNULIB_POSIXCHECK # undef fchownat -# define fchownat(d,n,o,g,f) \ +# define fchownat(d,n,o,g,f) \ (GL_LINK_WARNING ("fchownat is not portable - " \ "use gnulib module openat for portability"), \ fchownat (d, n, o, g, f)) @@ -614,11 +614,11 @@ extern int link (const char *path1, const char *path2); Return 0 if successful, otherwise -1 and errno set. */ # if !@HAVE_LINKAT@ || @REPLACE_LINKAT@ extern int linkat (int fd1, const char *path1, int fd2, const char *path2, - int flag); + int flag); # endif #elif defined GNULIB_POSIXCHECK # undef linkat -# define link(f1,path1,f2,path2,f) \ +# define link(f1,path1,f2,path2,f) \ (GL_LINK_WARNING ("linkat is unportable - " \ "use gnulib module linkat for portability"), \ linkat (f1, path1, f2, path2,f)) @@ -677,7 +677,7 @@ extern int pipe2 (int fd[2], int flags); # endif #elif defined GNULIB_POSIXCHECK # undef pread -# define pread(f,b,s,o) \ +# define pread(f,b,s,o) \ (GL_LINK_WARNING ("pread is unportable - " \ "use gnulib module pread for portability"), \ pread (f, b, s, o)) @@ -711,7 +711,7 @@ ssize_t readlinkat (int fd, char const *file, char *buf, size_t len); # endif #elif defined GNULIB_POSIXCHECK # undef readlinkat -# define readlinkat(d,n,b,l) \ +# define readlinkat(d,n,b,l) \ (GL_LINK_WARNING ("readlinkat is not portable - " \ "use gnulib module symlinkat for portability"), \ readlinkat (d, n, b, l)) @@ -764,7 +764,7 @@ int symlink (char const *contents, char const *file); # endif #elif defined GNULIB_POSIXCHECK # undef symlink -# define symlink(c,n) \ +# define symlink(c,n) \ (GL_LINK_WARNING ("symlink is not portable - " \ "use gnulib module symlink for portability"), \ symlink (c, n)) @@ -777,7 +777,7 @@ int symlinkat (char const *contents, int fd, char const *file); # endif #elif defined GNULIB_POSIXCHECK # undef symlinkat -# define symlinkat(c,d,n) \ +# define symlinkat(c,d,n) \ (GL_LINK_WARNING ("symlinkat is not portable - " \ "use gnulib module symlinkat for portability"), \ symlinkat (c, d, n)) diff --git a/lib/unistdio.h b/lib/unistdio.h index d9eca02fe..ee5ddbaa0 100644 --- a/lib/unistdio.h +++ b/lib/unistdio.h @@ -62,192 +62,192 @@ extern "C" { /* ASCII format string, result in locale dependent encoded 'char *'. */ extern int ulc_sprintf (char *buf, - const char *format, ...); + const char *format, ...); extern int ulc_snprintf (char *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int ulc_asprintf (char **resultp, - const char *format, ...); + const char *format, ...); extern char * ulc_asnprintf (char *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int ulc_vsprintf (char *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int ulc_vsnprintf (char *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int ulc_vasprintf (char **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern char * ulc_vasnprintf (char *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* ASCII format string, result in UTF-8 format. */ extern int u8_sprintf (uint8_t *buf, - const char *format, ...); + const char *format, ...); extern int u8_snprintf (uint8_t *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int u8_asprintf (uint8_t **resultp, - const char *format, ...); + const char *format, ...); extern uint8_t * u8_asnprintf (uint8_t *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int u8_vsprintf (uint8_t *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int u8_vsnprintf (uint8_t *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int u8_vasprintf (uint8_t **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern uint8_t * u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* UTF-8 format string, result in UTF-8 format. */ extern int u8_u8_sprintf (uint8_t *buf, - const uint8_t *format, ...); + const uint8_t *format, ...); extern int u8_u8_snprintf (uint8_t *buf, size_t size, - const uint8_t *format, ...); + const uint8_t *format, ...); extern int u8_u8_asprintf (uint8_t **resultp, - const uint8_t *format, ...); + const uint8_t *format, ...); extern uint8_t * u8_u8_asnprintf (uint8_t *resultbuf, size_t *lengthp, - const uint8_t *format, ...); + const uint8_t *format, ...); extern int u8_u8_vsprintf (uint8_t *buf, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); extern int u8_u8_vsnprintf (uint8_t *buf, size_t size, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); extern int u8_u8_vasprintf (uint8_t **resultp, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); extern uint8_t * u8_u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); /* ASCII format string, result in UTF-16 format. */ extern int u16_sprintf (uint16_t *buf, - const char *format, ...); + const char *format, ...); extern int u16_snprintf (uint16_t *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int u16_asprintf (uint16_t **resultp, - const char *format, ...); + const char *format, ...); extern uint16_t * u16_asnprintf (uint16_t *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int u16_vsprintf (uint16_t *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int u16_vsnprintf (uint16_t *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int u16_vasprintf (uint16_t **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern uint16_t * u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* UTF-16 format string, result in UTF-16 format. */ extern int u16_u16_sprintf (uint16_t *buf, - const uint16_t *format, ...); + const uint16_t *format, ...); extern int u16_u16_snprintf (uint16_t *buf, size_t size, - const uint16_t *format, ...); + const uint16_t *format, ...); extern int u16_u16_asprintf (uint16_t **resultp, - const uint16_t *format, ...); + const uint16_t *format, ...); extern uint16_t * u16_u16_asnprintf (uint16_t *resultbuf, size_t *lengthp, - const uint16_t *format, ...); + const uint16_t *format, ...); extern int u16_u16_vsprintf (uint16_t *buf, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); extern int u16_u16_vsnprintf (uint16_t *buf, size_t size, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); extern int u16_u16_vasprintf (uint16_t **resultp, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); extern uint16_t * u16_u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); /* ASCII format string, result in UTF-32 format. */ extern int u32_sprintf (uint32_t *buf, - const char *format, ...); + const char *format, ...); extern int u32_snprintf (uint32_t *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int u32_asprintf (uint32_t **resultp, - const char *format, ...); + const char *format, ...); extern uint32_t * u32_asnprintf (uint32_t *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int u32_vsprintf (uint32_t *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int u32_vsnprintf (uint32_t *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int u32_vasprintf (uint32_t **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern uint32_t * u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* UTF-32 format string, result in UTF-32 format. */ extern int u32_u32_sprintf (uint32_t *buf, - const uint32_t *format, ...); + const uint32_t *format, ...); extern int u32_u32_snprintf (uint32_t *buf, size_t size, - const uint32_t *format, ...); + const uint32_t *format, ...); extern int u32_u32_asprintf (uint32_t **resultp, - const uint32_t *format, ...); + const uint32_t *format, ...); extern uint32_t * u32_u32_asnprintf (uint32_t *resultbuf, size_t *lengthp, - const uint32_t *format, ...); + const uint32_t *format, ...); extern int u32_u32_vsprintf (uint32_t *buf, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); extern int u32_u32_vsnprintf (uint32_t *buf, size_t size, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); extern int u32_u32_vasprintf (uint32_t **resultp, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); extern uint32_t * u32_u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); /* ASCII format string, output to FILE in locale dependent encoding. */ extern int ulc_fprintf (FILE *stream, - const char *format, ...); + const char *format, ...); extern int ulc_vfprintf (FILE *stream, - const char *format, va_list ap); + const char *format, va_list ap); #ifdef __cplusplus } diff --git a/lib/unistdio/u-vsnprintf.h b/lib/unistdio/u-vsnprintf.h index 481a22f08..57ca679a0 100644 --- a/lib/unistdio/u-vsnprintf.h +++ b/lib/unistdio/u-vsnprintf.h @@ -31,13 +31,13 @@ VSNPRINTF (DCHAR_T *buf, size_t size, const FCHAR_T *format, va_list args) if (result != buf) { if (size != 0) - { - /* The result did not fit into the buffer. Copy the initial segment - into the buffer, truncating it if necessary. */ - size_t n = (length < size ? length : size - 1); - DCHAR_CPY (buf, result, n); - buf[n] = '\0'; - } + { + /* The result did not fit into the buffer. Copy the initial segment + into the buffer, truncating it if necessary. */ + size_t n = (length < size ? length : size - 1); + DCHAR_CPY (buf, result, n); + buf[n] = '\0'; + } free (result); } diff --git a/lib/unistdio/ulc-fprintf.c b/lib/unistdio/ulc-fprintf.c index 2da246cbe..f9d00023d 100644 --- a/lib/unistdio/ulc-fprintf.c +++ b/lib/unistdio/ulc-fprintf.c @@ -55,11 +55,11 @@ ulc_fprintf (FILE *fp, const char *format, ...) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/unistdio/ulc-vfprintf.c b/lib/unistdio/ulc-vfprintf.c index ae63b1491..04fa8fadd 100644 --- a/lib/unistdio/ulc-vfprintf.c +++ b/lib/unistdio/ulc-vfprintf.c @@ -52,11 +52,11 @@ ulc_vfprintf (FILE *fp, const char *format, va_list args) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/unistr.h b/lib/unistr.h index 83ff13411..35cd2dab4 100644 --- a/lib/unistr.h +++ b/lib/unistr.h @@ -81,32 +81,32 @@ extern const uint32_t * /* Convert an UTF-8 string to an UTF-16 string. */ extern uint16_t * u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-8 string to an UCS-4 string. */ extern uint32_t * u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-16 string to an UTF-8 string. */ extern uint8_t * u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-16 string to an UCS-4 string. */ extern uint32_t * u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UCS-4 string to an UTF-8 string. */ extern uint8_t * u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UCS-4 string to an UTF-16 string. */ extern uint16_t * u32_to_u16 (const uint32_t *s, size_t n, uint16_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Elementary string functions. */ @@ -351,12 +351,12 @@ u32_uctomb (uint32_t *s, ucs4_t uc, int n) if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000)) { if (n > 0) - { - *s = uc; - return 1; - } + { + *s = uc; + return 1; + } else - return -2; + return -2; } else return -1; diff --git a/lib/unistr/u-cmp2.h b/lib/unistr/u-cmp2.h index ae3750c48..a8704d57b 100644 --- a/lib/unistr/u-cmp2.h +++ b/lib/unistr/u-cmp2.h @@ -23,9 +23,9 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2) if (cmp == 0) { if (n1 < n2) - cmp = -1; + cmp = -1; else if (n1 > n2) - cmp = 1; + cmp = 1; } return cmp; diff --git a/lib/unistr/u-cpy-alloc.h b/lib/unistr/u-cpy-alloc.h index dace3e2e6..b67267309 100644 --- a/lib/unistr/u-cpy-alloc.h +++ b/lib/unistr/u-cpy-alloc.h @@ -30,7 +30,7 @@ FUNC (const UNIT *s, size_t n) UNIT *destptr = dest; for (; n > 0; n--) - *destptr++ = *s++; + *destptr++ = *s++; #else memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT)); #endif diff --git a/lib/unistr/u-move.h b/lib/unistr/u-move.h index 77b6788bd..06dca04ad 100644 --- a/lib/unistr/u-move.h +++ b/lib/unistr/u-move.h @@ -27,7 +27,7 @@ FUNC (UNIT *dest, const UNIT *src, size_t n) const UNIT *srcptr = src; for (; n > 0; n--) - *destptr++ = *srcptr++; + *destptr++ = *srcptr++; } else if (dest > src) { @@ -35,7 +35,7 @@ FUNC (UNIT *dest, const UNIT *src, size_t n) const UNIT *srcptr = src + n - 1; for (; n > 0; n--) - *destptr-- = *srcptr--; + *destptr-- = *srcptr--; } #else memmove ((char *) dest, (const char *) src, n * sizeof (UNIT)); diff --git a/lib/unistr/u-set.h b/lib/unistr/u-set.h index a093e7f68..3e3000cf0 100644 --- a/lib/unistr/u-set.h +++ b/lib/unistr/u-set.h @@ -23,17 +23,17 @@ FUNC (UNIT *s, ucs4_t uc, size_t n) if (n > 0) { if (IS_SINGLE_UNIT (uc)) - { - UNIT *ptr = s; + { + UNIT *ptr = s; - for (; n > 0; n--) - *ptr++ = uc; - } + for (; n > 0; n--) + *ptr++ = uc; + } else - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } } return s; } diff --git a/lib/unistr/u-startswith.h b/lib/unistr/u-startswith.h index 0486ef882..01d6d5a41 100644 --- a/lib/unistr/u-startswith.h +++ b/lib/unistr/u-startswith.h @@ -23,8 +23,8 @@ FUNC (const UNIT *str, const UNIT *prefix) UNIT uc1 = *str++; UNIT uc2 = *prefix++; if (uc2 == 0) - return true; + return true; if (uc1 != uc2) - return false; + return false; } } diff --git a/lib/unistr/u-strcoll.h b/lib/unistr/u-strcoll.h index af404a04b..03a99a640 100644 --- a/lib/unistr/u-strcoll.h +++ b/lib/unistr/u-strcoll.h @@ -32,48 +32,48 @@ FUNC (const UNIT *s1, const UNIT *s2) { sl2 = U_STRCONV_TO_LOCALE (s2); if (sl2 != NULL) - { - /* Compare sl1 and sl2. */ - errno = 0; - result = strcoll (sl1, sl2); - if (errno == 0) - { - /* strcoll succeeded. */ - free (sl1); - free (sl2); - } - else - { - /* strcoll failed. */ - final_errno = errno; - free (sl1); - free (sl2); - result = U_STRCMP (s1, s2); - } - } + { + /* Compare sl1 and sl2. */ + errno = 0; + result = strcoll (sl1, sl2); + if (errno == 0) + { + /* strcoll succeeded. */ + free (sl1); + free (sl2); + } + else + { + /* strcoll failed. */ + final_errno = errno; + free (sl1); + free (sl2); + result = U_STRCMP (s1, s2); + } + } else - { - /* s1 could be converted to locale encoding, s2 not. */ - final_errno = errno; - free (sl1); - result = -1; - } + { + /* s1 could be converted to locale encoding, s2 not. */ + final_errno = errno; + free (sl1); + result = -1; + } } else { final_errno = errno; sl2 = U_STRCONV_TO_LOCALE (s2); if (sl2 != NULL) - { - /* s2 could be converted to locale encoding, s1 not. */ - free (sl2); - result = 1; - } + { + /* s2 could be converted to locale encoding, s1 not. */ + free (sl2); + result = 1; + } else - { - /* Neither s1 nor s2 could be converted to locale encoding. */ - result = U_STRCMP (s1, s2); - } + { + /* Neither s1 nor s2 could be converted to locale encoding. */ + result = U_STRCMP (s1, s2); + } } errno = final_errno; diff --git a/lib/unistr/u-strcspn.h b/lib/unistr/u-strcspn.h index de3265639..a6b5dad60 100644 --- a/lib/unistr/u-strcspn.h +++ b/lib/unistr/u-strcspn.h @@ -26,11 +26,11 @@ FUNC (const UNIT *str, const UNIT *reject) int count = U_STRMBTOUC (&uc, reject); if (count >= 0 && reject[count] == 0) { - const UNIT *found = U_STRCHR (str, uc); - if (found != NULL) - return found - str; - else - return U_STRLEN (str); + const UNIT *found = U_STRCHR (str, uc); + if (found != NULL) + return found - str; + else + return U_STRLEN (str); } } /* General case. */ @@ -39,15 +39,15 @@ FUNC (const UNIT *str, const UNIT *reject) for (;;) { - ucs4_t uc; - int count = U_STRMBTOUC (&uc, ptr); - if (count == 0) - return ptr - str; - if (count < 0) - break; - if (U_STRCHR (reject, uc)) - return ptr - str; - ptr += count; + ucs4_t uc; + int count = U_STRMBTOUC (&uc, ptr); + if (count == 0) + return ptr - str; + if (count < 0) + break; + if (U_STRCHR (reject, uc)) + return ptr - str; + ptr += count; } return U_STRLEN (str); } diff --git a/lib/unistr/u-strdup.h b/lib/unistr/u-strdup.h index 71e527a71..fdf7011df 100644 --- a/lib/unistr/u-strdup.h +++ b/lib/unistr/u-strdup.h @@ -31,7 +31,7 @@ FUNC (const UNIT *s) UNIT *destptr = dest; for (; n > 0; n--) - *destptr++ = *s++; + *destptr++ = *s++; #else memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT)); #endif diff --git a/lib/unistr/u-strpbrk.h b/lib/unistr/u-strpbrk.h index 2ff461824..e884a7b1f 100644 --- a/lib/unistr/u-strpbrk.h +++ b/lib/unistr/u-strpbrk.h @@ -33,13 +33,13 @@ FUNC (const UNIT *str, const UNIT *accept) for (;;) { - ucs4_t uc; - int count = U_STRMBTOUC (&uc, ptr); - if (count <= 0) - break; - if (U_STRCHR (accept, uc)) - return (UNIT *) ptr; - ptr += count; + ucs4_t uc; + int count = U_STRMBTOUC (&uc, ptr); + if (count <= 0) + break; + if (U_STRCHR (accept, uc)) + return (UNIT *) ptr; + ptr += count; } return NULL; } diff --git a/lib/unistr/u-strspn.h b/lib/unistr/u-strspn.h index 6502ce4bb..f1f805c13 100644 --- a/lib/unistr/u-strspn.h +++ b/lib/unistr/u-strspn.h @@ -26,11 +26,11 @@ FUNC (const UNIT *str, const UNIT *accept) int count = U_STRMBTOUC (&uc, accept); if (count >= 0 && accept[count] == 0) { - const UNIT *ptr = str; - for (; *ptr != 0; ptr += count) - if (U_CMP (ptr, accept, count) != 0) - break; - return ptr - str; + const UNIT *ptr = str; + for (; *ptr != 0; ptr += count) + if (U_CMP (ptr, accept, count) != 0) + break; + return ptr - str; } } /* General case. */ @@ -39,15 +39,15 @@ FUNC (const UNIT *str, const UNIT *accept) for (;;) { - ucs4_t uc; - int count = U_STRMBTOUC (&uc, ptr); - if (count == 0) - return ptr - str; - if (count < 0) - break; - if (!U_STRCHR (accept, uc)) - return ptr - str; - ptr += count; + ucs4_t uc; + int count = U_STRMBTOUC (&uc, ptr); + if (count == 0) + return ptr - str; + if (count < 0) + break; + if (!U_STRCHR (accept, uc)) + return ptr - str; + ptr += count; } return U_STRLEN (str); } diff --git a/lib/unistr/u-strstr.h b/lib/unistr/u-strstr.h index 55b5a31da..8a6689038 100644 --- a/lib/unistr/u-strstr.h +++ b/lib/unistr/u-strstr.h @@ -32,17 +32,17 @@ FUNC (const UNIT *haystack, const UNIT *needle) for (; *haystack != 0; haystack++) if (*haystack == first) { - /* Compare with needle's remaining units. */ - const UNIT *hptr = haystack + 1; - const UNIT *nptr = needle + 1; - for (;;) - { - if (*hptr != *nptr) - break; - hptr++; nptr++; - if (*nptr == 0) - return (UNIT *) haystack; - } + /* Compare with needle's remaining units. */ + const UNIT *hptr = haystack + 1; + const UNIT *nptr = needle + 1; + for (;;) + { + if (*hptr != *nptr) + break; + hptr++; nptr++; + if (*nptr == 0) + return (UNIT *) haystack; + } } return NULL; diff --git a/lib/unistr/u-strtok.h b/lib/unistr/u-strtok.h index 7ed57d6f4..137d4c306 100644 --- a/lib/unistr/u-strtok.h +++ b/lib/unistr/u-strtok.h @@ -22,7 +22,7 @@ FUNC (UNIT *str, const UNIT *delim, UNIT **ptr) { str = *ptr; if (str == NULL) - return NULL; /* reminder that end of token sequence has been reached */ + return NULL; /* reminder that end of token sequence has been reached */ } /* Skip leading delimiters. */ @@ -40,9 +40,9 @@ FUNC (UNIT *str, const UNIT *delim, UNIT **ptr) UNIT *token_end = U_STRPBRK (str, delim); if (token_end) { - /* NUL-terminate the token. */ - *token_end = 0; - *ptr = token_end + 1; + /* NUL-terminate the token. */ + *token_end = 0; + *ptr = token_end + 1; } else *ptr = NULL; diff --git a/lib/unistr/u16-check.c b/lib/unistr/u16-check.c index 380cec2cc..fe853c1ba 100644 --- a/lib/unistr/u16-check.c +++ b/lib/unistr/u16-check.c @@ -31,19 +31,19 @@ u16_check (const uint16_t *s, size_t n) uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) - { - s++; - continue; - } + { + s++; + continue; + } if (c < 0xdc00) - { - if (s + 2 <= s_end - && s[1] >= 0xdc00 && s[1] < 0xe000) - { - s += 2; - continue; - } - } + { + if (s + 2 <= s_end + && s[1] >= 0xdc00 && s[1] < 0xe000) + { + s += 2; + continue; + } + } /* invalid or incomplete multibyte character */ return s; } diff --git a/lib/unistr/u16-chr.c b/lib/unistr/u16-chr.c index 2d7d797e9..ad94e66d2 100644 --- a/lib/unistr/u16-chr.c +++ b/lib/unistr/u16-chr.c @@ -30,27 +30,27 @@ u16_chr (const uint16_t *s, size_t n, ucs4_t uc) uint16_t c0 = uc; for (; n > 0; s++, n--) - { - if (*s == c0) - return (uint16_t *) s; - } + { + if (*s == c0) + return (uint16_t *) s; + } } else switch (u16_uctomb_aux (c, uc, 2)) { case 2: - if (n > 1) - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; - - for (n--; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1) - return (uint16_t *) s; - } - } - break; + if (n > 1) + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; + + for (n--; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1) + return (uint16_t *) s; + } + } + break; } return NULL; } diff --git a/lib/unistr/u16-cmp.c b/lib/unistr/u16-cmp.c index 0130d271e..5a113a726 100644 --- a/lib/unistr/u16-cmp.c +++ b/lib/unistr/u16-cmp.c @@ -31,22 +31,22 @@ u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n) uint16_t c1 = *s1++; uint16_t c2 = *s2++; if (c1 == c2) - { - n--; - continue; - } + { + n--; + continue; + } if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2. */ } diff --git a/lib/unistr/u16-mblen.c b/lib/unistr/u16-mblen.c index 6bb35ac8e..9d2bcb0b7 100644 --- a/lib/unistr/u16-mblen.c +++ b/lib/unistr/u16-mblen.c @@ -29,19 +29,19 @@ u16_mblen (const uint16_t *s, size_t n) uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) - return (c != 0 ? 1 : 0); + return (c != 0 ? 1 : 0); #if CONFIG_UNICODE_SAFETY if (c < 0xdc00) - { - if (n >= 2 - && s[1] >= 0xdc00 && s[1] < 0xe000) - return 2; - } + { + if (n >= 2 + && s[1] >= 0xdc00 && s[1] < 0xe000) + return 2; + } #else - { - if (n >= 2) - return 2; - } + { + if (n >= 2) + return 2; + } #endif } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u16-mbsnlen.c b/lib/unistr/u16-mbsnlen.c index 881958e17..465509fd5 100644 --- a/lib/unistr/u16-mbsnlen.c +++ b/lib/unistr/u16-mbsnlen.c @@ -30,7 +30,7 @@ u16_mbsnlen (const uint16_t *s, size_t n) { int count = u16_mblen (s, n); if (count <= 0) - count = 1; + count = 1; s += count; n -= count; characters++; diff --git a/lib/unistr/u16-mbtouc-aux.c b/lib/unistr/u16-mbtouc-aux.c index 5f35b8674..6e9990f10 100644 --- a/lib/unistr/u16-mbtouc-aux.c +++ b/lib/unistr/u16-mbtouc-aux.c @@ -30,18 +30,18 @@ u16_mbtouc_aux (ucs4_t *puc, const uint16_t *s, size_t n) if (c < 0xdc00) { if (n >= 2) - { - if (s[1] >= 0xdc00 && s[1] < 0xe000) - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + if (s[1] >= 0xdc00 && s[1] < 0xe000) + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtouc-unsafe-aux.c b/lib/unistr/u16-mbtouc-unsafe-aux.c index 9906e3016..eafd853d7 100644 --- a/lib/unistr/u16-mbtouc-unsafe-aux.c +++ b/lib/unistr/u16-mbtouc-unsafe-aux.c @@ -32,20 +32,20 @@ u16_mbtouc_unsafe_aux (ucs4_t *puc, const uint16_t *s, size_t n) #endif { if (n >= 2) - { + { #if CONFIG_UNICODE_SAFETY - if (s[1] >= 0xdc00 && s[1] < 0xe000) + if (s[1] >= 0xdc00 && s[1] < 0xe000) #endif - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtouc-unsafe.c b/lib/unistr/u16-mbtouc-unsafe.c index cc858d88d..c01b25ba7 100644 --- a/lib/unistr/u16-mbtouc-unsafe.c +++ b/lib/unistr/u16-mbtouc-unsafe.c @@ -43,20 +43,20 @@ u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n) #endif { if (n >= 2) - { + { #if CONFIG_UNICODE_SAFETY - if (s[1] >= 0xdc00 && s[1] < 0xe000) + if (s[1] >= 0xdc00 && s[1] < 0xe000) #endif - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtouc.c b/lib/unistr/u16-mbtouc.c index 2691db836..4ea0c8f9a 100644 --- a/lib/unistr/u16-mbtouc.c +++ b/lib/unistr/u16-mbtouc.c @@ -40,18 +40,18 @@ u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n) if (c < 0xdc00) { if (n >= 2) - { - if (s[1] >= 0xdc00 && s[1] < 0xe000) - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + if (s[1] >= 0xdc00 && s[1] < 0xe000) + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtoucr.c b/lib/unistr/u16-mbtoucr.c index a1bd8ee9a..98bb791c7 100644 --- a/lib/unistr/u16-mbtoucr.c +++ b/lib/unistr/u16-mbtoucr.c @@ -33,20 +33,20 @@ u16_mbtoucr (ucs4_t *puc, const uint16_t *s, size_t n) if (c < 0xdc00) { if (n >= 2) - { - if (s[1] >= 0xdc00 && s[1] < 0xe000) - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + if (s[1] >= 0xdc00 && s[1] < 0xe000) + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-next.c b/lib/unistr/u16-next.c index 7c49f72f6..bbf48a321 100644 --- a/lib/unistr/u16-next.c +++ b/lib/unistr/u16-next.c @@ -31,7 +31,7 @@ u16_next (ucs4_t *puc, const uint16_t *s) else { if (count < 0) - *puc = 0xfffd; + *puc = 0xfffd; return NULL; } } diff --git a/lib/unistr/u16-prev.c b/lib/unistr/u16-prev.c index 3beecf01c..c4d631bf8 100644 --- a/lib/unistr/u16-prev.c +++ b/lib/unistr/u16-prev.c @@ -29,25 +29,25 @@ u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start) uint16_t c_1 = s[-1]; if (c_1 < 0xd800 || c_1 >= 0xe000) - { - *puc = c_1; - return s - 1; - } + { + *puc = c_1; + return s - 1; + } #if CONFIG_UNICODE_SAFETY if (c_1 >= 0xdc00) #endif - if (s - 1 != start) - { - uint16_t c_2 = s[-2]; + if (s - 1 != start) + { + uint16_t c_2 = s[-2]; #if CONFIG_UNICODE_SAFETY - if (c_2 >= 0xd800 && c_2 < 0xdc00) + if (c_2 >= 0xd800 && c_2 < 0xdc00) #endif - { - *puc = 0x10000 + ((c_2 - 0xd800) << 10) + (c_1 - 0xdc00); - return s - 2; - } - } + { + *puc = 0x10000 + ((c_2 - 0xd800) << 10) + (c_1 - 0xdc00); + return s - 2; + } + } } return NULL; } diff --git a/lib/unistr/u16-strchr.c b/lib/unistr/u16-strchr.c index 673152f9f..decce012a 100644 --- a/lib/unistr/u16-strchr.c +++ b/lib/unistr/u16-strchr.c @@ -30,33 +30,33 @@ u16_strchr (const uint16_t *s, ucs4_t uc) uint16_t c0 = uc; for (;; s++) - { - if (*s == c0) - break; - if (*s == 0) - goto notfound; - } + { + if (*s == c0) + break; + if (*s == 0) + goto notfound; + } return (uint16_t *) s; } else switch (u16_uctomb_aux (c, uc, 2)) { case 2: - if (*s == 0) - goto notfound; - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; - - for (;; s++) - { - if (s[1] == 0) - goto notfound; - if (*s == c0 && s[1] == c1) - break; - } - return (uint16_t *) s; - } + if (*s == 0) + goto notfound; + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; + + for (;; s++) + { + if (s[1] == 0) + goto notfound; + if (*s == c0 && s[1] == c1) + break; + } + return (uint16_t *) s; + } } notfound: return NULL; diff --git a/lib/unistr/u16-strcmp.c b/lib/unistr/u16-strcmp.c index c161c65b6..8dd8bf9f2 100644 --- a/lib/unistr/u16-strcmp.c +++ b/lib/unistr/u16-strcmp.c @@ -31,19 +31,19 @@ u16_strcmp (const uint16_t *s1, const uint16_t *s2) uint16_t c1 = *s1++; uint16_t c2 = *s2++; if (c1 != 0 && c1 == c2) - continue; + continue; if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2. */ } diff --git a/lib/unistr/u16-strmblen.c b/lib/unistr/u16-strmblen.c index e7f362503..44510b1c8 100644 --- a/lib/unistr/u16-strmblen.c +++ b/lib/unistr/u16-strmblen.c @@ -32,7 +32,7 @@ u16_strmblen (const uint16_t *s) if (c < 0xdc00) { if (s[1] >= 0xdc00 && s[1] < 0xe000) - return 2; + return 2; } #else if (s[1] != 0) diff --git a/lib/unistr/u16-strmbtouc.c b/lib/unistr/u16-strmbtouc.c index 78d482ee7..e9cfb0612 100644 --- a/lib/unistr/u16-strmbtouc.c +++ b/lib/unistr/u16-strmbtouc.c @@ -40,10 +40,10 @@ u16_strmbtouc (ucs4_t *puc, const uint16_t *s) #else if (s[1] != 0) #endif - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u16-strncmp.c b/lib/unistr/u16-strncmp.c index 7278b6f07..4de32f887 100644 --- a/lib/unistr/u16-strncmp.c +++ b/lib/unistr/u16-strncmp.c @@ -31,22 +31,22 @@ u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n) uint16_t c1 = *s1++; uint16_t c2 = *s2++; if (c1 != 0 && c1 == c2) - { - n--; - continue; - } + { + n--; + continue; + } if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2, = 0 if c1 and c2 are both 0. */ } diff --git a/lib/unistr/u16-strrchr.c b/lib/unistr/u16-strrchr.c index b3c7ab034..c1986655c 100644 --- a/lib/unistr/u16-strrchr.c +++ b/lib/unistr/u16-strrchr.c @@ -33,32 +33,32 @@ u16_strrchr (const uint16_t *s, ucs4_t uc) uint16_t c0 = uc; for (;; s++) - { - if (*s == c0) - result = (uint16_t *) s; - if (*s == 0) - break; - } + { + if (*s == c0) + result = (uint16_t *) s; + if (*s == 0) + break; + } } else switch (u16_uctomb_aux (c, uc, 2)) { case 2: - if (*s) - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; + if (*s) + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; - /* FIXME: Maybe walking the string via u16_mblen is a win? */ - for (;; s++) - { - if (s[1] == 0) - break; - if (*s == c0 && s[1] == c1) - result = (uint16_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u16_mblen is a win? */ + for (;; s++) + { + if (s[1] == 0) + break; + if (*s == c0 && s[1] == c1) + result = (uint16_t *) s; + } + } + break; } return result; } diff --git a/lib/unistr/u16-to-u32.c b/lib/unistr/u16-to-u32.c index 2f39dcd7f..a6138c929 100644 --- a/lib/unistr/u16-to-u32.c +++ b/lib/unistr/u16-to-u32.c @@ -60,55 +60,55 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ count = u16_mbtouc (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ if (length + 1 > allocated) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 1 > allocated) - allocated = length + 1; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 1 > allocated) + allocated = length + 1; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + } result[length++] = uc; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -117,7 +117,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u16-to-u8.c b/lib/unistr/u16-to-u8.c index 38b27ec0e..33ed9b245 100644 --- a/lib/unistr/u16-to-u8.c +++ b/lib/unistr/u16-to-u8.c @@ -60,66 +60,66 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ count = u16_mbtouc (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ count = u8_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 6 > allocated) - allocated = length + 6; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u8_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 6 > allocated) + allocated = length + 6; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u8_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -128,7 +128,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u16-uctomb-aux.c b/lib/unistr/u16-uctomb-aux.c index 384452ba1..a290fadff 100644 --- a/lib/unistr/u16-uctomb-aux.c +++ b/lib/unistr/u16-uctomb-aux.c @@ -30,29 +30,29 @@ u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n) else if (uc < 0x10000) { if (uc >= 0xe000) - { - if (n >= 1) - { - s[0] = uc; - return 1; - } - } + { + if (n >= 1) + { + s[0] = uc; + return 1; + } + } else - return -1; + return -1; } else { if (uc < 0x110000) - { - if (n >= 2) - { - s[0] = 0xd800 + ((uc - 0x10000) >> 10); - s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); - return 2; - } - } + { + if (n >= 2) + { + s[0] = 0xd800 + ((uc - 0x10000) >> 10); + s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); + return 2; + } + } else - return -1; + return -1; } return -2; } diff --git a/lib/unistr/u16-uctomb.c b/lib/unistr/u16-uctomb.c index 6ac5ada5d..f7f499d48 100644 --- a/lib/unistr/u16-uctomb.c +++ b/lib/unistr/u16-uctomb.c @@ -33,38 +33,38 @@ u16_uctomb (uint16_t *s, ucs4_t uc, int n) if (uc < 0xd800) { if (n > 0) - { - s[0] = uc; - return 1; - } + { + s[0] = uc; + return 1; + } /* else return -2, below. */ } else if (uc < 0x10000) { if (uc >= 0xe000) - { - if (n >= 1) - { - s[0] = uc; - return 1; - } - } + { + if (n >= 1) + { + s[0] = uc; + return 1; + } + } else - return -1; + return -1; } else { if (uc < 0x110000) - { - if (n >= 2) - { - s[0] = 0xd800 + ((uc - 0x10000) >> 10); - s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); - return 2; - } - } + { + if (n >= 2) + { + s[0] = 0xd800 + ((uc - 0x10000) >> 10); + s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); + return 2; + } + } else - return -1; + return -1; } return -2; } diff --git a/lib/unistr/u32-check.c b/lib/unistr/u32-check.c index 87e912711..f68fae46d 100644 --- a/lib/unistr/u32-check.c +++ b/lib/unistr/u32-check.c @@ -30,10 +30,10 @@ u32_check (const uint32_t *s, size_t n) uint32_t c = *s; if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) - s++; + s++; else - /* invalid Unicode character */ - return s; + /* invalid Unicode character */ + return s; } return NULL; } diff --git a/lib/unistr/u32-chr.c b/lib/unistr/u32-chr.c index 5a594b253..77ce1c31c 100644 --- a/lib/unistr/u32-chr.c +++ b/lib/unistr/u32-chr.c @@ -26,7 +26,7 @@ u32_chr (const uint32_t *s, size_t n, ucs4_t uc) for (; n > 0; s++, n--) { if (*s == uc) - return (uint32_t *) s; + return (uint32_t *) s; } return NULL; } diff --git a/lib/unistr/u32-cmp.c b/lib/unistr/u32-cmp.c index a273b10b3..6a349b9d2 100644 --- a/lib/unistr/u32-cmp.c +++ b/lib/unistr/u32-cmp.c @@ -28,10 +28,10 @@ u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n) uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; if (uc1 == uc2) - { - n--; - continue; - } + { + n--; + continue; + } /* Note that uc1 and uc2 each have at most 31 bits. */ return (int)uc1 - (int)uc2; /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ diff --git a/lib/unistr/u32-mblen.c b/lib/unistr/u32-mblen.c index a48c8b21f..5f4fc1c3a 100644 --- a/lib/unistr/u32-mblen.c +++ b/lib/unistr/u32-mblen.c @@ -30,7 +30,7 @@ u32_mblen (const uint32_t *s, size_t n) #if CONFIG_UNICODE_SAFETY if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) #endif - return (c != 0 ? 1 : 0); + return (c != 0 ? 1 : 0); } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u32-next.c b/lib/unistr/u32-next.c index c529295cb..eaf6cb401 100644 --- a/lib/unistr/u32-next.c +++ b/lib/unistr/u32-next.c @@ -32,7 +32,7 @@ u32_next (ucs4_t *puc, const uint32_t *s) { #if CONFIG_UNICODE_SAFETY if (count < 0) - *puc = 0xfffd; + *puc = 0xfffd; #endif return NULL; } diff --git a/lib/unistr/u32-prev.c b/lib/unistr/u32-prev.c index bc20c93fe..18f8fc29b 100644 --- a/lib/unistr/u32-prev.c +++ b/lib/unistr/u32-prev.c @@ -30,10 +30,10 @@ u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start) #if CONFIG_UNICODE_SAFETY if (c_1 < 0xd800 || (c_1 >= 0xe000 && c_1 < 0x110000)) #endif - { - *puc = c_1; - return s - 1; - } + { + *puc = c_1; + return s - 1; + } } return NULL; } diff --git a/lib/unistr/u32-strchr.c b/lib/unistr/u32-strchr.c index 57a3a3cf8..c5581735b 100644 --- a/lib/unistr/u32-strchr.c +++ b/lib/unistr/u32-strchr.c @@ -26,9 +26,9 @@ u32_strchr (const uint32_t *s, ucs4_t uc) for (;; s++) { if (*s == uc) - break; + break; if (*s == 0) - goto notfound; + goto notfound; } return (uint32_t *) s; notfound: diff --git a/lib/unistr/u32-strcmp.c b/lib/unistr/u32-strcmp.c index b82d5ede9..19caa4f83 100644 --- a/lib/unistr/u32-strcmp.c +++ b/lib/unistr/u32-strcmp.c @@ -28,7 +28,7 @@ u32_strcmp (const uint32_t *s1, const uint32_t *s2) uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; if (uc1 != 0 && uc1 == uc2) - continue; + continue; /* Note that uc1 and uc2 each have at most 31 bits. */ return (int)uc1 - (int)uc2; /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ diff --git a/lib/unistr/u32-strcspn.c b/lib/unistr/u32-strcspn.c index f93ab2ef4..22ceaa1d2 100644 --- a/lib/unistr/u32-strcspn.c +++ b/lib/unistr/u32-strcspn.c @@ -36,8 +36,8 @@ FUNC (const UNIT *str, const UNIT *reject) ucs4_t uc = reject[0]; const UNIT *ptr = str; for (; *ptr != 0; ptr++) - if (*ptr == uc) - break; + if (*ptr == uc) + break; return ptr - str; } /* General case. */ @@ -45,7 +45,7 @@ FUNC (const UNIT *str, const UNIT *reject) const UNIT *ptr = str; for (; *ptr != 0; ptr++) if (U_STRCHR (reject, *ptr)) - break; + break; return ptr - str; } } diff --git a/lib/unistr/u32-strncmp.c b/lib/unistr/u32-strncmp.c index 026ce50c4..e044c42c2 100644 --- a/lib/unistr/u32-strncmp.c +++ b/lib/unistr/u32-strncmp.c @@ -28,10 +28,10 @@ u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n) uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; if (uc1 != 0 && uc1 == uc2) - { - n--; - continue; - } + { + n--; + continue; + } /* Note that uc1 and uc2 each have at most 31 bits. */ return (int)uc1 - (int)uc2; /* > 0 if uc1 > uc2, < 0 if uc1 < uc2, = 0 if uc1 and uc2 are both 0. */ diff --git a/lib/unistr/u32-strpbrk.c b/lib/unistr/u32-strpbrk.c index 9579a1b07..3cf7ae920 100644 --- a/lib/unistr/u32-strpbrk.c +++ b/lib/unistr/u32-strpbrk.c @@ -35,8 +35,8 @@ FUNC (const UNIT *str, const UNIT *accept) ucs4_t uc = accept[0]; const UNIT *ptr = str; for (; *ptr != 0; ptr++) - if (*ptr == uc) - return (UNIT *) ptr; + if (*ptr == uc) + return (UNIT *) ptr; return NULL; } /* General case. */ @@ -44,7 +44,7 @@ FUNC (const UNIT *str, const UNIT *accept) const UNIT *ptr = str; for (; *ptr != 0; ptr++) if (U_STRCHR (accept, *ptr)) - return (UNIT *) ptr; + return (UNIT *) ptr; return NULL; } } diff --git a/lib/unistr/u32-strrchr.c b/lib/unistr/u32-strrchr.c index b4641f337..c6f1b1de4 100644 --- a/lib/unistr/u32-strrchr.c +++ b/lib/unistr/u32-strrchr.c @@ -30,9 +30,9 @@ u32_strrchr (const uint32_t *s, ucs4_t uc) for (;; s++) { if (*s == uc) - result = (uint32_t *) s; + result = (uint32_t *) s; if (*s == 0) - break; + break; } return result; } diff --git a/lib/unistr/u32-strspn.c b/lib/unistr/u32-strspn.c index 6f802029a..a7f916e15 100644 --- a/lib/unistr/u32-strspn.c +++ b/lib/unistr/u32-strspn.c @@ -35,8 +35,8 @@ FUNC (const UNIT *str, const UNIT *accept) ucs4_t uc = accept[0]; const UNIT *ptr = str; for (; *ptr != 0; ptr++) - if (*ptr != uc) - break; + if (*ptr != uc) + break; return ptr - str; } /* General case. */ @@ -44,7 +44,7 @@ FUNC (const UNIT *str, const UNIT *accept) const UNIT *ptr = str; for (; *ptr != 0; ptr++) if (!U_STRCHR (accept, *ptr)) - break; + break; return ptr - str; } } diff --git a/lib/unistr/u32-to-u16.c b/lib/unistr/u32-to-u16.c index 3a32162cf..7b69d4a7a 100644 --- a/lib/unistr/u32-to-u16.c +++ b/lib/unistr/u32-to-u16.c @@ -60,60 +60,60 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ uc = *s++; /* No need to call the safe variant u32_mbtouc, because - u16_uctomb will verify uc anyway. */ + u16_uctomb will verify uc anyway. */ /* Store it in the output string. */ count = u16_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 2 > allocated) - allocated = length + 2; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u16_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 2 > allocated) + allocated = length + 2; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u16_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -122,7 +122,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u32-to-u8.c b/lib/unistr/u32-to-u8.c index 4dce896bd..30a104f82 100644 --- a/lib/unistr/u32-to-u8.c +++ b/lib/unistr/u32-to-u8.c @@ -60,60 +60,60 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ uc = *s++; /* No need to call the safe variant u32_mbtouc, because - u8_uctomb will verify uc anyway. */ + u8_uctomb will verify uc anyway. */ /* Store it in the output string. */ count = u8_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 6 > allocated) - allocated = length + 6; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u8_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 6 > allocated) + allocated = length + 6; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u8_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -122,7 +122,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u32-uctomb.c b/lib/unistr/u32-uctomb.c index 583b3b669..939c87709 100644 --- a/lib/unistr/u32-uctomb.c +++ b/lib/unistr/u32-uctomb.c @@ -33,12 +33,12 @@ u32_uctomb (uint32_t *s, ucs4_t uc, int n) if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000)) { if (n > 0) - { - *s = uc; - return 1; - } + { + *s = uc; + return 1; + } else - return -2; + return -2; } else return -1; diff --git a/lib/unistr/u8-check.c b/lib/unistr/u8-check.c index 53897fc5a..dea66ff28 100644 --- a/lib/unistr/u8-check.c +++ b/lib/unistr/u8-check.c @@ -31,73 +31,73 @@ u8_check (const uint8_t *s, size_t n) uint8_t c = *s; if (c < 0x80) - { - s++; - continue; - } + { + s++; + continue; + } if (c >= 0xc2) - { - if (c < 0xe0) - { - if (s + 2 <= s_end - && (s[1] ^ 0x80) < 0x40) - { - s += 2; - continue; - } - } - else if (c < 0xf0) - { - if (s + 3 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - s += 3; - continue; - } - } - else if (c < 0xf8) - { - if (s + 4 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (c < 0xe0) + { + if (s + 2 <= s_end + && (s[1] ^ 0x80) < 0x40) + { + s += 2; + continue; + } + } + else if (c < 0xf0) + { + if (s + 3 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + s += 3; + continue; + } + } + else if (c < 0xf8) + { + if (s + 4 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - s += 4; - continue; - } - } + ) + { + s += 4; + continue; + } + } #if 0 - else if (c < 0xfc) - { - if (s + 5 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - s += 5; - continue; - } - } - else if (c < 0xfe) - { - if (s + 6 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - s += 6; - continue; - } - } + else if (c < 0xfc) + { + if (s + 5 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + s += 5; + continue; + } + } + else if (c < 0xfe) + { + if (s + 6 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + s += 6; + continue; + } + } #endif - } + } /* invalid or incomplete multibyte character */ return s; } diff --git a/lib/unistr/u8-chr.c b/lib/unistr/u8-chr.c index 2c4d7687b..4ccd576e1 100644 --- a/lib/unistr/u8-chr.c +++ b/lib/unistr/u8-chr.c @@ -30,58 +30,58 @@ u8_chr (const uint8_t *s, size_t n, ucs4_t uc) uint8_t c0 = uc; for (; n > 0; s++, n--) - { - if (*s == c0) - return (uint8_t *) s; - } + { + if (*s == c0) + return (uint8_t *) s; + } } else switch (u8_uctomb_aux (c, uc, 6)) { case 2: - if (n > 1) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; + if (n > 1) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; - for (n--; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1) - return (uint8_t *) s; - } - } - break; + for (n--; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1) + return (uint8_t *) s; + } + } + break; case 3: - if (n > 2) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; + if (n > 2) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; - for (n -= 2; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1 && s[2] == c2) - return (uint8_t *) s; - } - } - break; + for (n -= 2; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1 && s[2] == c2) + return (uint8_t *) s; + } + } + break; case 4: - if (n > 3) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; + if (n > 3) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; - for (n -= 3; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) - return (uint8_t *) s; - } - } - break; + for (n -= 3; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) + return (uint8_t *) s; + } + } + break; } return NULL; } diff --git a/lib/unistr/u8-mblen.c b/lib/unistr/u8-mblen.c index 1981befed..326662312 100644 --- a/lib/unistr/u8-mblen.c +++ b/lib/unistr/u8-mblen.c @@ -29,69 +29,69 @@ u8_mblen (const uint8_t *s, size_t n) uint8_t c = *s; if (c < 0x80) - return (c != 0 ? 1 : 0); + return (c != 0 ? 1 : 0); if (c >= 0xc2) - { - if (c < 0xe0) - { - if (n >= 2 + { + if (c < 0xe0) + { + if (n >= 2 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 + && (s[1] ^ 0x80) < 0x40 #endif - ) - return 2; - } - else if (c < 0xf0) - { - if (n >= 3 + ) + return 2; + } + else if (c < 0xf0) + { + if (n >= 3 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0) #endif - ) - return 3; - } - else if (c < 0xf8) - { - if (n >= 4 + ) + return 3; + } + else if (c < 0xf8) + { + if (n >= 4 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif #endif - ) - return 4; - } + ) + return 4; + } #if 0 - else if (c < 0xfc) - { - if (n >= 5 + else if (c < 0xfc) + { + if (n >= 5 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88) #endif - ) - return 5; - } - else if (c < 0xfe) - { - if (n >= 6 + ) + return 5; + } + else if (c < 0xfe) + { + if (n >= 6 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84) #endif - ) - return 6; - } + ) + return 6; + } #endif - } + } } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u8-mbsnlen.c b/lib/unistr/u8-mbsnlen.c index 29af297ff..c3de7f0c3 100644 --- a/lib/unistr/u8-mbsnlen.c +++ b/lib/unistr/u8-mbsnlen.c @@ -30,7 +30,7 @@ u8_mbsnlen (const uint8_t *s, size_t n) { int count = u8_mblen (s, n); if (count <= 0) - count = 1; + count = 1; s += count; n -= count; characters++; diff --git a/lib/unistr/u8-mbtouc-aux.c b/lib/unistr/u8-mbtouc-aux.c index 53d02bf0d..e0d20d92d 100644 --- a/lib/unistr/u8-mbtouc-aux.c +++ b/lib/unistr/u8-mbtouc-aux.c @@ -30,124 +30,124 @@ u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n) if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 3) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (n >= 4) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + ) + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 5) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 6) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtouc-unsafe-aux.c b/lib/unistr/u8-mbtouc-unsafe-aux.c index 43e4a360f..53188639d 100644 --- a/lib/unistr/u8-mbtouc-unsafe-aux.c +++ b/lib/unistr/u8-mbtouc-unsafe-aux.c @@ -30,134 +30,134 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { + { + if (n >= 2) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #endif - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { + { + if (n >= 3) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #endif - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { + { + if (n >= 4) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #endif - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { + { + if (n >= 5) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { + { + if (n >= 6) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtouc-unsafe.c b/lib/unistr/u8-mbtouc-unsafe.c index 466156967..0772c0b07 100644 --- a/lib/unistr/u8-mbtouc-unsafe.c +++ b/lib/unistr/u8-mbtouc-unsafe.c @@ -41,134 +41,134 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) else if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { + { + if (n >= 2) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #endif - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { + { + if (n >= 3) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #endif - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { + { + if (n >= 4) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #endif - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { + { + if (n >= 5) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { + { + if (n >= 6) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtouc.c b/lib/unistr/u8-mbtouc.c index ff624f17d..2c2927964 100644 --- a/lib/unistr/u8-mbtouc.c +++ b/lib/unistr/u8-mbtouc.c @@ -40,124 +40,124 @@ u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n) else if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 3) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (n >= 4) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + ) + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 5) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 6) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtoucr.c b/lib/unistr/u8-mbtoucr.c index dd8335247..c93ec883d 100644 --- a/lib/unistr/u8-mbtoucr.c +++ b/lib/unistr/u8-mbtoucr.c @@ -33,250 +33,250 @@ u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n) else if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } else if (c < 0xf0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } else if (c < 0xf8) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + ) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + if (n >= 4) + { + if ((s[3] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - if (n >= 5) - { - if ((s[4] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + if (n >= 4) + { + if ((s[3] ^ 0x80) < 0x40) + { + if (n >= 5) + { + if ((s[4] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } else if (c < 0xfe) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - if (n >= 5) - { - if ((s[4] ^ 0x80) < 0x40) - { - if (n >= 6) - { - if ((s[5] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + if (n >= 4) + { + if ((s[3] ^ 0x80) < 0x40) + { + if (n >= 5) + { + if ((s[4] ^ 0x80) < 0x40) + { + if (n >= 6) + { + if ((s[5] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-next.c b/lib/unistr/u8-next.c index ecf4f80a8..223675f66 100644 --- a/lib/unistr/u8-next.c +++ b/lib/unistr/u8-next.c @@ -31,7 +31,7 @@ u8_next (ucs4_t *puc, const uint8_t *s) else { if (count < 0) - *puc = 0xfffd; + *puc = 0xfffd; return NULL; } } diff --git a/lib/unistr/u8-prev.c b/lib/unistr/u8-prev.c index 245d22ff0..e97884eb8 100644 --- a/lib/unistr/u8-prev.c +++ b/lib/unistr/u8-prev.c @@ -29,65 +29,65 @@ u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start) uint8_t c_1 = s[-1]; if (c_1 < 0x80) - { - *puc = c_1; - return s - 1; - } + { + *puc = c_1; + return s - 1; + } #if CONFIG_UNICODE_SAFETY if ((c_1 ^ 0x80) < 0x40) #endif - if (s - 1 != start) - { - uint8_t c_2 = s[-2]; + if (s - 1 != start) + { + uint8_t c_2 = s[-2]; - if (c_2 >= 0xc2 && c_2 < 0xe0) - { - *puc = ((unsigned int) (c_2 & 0x1f) << 6) - | (unsigned int) (c_1 ^ 0x80); - return s - 2; - } + if (c_2 >= 0xc2 && c_2 < 0xe0) + { + *puc = ((unsigned int) (c_2 & 0x1f) << 6) + | (unsigned int) (c_1 ^ 0x80); + return s - 2; + } #if CONFIG_UNICODE_SAFETY - if ((c_2 ^ 0x80) < 0x40) + if ((c_2 ^ 0x80) < 0x40) #endif - if (s - 2 != start) - { - uint8_t c_3 = s[-3]; + if (s - 2 != start) + { + uint8_t c_3 = s[-3]; - if (c_3 >= 0xe0 && c_3 < 0xf0 + if (c_3 >= 0xe0 && c_3 < 0xf0 #if CONFIG_UNICODE_SAFETY - && (c_3 >= 0xe1 || c_2 >= 0xa0) - && (c_3 != 0xed || c_2 < 0xa0) + && (c_3 >= 0xe1 || c_2 >= 0xa0) + && (c_3 != 0xed || c_2 < 0xa0) #endif - ) - { - *puc = ((unsigned int) (c_3 & 0x0f) << 12) - | ((unsigned int) (c_2 ^ 0x80) << 6) - | (unsigned int) (c_1 ^ 0x80); - return s - 3; - } + ) + { + *puc = ((unsigned int) (c_3 & 0x0f) << 12) + | ((unsigned int) (c_2 ^ 0x80) << 6) + | (unsigned int) (c_1 ^ 0x80); + return s - 3; + } #if CONFIG_UNICODE_SAFETY - if ((c_3 ^ 0x80) < 0x40) + if ((c_3 ^ 0x80) < 0x40) #endif - if (s - 3 != start) - { - uint8_t c_4 = s[-4]; + if (s - 3 != start) + { + uint8_t c_4 = s[-4]; - if (c_4 >= 0xf0 && c_4 < 0xf8 + if (c_4 >= 0xf0 && c_4 < 0xf8 #if CONFIG_UNICODE_SAFETY - && (c_4 >= 0xf1 || c_3 >= 0x90) - && (c_4 < 0xf4 || (c_4 == 0xf4 && c_3 < 0x90)) + && (c_4 >= 0xf1 || c_3 >= 0x90) + && (c_4 < 0xf4 || (c_4 == 0xf4 && c_3 < 0x90)) #endif - ) - { - *puc = ((unsigned int) (c_4 & 0x07) << 18) - | ((unsigned int) (c_3 ^ 0x80) << 12) - | ((unsigned int) (c_2 ^ 0x80) << 6) - | (unsigned int) (c_1 ^ 0x80); - return s - 4; - } - } - } - } + ) + { + *puc = ((unsigned int) (c_4 & 0x07) << 18) + | ((unsigned int) (c_3 ^ 0x80) << 12) + | ((unsigned int) (c_2 ^ 0x80) << 6) + | (unsigned int) (c_1 ^ 0x80); + return s - 4; + } + } + } + } } return NULL; } diff --git a/lib/unistr/u8-set.c b/lib/unistr/u8-set.c index 5bb4fd7ae..ac1536e11 100644 --- a/lib/unistr/u8-set.c +++ b/lib/unistr/u8-set.c @@ -33,12 +33,12 @@ FUNC (UNIT *s, ucs4_t uc, size_t n) if (n > 0) { if (IS_SINGLE_UNIT (uc)) - memset ((char *) s, uc, n); + memset ((char *) s, uc, n); else - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } } return s; } diff --git a/lib/unistr/u8-strchr.c b/lib/unistr/u8-strchr.c index 370a7930c..87bfe7f1a 100644 --- a/lib/unistr/u8-strchr.c +++ b/lib/unistr/u8-strchr.c @@ -30,70 +30,70 @@ u8_strchr (const uint8_t *s, ucs4_t uc) uint8_t c0 = uc; for (;; s++) - { - if (*s == c0) - break; - if (*s == 0) - goto notfound; - } + { + if (*s == c0) + break; + if (*s == 0) + goto notfound; + } return (uint8_t *) s; } else switch (u8_uctomb_aux (c, uc, 6)) { case 2: - if (*s == 0) - goto notfound; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; + if (*s == 0) + goto notfound; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; - for (;; s++) - { - if (s[1] == 0) - goto notfound; - if (*s == c0 && s[1] == c1) - break; - } - return (uint8_t *) s; - } + for (;; s++) + { + if (s[1] == 0) + goto notfound; + if (*s == c0 && s[1] == c1) + break; + } + return (uint8_t *) s; + } case 3: - if (*s == 0 || s[1] == 0) - goto notfound; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; + if (*s == 0 || s[1] == 0) + goto notfound; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; - for (;; s++) - { - if (s[2] == 0) - goto notfound; - if (*s == c0 && s[1] == c1 && s[2] == c2) - break; - } - return (uint8_t *) s; - } + for (;; s++) + { + if (s[2] == 0) + goto notfound; + if (*s == c0 && s[1] == c1 && s[2] == c2) + break; + } + return (uint8_t *) s; + } case 4: - if (*s == 0 || s[1] == 0 || s[2] == 0) - goto notfound; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; + if (*s == 0 || s[1] == 0 || s[2] == 0) + goto notfound; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; - for (;; s++) - { - if (s[3] == 0) - goto notfound; - if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) - break; - } - return (uint8_t *) s; - } + for (;; s++) + { + if (s[3] == 0) + goto notfound; + if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) + break; + } + return (uint8_t *) s; + } } notfound: return NULL; diff --git a/lib/unistr/u8-strmblen.c b/lib/unistr/u8-strmblen.c index 52db99d04..159bdfca5 100644 --- a/lib/unistr/u8-strmblen.c +++ b/lib/unistr/u8-strmblen.c @@ -31,64 +31,64 @@ u8_strmblen (const uint8_t *s) if (c >= 0xc2) { if (c < 0xe0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #else - if (s[1] != 0) + if (s[1] != 0) #endif - return 2; - } + return 2; + } else if (c < 0xf0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #else - if (s[1] != 0 && s[2] != 0) + if (s[1] != 0 && s[2] != 0) #endif - return 3; - } + return 3; + } else if (c < 0xf8) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0) #endif - return 4; - } + return 4; + } #if 0 else if (c < 0xfc) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) #endif - return 5; - } + return 5; + } else if (c < 0xfe) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) #endif - return 6; - } + return 6; + } #endif } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u8-strmbtouc.c b/lib/unistr/u8-strmbtouc.c index bc2fdb0de..36562d132 100644 --- a/lib/unistr/u8-strmbtouc.c +++ b/lib/unistr/u8-strmbtouc.c @@ -34,94 +34,94 @@ u8_strmbtouc (ucs4_t *puc, const uint8_t *s) if (c >= 0xc2) { if (c < 0xe0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #else - if (s[1] != 0) + if (s[1] != 0) #endif - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - } + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + } else if (c < 0xf0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #else - if (s[1] != 0 && s[2] != 0) + if (s[1] != 0 && s[2] != 0) #endif - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - } + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + } else if (c < 0xf8) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0) #endif - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - } + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + } #if 0 else if (c < 0xfc) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) #endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - } + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + } else if (c < 0xfe) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) #endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - } + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + } #endif } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u8-strrchr.c b/lib/unistr/u8-strrchr.c index 309f3234e..487abdae3 100644 --- a/lib/unistr/u8-strrchr.c +++ b/lib/unistr/u8-strrchr.c @@ -33,69 +33,69 @@ u8_strrchr (const uint8_t *s, ucs4_t uc) uint8_t c0 = uc; for (;; s++) - { - if (*s == c0) - result = (uint8_t *) s; - if (*s == 0) - break; - } + { + if (*s == c0) + result = (uint8_t *) s; + if (*s == 0) + break; + } } else switch (u8_uctomb_aux (c, uc, 6)) { case 2: - if (*s) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; + if (*s) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[1] == 0) - break; - if (*s == c0 && s[1] == c1) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[1] == 0) + break; + if (*s == c0 && s[1] == c1) + result = (uint8_t *) s; + } + } + break; case 3: - if (*s && s[1]) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; + if (*s && s[1]) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[2] == 0) - break; - if (*s == c0 && s[1] == c1 && s[2] == c2) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[2] == 0) + break; + if (*s == c0 && s[1] == c1 && s[2] == c2) + result = (uint8_t *) s; + } + } + break; case 4: - if (*s && s[1] && s[2]) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; + if (*s && s[1] && s[2]) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[3] == 0) - break; - if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[3] == 0) + break; + if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) + result = (uint8_t *) s; + } + } + break; } return result; } diff --git a/lib/unistr/u8-to-u16.c b/lib/unistr/u8-to-u16.c index 03c660009..1c4ce8b75 100644 --- a/lib/unistr/u8-to-u16.c +++ b/lib/unistr/u8-to-u16.c @@ -60,66 +60,66 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ count = u8_mbtouc (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ count = u16_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 2 > allocated) - allocated = length + 2; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u16_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 2 > allocated) + allocated = length + 2; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u16_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -128,7 +128,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u8-to-u32.c b/lib/unistr/u8-to-u32.c index 2a0ad39e6..f522a3be2 100644 --- a/lib/unistr/u8-to-u32.c +++ b/lib/unistr/u8-to-u32.c @@ -60,55 +60,55 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ count = u8_mbtouc (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ if (length + 1 > allocated) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 1 > allocated) - allocated = length + 1; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 1 > allocated) + allocated = length + 1; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + } result[length++] = uc; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -117,7 +117,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u8-uctomb-aux.c b/lib/unistr/u8-uctomb-aux.c index c42fa5015..5a6b6b5c0 100644 --- a/lib/unistr/u8-uctomb-aux.c +++ b/lib/unistr/u8-uctomb-aux.c @@ -33,9 +33,9 @@ u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n) else if (uc < 0x10000) { if (uc < 0xd800 || uc >= 0xe000) - count = 3; + count = 3; else - return -1; + return -1; } #if 0 else if (uc < 0x200000) diff --git a/lib/unistr/u8-uctomb.c b/lib/unistr/u8-uctomb.c index 33921669e..81e41adf4 100644 --- a/lib/unistr/u8-uctomb.c +++ b/lib/unistr/u8-uctomb.c @@ -33,10 +33,10 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) if (uc < 0x80) { if (n > 0) - { - s[0] = uc; - return 1; - } + { + s[0] = uc; + return 1; + } /* else return -2, below. */ } else @@ -44,43 +44,43 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) int count; if (uc < 0x800) - count = 2; + count = 2; else if (uc < 0x10000) - { - if (uc < 0xd800 || uc >= 0xe000) - count = 3; - else - return -1; - } + { + if (uc < 0xd800 || uc >= 0xe000) + count = 3; + else + return -1; + } #if 0 else if (uc < 0x200000) - count = 4; + count = 4; else if (uc < 0x4000000) - count = 5; + count = 5; else if (uc <= 0x7fffffff) - count = 6; + count = 6; #else else if (uc < 0x110000) - count = 4; + count = 4; #endif else - return -1; + return -1; if (n >= count) - { - switch (count) /* note: code falls through cases! */ - { + { + switch (count) /* note: code falls through cases! */ + { #if 0 - case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; - case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; + case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; + case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; #endif - case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; - case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; - case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; - /*case 1:*/ s[0] = uc; - } - return count; - } + case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; + case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; + case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; + /*case 1:*/ s[0] = uc; + } + return count; + } } return -2; } diff --git a/lib/uniwbrk/u-wordbreaks.h b/lib/uniwbrk/u-wordbreaks.h index 5ef4e8c1a..ca8e39d96 100644 --- a/lib/uniwbrk/u-wordbreaks.h +++ b/lib/uniwbrk/u-wordbreaks.h @@ -23,105 +23,105 @@ FUNC (const UNIT *s, size_t n, char *p) const UNIT *s_end = s + n; /* Word break property of the last character. - -1 at the very beginning of the string. */ + -1 at the very beginning of the string. */ int last_char_prop = -1; /* Format and Extend characters are ignored; this means, the mostly used - unit is the complex character (= character with subsequent ignored - characters). - Word break property of the last complex character. - -1 at the very beginning of the string. */ + unit is the complex character (= character with subsequent ignored + characters). + Word break property of the last complex character. + -1 at the very beginning of the string. */ int last_compchar_prop = -1; char *last_compchar_ptr = NULL; /* For recognizing rules involving 3 complex characters: - Word break property of the second-to-last complex character. - -1 at the very beginning of the string. */ + Word break property of the second-to-last complex character. + -1 at the very beginning of the string. */ int secondlast_compchar_prop = -1; /* Don't break inside multibyte characters. */ memset (p, 0, n); while (s < s_end) - { - ucs4_t uc; - int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); - int prop = uc_wordbreak_property (uc); + { + ucs4_t uc; + int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); + int prop = uc_wordbreak_property (uc); - /* No break at the start of the string. */ - if (last_char_prop >= 0) - { - /* No break between CR and LF. */ - if (last_char_prop == WBP_CR && prop == WBP_LF) - /* *p = 0 */; - /* Break before and after newlines. */ - else if (last_char_prop >= WBP_NEWLINE - /* same as: - last_char_prop == WBP_CR - || last_char_prop == WBP_LF - || last_char_prop == WBP_NEWLINE */ - || prop >= WBP_NEWLINE - /* same as: - prop == WBP_CR - || prop == WBP_LF - || prop == WBP_NEWLINE */) - *p = 1; - /* Ignore Format and Extend characters. */ - else if (!(prop == WBP_EXTEND || prop == WBP_FORMAT)) - { - /* No break in these situations (see UAX #29): + /* No break at the start of the string. */ + if (last_char_prop >= 0) + { + /* No break between CR and LF. */ + if (last_char_prop == WBP_CR && prop == WBP_LF) + /* *p = 0 */; + /* Break before and after newlines. */ + else if (last_char_prop >= WBP_NEWLINE + /* same as: + last_char_prop == WBP_CR + || last_char_prop == WBP_LF + || last_char_prop == WBP_NEWLINE */ + || prop >= WBP_NEWLINE + /* same as: + prop == WBP_CR + || prop == WBP_LF + || prop == WBP_NEWLINE */) + *p = 1; + /* Ignore Format and Extend characters. */ + else if (!(prop == WBP_EXTEND || prop == WBP_FORMAT)) + { + /* No break in these situations (see UAX #29): - secondlast last current + secondlast last current - ALetter (MidLetter | MidNumLet) × ALetter (WB7) - ALetter × (MidLetter | MidNumLet) ALetter (WB6) - Numeric (MidNum | MidNumLet) × Numeric (WB11) - Numeric × (MidNum | MidNumLet) Numeric (WB12) - ALetter × ALetter (WB5) - ALetter × Numeric (WB9) - Numeric × ALetter (WB10) - Numeric × Numeric (WB8) - Katakana × Katakana (WB13) - (ALetter | Numeric | Katakana) × ExtendNumLet (WB13a) - ExtendNumLet × ExtendNumLet (WB13a) - ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) - */ - /* No break across certain punctuation. Also, disable word - breaks that were recognized earlier (due to lookahead of - only one complex character). */ - if ((prop == WBP_ALETTER - && (last_compchar_prop == WBP_MIDLETTER - || last_compchar_prop == WBP_MIDNUMLET) - && secondlast_compchar_prop == WBP_ALETTER) - || (prop == WBP_NUMERIC - && (last_compchar_prop == WBP_MIDNUM - || last_compchar_prop == WBP_MIDNUMLET) - && secondlast_compchar_prop == WBP_NUMERIC)) - { - *last_compchar_ptr = 0; - /* *p = 0; */ - } - else - { - /* Perform a single table lookup. */ - if (uniwbrk_table[last_compchar_prop][prop]) - *p = 1; - /* else *p = 0; */ - } - } - } + ALetter (MidLetter | MidNumLet) × ALetter (WB7) + ALetter × (MidLetter | MidNumLet) ALetter (WB6) + Numeric (MidNum | MidNumLet) × Numeric (WB11) + Numeric × (MidNum | MidNumLet) Numeric (WB12) + ALetter × ALetter (WB5) + ALetter × Numeric (WB9) + Numeric × ALetter (WB10) + Numeric × Numeric (WB8) + Katakana × Katakana (WB13) + (ALetter | Numeric | Katakana) × ExtendNumLet (WB13a) + ExtendNumLet × ExtendNumLet (WB13a) + ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) + */ + /* No break across certain punctuation. Also, disable word + breaks that were recognized earlier (due to lookahead of + only one complex character). */ + if ((prop == WBP_ALETTER + && (last_compchar_prop == WBP_MIDLETTER + || last_compchar_prop == WBP_MIDNUMLET) + && secondlast_compchar_prop == WBP_ALETTER) + || (prop == WBP_NUMERIC + && (last_compchar_prop == WBP_MIDNUM + || last_compchar_prop == WBP_MIDNUMLET) + && secondlast_compchar_prop == WBP_NUMERIC)) + { + *last_compchar_ptr = 0; + /* *p = 0; */ + } + else + { + /* Perform a single table lookup. */ + if (uniwbrk_table[last_compchar_prop][prop]) + *p = 1; + /* else *p = 0; */ + } + } + } - last_char_prop = prop; - /* Ignore Format and Extend characters, except at the start of the string. */ - if (last_compchar_prop < 0 || !(prop == WBP_EXTEND || prop == WBP_FORMAT)) - { - secondlast_compchar_prop = last_compchar_prop; - last_compchar_prop = prop; - last_compchar_ptr = p; - } + last_char_prop = prop; + /* Ignore Format and Extend characters, except at the start of the string. */ + if (last_compchar_prop < 0 || !(prop == WBP_EXTEND || prop == WBP_FORMAT)) + { + secondlast_compchar_prop = last_compchar_prop; + last_compchar_prop = prop; + last_compchar_ptr = p; + } - s += count; - p += count; - } + s += count; + p += count; + } } } diff --git a/lib/uniwbrk/u8-wordbreaks.c b/lib/uniwbrk/u8-wordbreaks.c index 59d2076de..af8dc84ef 100644 --- a/lib/uniwbrk/u8-wordbreaks.c +++ b/lib/uniwbrk/u8-wordbreaks.c @@ -50,28 +50,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -98,20 +98,20 @@ main (int argc, char * argv[]) u8_wordbreaks ((uint8_t *) input, length, breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case 1: - /* U+2027 in UTF-8 encoding */ - putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); - break; - case 0: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case 1: + /* U+2027 in UTF-8 encoding */ + putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); + break; + case 0: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/uniwbrk/ulc-wordbreaks.c b/lib/uniwbrk/ulc-wordbreaks.c index cb6e131cc..9869bfb7c 100644 --- a/lib/uniwbrk/ulc-wordbreaks.c +++ b/lib/uniwbrk/ulc-wordbreaks.c @@ -49,60 +49,60 @@ ulc_wordbreaks (const char *s, size_t n, char *p) const char *encoding = locale_charset (); if (is_utf8_encoding (encoding)) - u8_wordbreaks ((const uint8_t *) s, n, p); + u8_wordbreaks ((const uint8_t *) s, n, p); else - { - /* Convert the string to UTF-8 and build a translation table - from offsets into s to offsets into the translated string. */ - size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); - - if (offsets != NULL) - { - uint8_t *t; - size_t m; - - t = u8_conv_from_encoding (encoding, iconveh_question_mark, - s, n, offsets, NULL, &m); - if (t != NULL) - { - char *q = (char *) (m > 0 ? malloc (m) : NULL); - - if (m == 0 || q != NULL) - { - size_t i; - - /* Determine the word breaks of the UTF-8 string. */ - u8_wordbreaks (t, m, q); - - /* Translate the result back to the original string. */ - memset (p, 0, n); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - p[i] = q[offsets[i]]; - - free (q); - free (t); - free (offsets); - return; - } - free (t); - } - free (offsets); - } - - /* Impossible to convert. */ + { + /* Convert the string to UTF-8 and build a translation table + from offsets into s to offsets into the translated string. */ + size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); + + if (offsets != NULL) + { + uint8_t *t; + size_t m; + + t = u8_conv_from_encoding (encoding, iconveh_question_mark, + s, n, offsets, NULL, &m); + if (t != NULL) + { + char *q = (char *) (m > 0 ? malloc (m) : NULL); + + if (m == 0 || q != NULL) + { + size_t i; + + /* Determine the word breaks of the UTF-8 string. */ + u8_wordbreaks (t, m, q); + + /* Translate the result back to the original string. */ + memset (p, 0, n); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + p[i] = q[offsets[i]]; + + free (q); + free (t); + free (offsets); + return; + } + free (t); + } + free (offsets); + } + + /* Impossible to convert. */ #if C_CTYPE_ASCII - if (is_all_ascii (s, n)) - { - /* ASCII is a subset of UTF-8. */ - u8_wordbreaks ((const uint8_t *) s, n, p); - return; - } + if (is_all_ascii (s, n)) + { + /* ASCII is a subset of UTF-8. */ + u8_wordbreaks ((const uint8_t *) s, n, p); + return; + } #endif - /* We have a non-ASCII string and cannot convert it. - Don't produce any word breaks. */ - memset (p, 0, n); - } + /* We have a non-ASCII string and cannot convert it. + Don't produce any word breaks. */ + memset (p, 0, n); + } } } @@ -127,28 +127,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -176,19 +176,19 @@ main (int argc, char * argv[]) ulc_wordbreaks (input, length, breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case 1: - putc ('|', stdout); - break; - case 0: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case 1: + putc ('|', stdout); + break; + case 0: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/uniwbrk/wbrktable.c b/lib/uniwbrk/wbrktable.c index 81a2323e0..20aefdbfe 100644 --- a/lib/uniwbrk/wbrktable.c +++ b/lib/uniwbrk/wbrktable.c @@ -22,22 +22,22 @@ /* This table contains the following rules (see UAX #29): - last current + last current - ALetter × ALetter (WB5) - ALetter × Numeric (WB9) - Numeric × ALetter (WB10) - Numeric × Numeric (WB8) - Katakana × Katakana (WB13) + ALetter × ALetter (WB5) + ALetter × Numeric (WB9) + Numeric × ALetter (WB10) + Numeric × Numeric (WB8) + Katakana × Katakana (WB13) (ALetter | Numeric | Katakana) × ExtendNumLet (WB13a) - ExtendNumLet × ExtendNumLet (WB13a) - ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) + ExtendNumLet × ExtendNumLet (WB13a) + ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) */ const unsigned char uniwbrk_table[10][8] = { /* current: OTHER MIDNUMLET NUMERIC */ - /* KATAKANA MIDLETTER EXTENDNUMLET */ - /* ALETTER MIDNUM */ + /* KATAKANA MIDLETTER EXTENDNUMLET */ + /* ALETTER MIDNUM */ /* last */ /* WBP_OTHER */ { 1, 1, 1, 1, 1, 1, 1, 1 }, /* WBP_KATAKANA */ { 1, 0, 1, 1, 1, 1, 1, 0 }, diff --git a/lib/uniwbrk/wordbreak-property.c b/lib/uniwbrk/wordbreak-property.c index 4d0a212d1..38c25bf16 100644 --- a/lib/uniwbrk/wordbreak-property.c +++ b/lib/uniwbrk/wordbreak-property.c @@ -30,15 +30,15 @@ uc_wordbreak_property (ucs4_t uc) { int lookup1 = uniwbrkprop.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> wbrkprop_header_2) & wbrkprop_header_3; - int lookup2 = uniwbrkprop.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = uc & wbrkprop_header_4; - return uniwbrkprop.level3[lookup2 + index3]; - } - } + { + unsigned int index2 = (uc >> wbrkprop_header_2) & wbrkprop_header_3; + int lookup2 = uniwbrkprop.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = uc & wbrkprop_header_4; + return uniwbrkprop.level3[lookup2 + index3]; + } + } } return WBP_OTHER; } diff --git a/lib/uniwidth/u16-width.c b/lib/uniwidth/u16-width.c index b866b3c9e..dd68a4e73 100644 --- a/lib/uniwidth/u16-width.c +++ b/lib/uniwidth/u16-width.c @@ -36,11 +36,11 @@ u16_width (const uint16_t *s, size_t n, const char *encoding) s += u16_mbtouc_unsafe (&uc, s, s_end - s); if (uc == 0) - break; /* end of string reached */ + break; /* end of string reached */ w = uc_width (uc, encoding); if (w >= 0) /* ignore control characters in the string */ - width += w; + width += w; } return width; diff --git a/lib/uniwidth/u32-width.c b/lib/uniwidth/u32-width.c index f928fa45e..b395f2ee9 100644 --- a/lib/uniwidth/u32-width.c +++ b/lib/uniwidth/u32-width.c @@ -32,11 +32,11 @@ u32_width (const uint32_t *s, size_t n, const char *encoding) int w; if (uc == 0) - break; /* end of string reached */ + break; /* end of string reached */ w = uc_width (uc, encoding); if (w >= 0) /* ignore control characters in the string */ - width += w; + width += w; } return width; diff --git a/lib/uniwidth/u8-width.c b/lib/uniwidth/u8-width.c index ad0d49d80..cd03c464d 100644 --- a/lib/uniwidth/u8-width.c +++ b/lib/uniwidth/u8-width.c @@ -36,11 +36,11 @@ u8_width (const uint8_t *s, size_t n, const char *encoding) s += u8_mbtouc_unsafe (&uc, s, s_end - s); if (uc == 0) - break; /* end of string reached */ + break; /* end of string reached */ w = uc_width (uc, encoding); if (w >= 0) /* ignore control characters in the string */ - width += w; + width += w; } return width; diff --git a/lib/uniwidth/width.c b/lib/uniwidth/width.c index 25ff0c73f..b0660de92 100644 --- a/lib/uniwidth/width.c +++ b/lib/uniwidth/width.c @@ -310,26 +310,26 @@ uc_width (ucs4_t uc, const char *encoding) { 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; - } + 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; - } + { + if (uc <= 0xe01ef) + return 0; + } else - { - if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001) - return 0; - } + { + if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001) + return 0; + } } /* Test for double-width character. * Generated from "grep '^....;[WF]' EastAsianWidth.txt" @@ -337,17 +337,17 @@ uc_width (ucs4_t uc, const char *encoding) */ 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 <= 0x2a6d6) /* CJK */ - || (uc >= 0x2f800 && uc <= 0x2fa1d) /* CJK Compatibility Ideographs */ + || (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 <= 0x2a6d6) /* CJK */ + || (uc >= 0x2f800 && uc <= 0x2fa1d) /* CJK Compatibility Ideographs */ ) ) return 2; /* In ancient CJK encodings, Cyrillic and most other characters are diff --git a/lib/unlink.c b/lib/unlink.c index cd8f4b1a0..558515888 100644 --- a/lib/unlink.c +++ b/lib/unlink.c @@ -38,46 +38,46 @@ rpl_unlink (char const *name) if (len && ISSLASH (name[len - 1])) { /* We can't unlink(2) something if it doesn't exist. If it does - exist, then it resolved to a directory, due to the trailing - slash, and POSIX requires that the unlink attempt to remove - that directory (which would leave the symlink dangling). - Unfortunately, Solaris 9 is one of the platforms where the - root user can unlink directories, and we don't want to - cripple this behavior on real directories, even if it is - seldom needed (at any rate, it's nicer to let coreutils' - unlink(1) give the correct errno for non-root users). But we - don't know whether name was an actual directory, or a symlink - to a directory; and due to the bug of ignoring trailing - slash, Solaris 9 would end up successfully unlinking the - symlink instead of the directory. Technically, we could use - realpath to find the canonical directory name to attempt - deletion on. But that is a lot of work for a corner case; so - we instead just use an lstat on the shortened name, and - reject symlinks with trailing slashes. The root user of - unlink(1) will just have to live with the rule that they - can't delete a directory via a symlink. */ + exist, then it resolved to a directory, due to the trailing + slash, and POSIX requires that the unlink attempt to remove + that directory (which would leave the symlink dangling). + Unfortunately, Solaris 9 is one of the platforms where the + root user can unlink directories, and we don't want to + cripple this behavior on real directories, even if it is + seldom needed (at any rate, it's nicer to let coreutils' + unlink(1) give the correct errno for non-root users). But we + don't know whether name was an actual directory, or a symlink + to a directory; and due to the bug of ignoring trailing + slash, Solaris 9 would end up successfully unlinking the + symlink instead of the directory. Technically, we could use + realpath to find the canonical directory name to attempt + deletion on. But that is a lot of work for a corner case; so + we instead just use an lstat on the shortened name, and + reject symlinks with trailing slashes. The root user of + unlink(1) will just have to live with the rule that they + can't delete a directory via a symlink. */ struct stat st; result = lstat (name, &st); if (result == 0) - { - /* Trailing NUL will overwrite the trailing slash. */ - char *short_name = malloc (len); - if (!short_name) - { - errno = EPERM; - return -1; - } - memcpy (short_name, name, len); - while (len && ISSLASH (short_name[len - 1])) - short_name[--len] = '\0'; - if (len && (lstat (short_name, &st) || S_ISLNK (st.st_mode))) - { - free (short_name); - errno = EPERM; - return -1; - } - free (short_name); - } + { + /* Trailing NUL will overwrite the trailing slash. */ + char *short_name = malloc (len); + if (!short_name) + { + errno = EPERM; + return -1; + } + memcpy (short_name, name, len); + while (len && ISSLASH (short_name[len - 1])) + short_name[--len] = '\0'; + if (len && (lstat (short_name, &st) || S_ISLNK (st.st_mode))) + { + free (short_name); + errno = EPERM; + return -1; + } + free (short_name); + } } if (!result) result = unlink (name); diff --git a/lib/unlinkat.c b/lib/unlinkat.c index 73022529e..308788fd9 100644 --- a/lib/unlinkat.c +++ b/lib/unlinkat.c @@ -48,30 +48,30 @@ rpl_unlinkat (int fd, char const *name, int flag) if (len && ISSLASH (name[len - 1])) { /* See the lengthy comment in unlink.c why we disobey the POSIX - rule of letting unlink("link-to-dir/") attempt to unlink a - directory. */ + rule of letting unlink("link-to-dir/") attempt to unlink a + directory. */ struct stat st; result = lstatat (fd, name, &st); if (result == 0) - { - /* Trailing NUL will overwrite the trailing slash. */ - char *short_name = malloc (len); - if (!short_name) - { - errno = EPERM; - return -1; - } - memcpy (short_name, name, len); - while (len && ISSLASH (short_name[len - 1])) - short_name[--len] = '\0'; - if (len && (lstatat (fd, short_name, &st) || S_ISLNK (st.st_mode))) - { - free (short_name); - errno = EPERM; - return -1; - } - free (short_name); - } + { + /* Trailing NUL will overwrite the trailing slash. */ + char *short_name = malloc (len); + if (!short_name) + { + errno = EPERM; + return -1; + } + memcpy (short_name, name, len); + while (len && ISSLASH (short_name[len - 1])) + short_name[--len] = '\0'; + if (len && (lstatat (fd, short_name, &st) || S_ISLNK (st.st_mode))) + { + free (short_name); + errno = EPERM; + return -1; + } + free (short_name); + } } if (!result) result = unlinkat (fd, name, flag); diff --git a/lib/unlinkdir.c b/lib/unlinkdir.c index a9713c79c..8fd6e2c8d 100644 --- a/lib/unlinkdir.c +++ b/lib/unlinkdir.c @@ -38,8 +38,8 @@ cannot_unlink_dir (void) { # if defined PRIV_SYS_LINKDIR /* We might be able to unlink directories if we cannot - determine our privileges, or if we have the - PRIV_SYS_LINKDIR privilege. */ + determine our privileges, or if we have the + PRIV_SYS_LINKDIR privilege. */ cannot = (priv_set_ismember (PRIV_SYS_LINKDIR) == 0); # else /* In traditional Unix, only root can unlink directories. */ diff --git a/lib/unsetenv.c b/lib/unsetenv.c index 21fb1999d..a2c181acc 100644 --- a/lib/unsetenv.c +++ b/lib/unsetenv.c @@ -28,15 +28,15 @@ #include #if !_LIBC -# define __environ environ +# define __environ environ #endif #if _LIBC /* This lock protects against simultaneous modifications of `environ'. */ # include __libc_lock_define_initialized (static, envlock) -# define LOCK __libc_lock_lock (envlock) -# define UNLOCK __libc_lock_unlock (envlock) +# define LOCK __libc_lock_lock (envlock) +# define UNLOCK __libc_lock_unlock (envlock) #else # define LOCK # define UNLOCK @@ -69,13 +69,13 @@ unsetenv (const char *name) while (*ep != NULL) if (!strncmp (*ep, name, len) && (*ep)[len] == '=') { - /* Found it. Remove this pointer by moving later ones back. */ - char **dp = ep; + /* 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. */ + do + dp[0] = dp[1]; + while (*dp++); + /* Continue the loop in case NAME appears again. */ } else ++ep; diff --git a/lib/userspec.h b/lib/userspec.h index 8a09eaea0..67af8451b 100644 --- a/lib/userspec.h +++ b/lib/userspec.h @@ -5,6 +5,6 @@ const char * parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, - char **username_arg, char **groupname_arg); + char **username_arg, char **groupname_arg); #endif diff --git a/lib/utime.c b/lib/utime.c index 9ddb8b86f..8b18745ba 100644 --- a/lib/utime.c +++ b/lib/utime.c @@ -74,8 +74,8 @@ utime_null (const char *file) || lseek (fd, (off_t) 0, SEEK_SET) < 0 || full_write (fd, &c, sizeof c) != sizeof c /* Maybe do this -- it's necessary on SunOS 4.1.3 with some combination - of patches, but that system doesn't use this code: it has utimes. - || fsync (fd) < 0 + of patches, but that system doesn't use this code: it has utimes. + || fsync (fd) < 0 */ || (st.st_size == 0 && ftruncate (fd, st.st_size) < 0)) { @@ -86,12 +86,12 @@ utime_null (const char *file) if (0 <= fd) { if (close (fd) < 0) - status = -1; + status = -1; /* If there was a prior failure, use the saved errno value. - But if the only failure was in the close, don't change errno. */ + But if the only failure was in the close, don't change errno. */ if (saved_errno) - errno = saved_errno; + errno = saved_errno; } return status; diff --git a/lib/utimecmp.c b/lib/utimecmp.c index 9dcb65294..473e115c1 100644 --- a/lib/utimecmp.c +++ b/lib/utimecmp.c @@ -48,11 +48,11 @@ enum { BILLION = 1000 * 1000 * 1000 }; #if HAVE_UTIMENSAT enum { SYSCALL_RESOLUTION = 1 }; #elif ((HAVE_FUTIMESAT || HAVE_WORKING_UTIMES) \ - && (defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC \ - || defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC \ - || defined HAVE_STRUCT_STAT_ST_ATIMENSEC \ - || defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC \ - || defined HAVE_STRUCT_STAT_ST_SPARE1)) + && (defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC \ + || defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC \ + || defined HAVE_STRUCT_STAT_ST_ATIMENSEC \ + || defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC \ + || defined HAVE_STRUCT_STAT_ST_SPARE1)) enum { SYSCALL_RESOLUTION = 1000 }; #else enum { SYSCALL_RESOLUTION = BILLION }; @@ -116,9 +116,9 @@ dev_info_compare (void const *x, void const *y) int utimecmp (char const *dst_name, - struct stat const *dst_stat, - struct stat const *src_stat, - int options) + struct stat const *dst_stat, + struct stat const *src_stat, + int options) { /* Things to watch out for: @@ -155,194 +155,194 @@ utimecmp (char const *dst_name, int res; /* Quick exit, if possible. Since the worst resolution is 2 - seconds, anything that differs by more than that does not - needs source truncation. */ + seconds, anything that differs by more than that does not + needs source truncation. */ if (dst_s == src_s && dst_ns == src_ns) - return 0; + return 0; if (dst_s <= src_s - 2) - return -1; + return -1; if (src_s <= dst_s - 2) - return 1; + return 1; if (! ht) - ht = hash_initialize (16, NULL, dev_info_hash, dev_info_compare, free); + ht = hash_initialize (16, NULL, dev_info_hash, dev_info_compare, free); if (! new_dst_res) - { - new_dst_res = xmalloc (sizeof *new_dst_res); - new_dst_res->resolution = 2 * BILLION; - new_dst_res->exact = false; - } + { + new_dst_res = xmalloc (sizeof *new_dst_res); + new_dst_res->resolution = 2 * BILLION; + new_dst_res->exact = false; + } new_dst_res->dev = dst_stat->st_dev; dst_res = hash_insert (ht, new_dst_res); if (! dst_res) - xalloc_die (); + xalloc_die (); if (dst_res == new_dst_res) - { - /* NEW_DST_RES is now in use in the hash table, so allocate a - new entry next time. */ - new_dst_res = NULL; - } + { + /* NEW_DST_RES is now in use in the hash table, so allocate a + new entry next time. */ + new_dst_res = NULL; + } res = dst_res->resolution; #ifdef _PC_TIMESTAMP_RESOLUTION - /* If the system will tell us the resolution, we're set! */ + /* If the system will tell us the resolution, we're set! */ if (! dst_res->exact) - { - res = pathconf (dst_name, _PC_TIMESTAMP_RESOLUTION); - if (0 < res) - { - dst_res->resolution = res; - dst_res->exact = true; - } - } + { + res = pathconf (dst_name, _PC_TIMESTAMP_RESOLUTION); + if (0 < res) + { + dst_res->resolution = res; + dst_res->exact = true; + } + } #endif if (! dst_res->exact) - { - /* This file system's resolution is not known exactly. - Deduce it, and store the result in the hash table. */ - - time_t dst_a_s = dst_stat->st_atime; - time_t dst_c_s = dst_stat->st_ctime; - time_t dst_m_s = dst_s; - int dst_a_ns = get_stat_atime_ns (dst_stat); - int dst_c_ns = get_stat_ctime_ns (dst_stat); - int dst_m_ns = dst_ns; - - /* Set RES to an upper bound on the file system resolution - (after truncation due to SYSCALL_RESOLUTION) by inspecting - the atime, ctime and mtime of the existing destination. - We don't know of any file system that stores atime or - ctime with a higher precision than mtime, so it's valid to - look at them too. */ - { - bool odd_second = (dst_a_s | dst_c_s | dst_m_s) & 1; - - if (SYSCALL_RESOLUTION == BILLION) - { - if (odd_second | dst_a_ns | dst_c_ns | dst_m_ns) - res = BILLION; - } - else - { - int a = dst_a_ns; - int c = dst_c_ns; - int m = dst_m_ns; - - /* Write it this way to avoid mistaken GCC warning - about integer overflow in constant expression. */ - int SR10 = SYSCALL_RESOLUTION; SR10 *= 10; - - if ((a % SR10 | c % SR10 | m % SR10) != 0) - res = SYSCALL_RESOLUTION; - else - for (res = SR10, a /= SR10, c /= SR10, m /= SR10; - (res < dst_res->resolution - && (a % 10 | c % 10 | m % 10) == 0); - res *= 10, a /= 10, c /= 10, m /= 10) - if (res == BILLION) - { - if (! odd_second) - res *= 2; - break; - } - } - - dst_res->resolution = res; - } - - if (SYSCALL_RESOLUTION < res) - { - struct timespec timespec[2]; - struct stat dst_status; - - /* Ignore source time stamp information that must necessarily - be lost when filtered through utimens. */ - src_ns -= src_ns % SYSCALL_RESOLUTION; - - /* If the time stamps disagree widely enough, there's no need - to interrogate the file system to deduce the exact time - stamp resolution; return the answer directly. */ - { - time_t s = src_s & ~ (res == 2 * BILLION); - if (src_s < dst_s || (src_s == dst_s && src_ns <= dst_ns)) - return 1; - if (dst_s < s - || (dst_s == s && dst_ns < src_ns - src_ns % res)) - return -1; - } - - /* Determine the actual time stamp resolution for the - destination file system (after truncation due to - SYSCALL_RESOLUTION) by setting the access time stamp of the - destination to the existing access time, except with - trailing nonzero digits. */ - - timespec[0].tv_sec = dst_a_s; - timespec[0].tv_nsec = dst_a_ns; - timespec[1].tv_sec = dst_m_s | (res == 2 * BILLION); - timespec[1].tv_nsec = dst_m_ns + res / 9; - - /* Set the modification time. But don't try to set the - modification time of symbolic links; on many hosts this sets - the time of the pointed-to file. */ - if ((S_ISLNK (dst_stat->st_mode) - ? lutimens (dst_name, timespec) - : utimens (dst_name, timespec)) != 0) - return -2; - - /* Read the modification time that was set. */ - { - int stat_result = (S_ISLNK (dst_stat->st_mode) - ? lstat (dst_name, &dst_status) - : stat (dst_name, &dst_status)); - - if (stat_result - | (dst_status.st_mtime ^ dst_m_s) - | (get_stat_mtime_ns (&dst_status) ^ dst_m_ns)) - { - /* The modification time changed, or we can't tell whether - it changed. Change it back as best we can. */ - timespec[1].tv_sec = dst_m_s; - timespec[1].tv_nsec = dst_m_ns; - if (S_ISLNK (dst_stat->st_mode)) - lutimens (dst_name, timespec); - else - utimens (dst_name, timespec); - } - - if (stat_result != 0) - return -2; - } - - /* Determine the exact resolution from the modification time - that was read back. */ - { - int old_res = res; - int a = (BILLION * (dst_status.st_mtime & 1) - + get_stat_mtime_ns (&dst_status)); - - res = SYSCALL_RESOLUTION; - - for (a /= res; a % 10 != 0; a /= 10) - { - if (res == BILLION) - { - res *= 2; - break; - } - res *= 10; - if (res == old_res) - break; - } - } - } - - dst_res->resolution = res; - dst_res->exact = true; - } + { + /* This file system's resolution is not known exactly. + Deduce it, and store the result in the hash table. */ + + time_t dst_a_s = dst_stat->st_atime; + time_t dst_c_s = dst_stat->st_ctime; + time_t dst_m_s = dst_s; + int dst_a_ns = get_stat_atime_ns (dst_stat); + int dst_c_ns = get_stat_ctime_ns (dst_stat); + int dst_m_ns = dst_ns; + + /* Set RES to an upper bound on the file system resolution + (after truncation due to SYSCALL_RESOLUTION) by inspecting + the atime, ctime and mtime of the existing destination. + We don't know of any file system that stores atime or + ctime with a higher precision than mtime, so it's valid to + look at them too. */ + { + bool odd_second = (dst_a_s | dst_c_s | dst_m_s) & 1; + + if (SYSCALL_RESOLUTION == BILLION) + { + if (odd_second | dst_a_ns | dst_c_ns | dst_m_ns) + res = BILLION; + } + else + { + int a = dst_a_ns; + int c = dst_c_ns; + int m = dst_m_ns; + + /* Write it this way to avoid mistaken GCC warning + about integer overflow in constant expression. */ + int SR10 = SYSCALL_RESOLUTION; SR10 *= 10; + + if ((a % SR10 | c % SR10 | m % SR10) != 0) + res = SYSCALL_RESOLUTION; + else + for (res = SR10, a /= SR10, c /= SR10, m /= SR10; + (res < dst_res->resolution + && (a % 10 | c % 10 | m % 10) == 0); + res *= 10, a /= 10, c /= 10, m /= 10) + if (res == BILLION) + { + if (! odd_second) + res *= 2; + break; + } + } + + dst_res->resolution = res; + } + + if (SYSCALL_RESOLUTION < res) + { + struct timespec timespec[2]; + struct stat dst_status; + + /* Ignore source time stamp information that must necessarily + be lost when filtered through utimens. */ + src_ns -= src_ns % SYSCALL_RESOLUTION; + + /* If the time stamps disagree widely enough, there's no need + to interrogate the file system to deduce the exact time + stamp resolution; return the answer directly. */ + { + time_t s = src_s & ~ (res == 2 * BILLION); + if (src_s < dst_s || (src_s == dst_s && src_ns <= dst_ns)) + return 1; + if (dst_s < s + || (dst_s == s && dst_ns < src_ns - src_ns % res)) + return -1; + } + + /* Determine the actual time stamp resolution for the + destination file system (after truncation due to + SYSCALL_RESOLUTION) by setting the access time stamp of the + destination to the existing access time, except with + trailing nonzero digits. */ + + timespec[0].tv_sec = dst_a_s; + timespec[0].tv_nsec = dst_a_ns; + timespec[1].tv_sec = dst_m_s | (res == 2 * BILLION); + timespec[1].tv_nsec = dst_m_ns + res / 9; + + /* Set the modification time. But don't try to set the + modification time of symbolic links; on many hosts this sets + the time of the pointed-to file. */ + if ((S_ISLNK (dst_stat->st_mode) + ? lutimens (dst_name, timespec) + : utimens (dst_name, timespec)) != 0) + return -2; + + /* Read the modification time that was set. */ + { + int stat_result = (S_ISLNK (dst_stat->st_mode) + ? lstat (dst_name, &dst_status) + : stat (dst_name, &dst_status)); + + if (stat_result + | (dst_status.st_mtime ^ dst_m_s) + | (get_stat_mtime_ns (&dst_status) ^ dst_m_ns)) + { + /* The modification time changed, or we can't tell whether + it changed. Change it back as best we can. */ + timespec[1].tv_sec = dst_m_s; + timespec[1].tv_nsec = dst_m_ns; + if (S_ISLNK (dst_stat->st_mode)) + lutimens (dst_name, timespec); + else + utimens (dst_name, timespec); + } + + if (stat_result != 0) + return -2; + } + + /* Determine the exact resolution from the modification time + that was read back. */ + { + int old_res = res; + int a = (BILLION * (dst_status.st_mtime & 1) + + get_stat_mtime_ns (&dst_status)); + + res = SYSCALL_RESOLUTION; + + for (a /= res; a % 10 != 0; a /= 10) + { + if (res == BILLION) + { + res *= 2; + break; + } + res *= 10; + if (res == old_res) + break; + } + } + } + + dst_res->resolution = res; + dst_res->exact = true; + } /* Truncate the source's time stamp according to the resolution. */ src_s &= ~ (res == 2 * BILLION); @@ -351,7 +351,7 @@ utimecmp (char const *dst_name, /* Compare the time stamps and return -1, 0, 1 accordingly. */ return (dst_s < src_s ? -1 - : dst_s > src_s ? 1 - : dst_ns < src_ns ? -1 - : dst_ns > src_ns); + : dst_s > src_s ? 1 + : dst_ns < src_ns ? -1 + : dst_ns > src_ns); } diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index faffd9ee9..4dda536fc 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -67,13 +67,13 @@ # endif #endif -#include /* localeconv() */ -#include /* snprintf(), sprintf() */ -#include /* abort(), malloc(), realloc(), free() */ -#include /* memcpy(), strlen() */ -#include /* errno */ -#include /* CHAR_BIT */ -#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ +#include /* localeconv() */ +#include /* snprintf(), sprintf() */ +#include /* abort(), malloc(), realloc(), free() */ +#include /* memcpy(), strlen() */ +#include /* errno */ +#include /* CHAR_BIT */ +#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ #if HAVE_NL_LANGINFO # include #endif @@ -364,26 +364,26 @@ multiply (mpn_t src1, mpn_t src2, mpn_t *dest) dlen = len1 + len2; dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); if (dp == NULL) - return NULL; + return NULL; for (k = len2; k > 0; ) - dp[--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; - } + { + 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--; + dlen--; dest->nlimbs = dlen; dest->limbs = dp; } @@ -477,12 +477,12 @@ divide (mpn_t a, mpn_t b, mpn_t *q) for (;;) { if (b_len == 0) - /* Division by zero. */ - abort (); + /* Division by zero. */ + abort (); if (b_ptr[b_len - 1] == 0) - b_len--; + b_len--; else - break; + break; } /* Here m = a_len >= 0 and n = b_len > 0. */ @@ -499,261 +499,261 @@ divide (mpn_t a, mpn_t b, mpn_t *q) else if (b_len == 1) { /* n=1: single precision division. - beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ + 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--; + 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). */ + 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 */ - 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; - } + mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ + 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; + } } /* 0 <= s < GMP_LIMB_BITS. - Copy b, shifting it left by s 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; - } + { + 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] */ + 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; - } + { + 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; - } + { + 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, 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--; - } + 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, 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--; + 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. */ + 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); - } - } + { + 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--; + r_len--; } /* Compare r << 1 with b. */ if (r_len > b_len) @@ -762,17 +762,17 @@ divide (mpn_t a, mpn_t b, mpn_t *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--; + 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)) @@ -781,8 +781,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q) { size_t i; for (i = 0; i < q_len; i++) - if (++(q_ptr[i]) != 0) - goto keep_q; + if (++(q_ptr[i]) != 0) + goto keep_q; q_ptr[q_len++] = 1; } keep_q: @@ -811,36 +811,36 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes) { char *d_ptr = c_ptr; for (; extra_zeroes > 0; extra_zeroes--) - *d_ptr++ = '0'; + *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--; - } + { + /* 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--; + d_ptr--; /* But keep at least one zero. */ if (d_ptr == c_ptr) - *d_ptr++ = '0'; + *d_ptr++ = '0'; /* Terminate the string. */ *d_ptr = '\0'; } @@ -885,12 +885,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -900,7 +900,7 @@ decode_long_double (long double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -912,12 +912,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } #if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess @@ -973,12 +973,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -988,7 +988,7 @@ decode_double (double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -1000,12 +1000,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } if (!(y == 0.0)) @@ -1063,8 +1063,8 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) 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)); + + abs_s / GMP_LIMB_BITS + 1) + * sizeof (mp_limb_t)); if (pow5_ptr == NULL) { free (memory); @@ -1077,26 +1077,26 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int 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 - }; + { + 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; - } + { + 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; @@ -1104,129 +1104,129 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) { /* 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++; - } - } + { + 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; - } + { + 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); - } + { + /* 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); - } + { + /* 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); - } + { + /* 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); - } + { + /* 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); @@ -1298,35 +1298,35 @@ floorlog10l (long double x) 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; - } + { + 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; - } + { + y *= 1.0L * (1 << 16); + exp -= 16; + } if (y < (1.0L / (1 << 8))) - { - y *= 1.0L * (1 << 8); - exp -= 8; - } + { + y *= 1.0L * (1 << 8); + exp -= 8; + } if (y < (1.0L / (1 << 4))) - { - y *= 1.0L * (1 << 4); - exp -= 4; - } + { + y *= 1.0L * (1 << 4); + exp -= 4; + } if (y < (1.0L / (1 << 2))) - { - y *= 1.0L * (1 << 2); - exp -= 2; - } + { + y *= 1.0L * (1 << 2); + exp -= 2; + } if (y < (1.0L / (1 << 1))) - { - y *= 1.0L * (1 << 1); - exp -= 1; - } + { + y *= 1.0L * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5L && y < 1.0L)) abort (); @@ -1389,35 +1389,35 @@ floorlog10 (double x) 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; - } + { + 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; - } + { + y *= 1.0 * (1 << 16); + exp -= 16; + } if (y < (1.0 / (1 << 8))) - { - y *= 1.0 * (1 << 8); - exp -= 8; - } + { + y *= 1.0 * (1 << 8); + exp -= 8; + } if (y < (1.0 / (1 << 4))) - { - y *= 1.0 * (1 << 4); - exp -= 4; - } + { + y *= 1.0 * (1 << 4); + exp -= 4; + } if (y < (1.0 / (1 << 2))) - { - y *= 1.0 * (1 << 2); - exp -= 2; - } + { + y *= 1.0 * (1 << 2); + exp -= 2; + } if (y < (1.0 / (1 << 1))) - { - y *= 1.0 * (1 << 1); - exp -= 1; - } + { + y *= 1.0 * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5 && y < 1.0)) abort (); @@ -1476,7 +1476,7 @@ is_borderline (const char *digits, size_t precision) DCHAR_T * VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, - const FCHAR_T *format, va_list args) + const FCHAR_T *format, va_list args) { DIRECTIVES d; arguments a; @@ -1486,8 +1486,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, return NULL; #define CLEANUP() \ - free (d.dir); \ - if (a.arg) \ + free (d.dir); \ + if (a.arg) \ free (a.arg); if (PRINTF_FETCHARGS (args, &a) < 0) @@ -1516,30 +1516,30 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, #if HAVE_ALLOCA if (buf_neededlength < 4000 / sizeof (TCHAR_T)) { - buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); - buf_malloced = NULL; + 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; + 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; + result = resultbuf; + allocated = *lengthp; } else { - result = NULL; - allocated = 0; + result = NULL; + allocated = 0; } length = 0; /* Invariants: @@ -1549,3881 +1549,3881 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, /* 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; \ + 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 (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; + case TYPE_COUNT_LONGLONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; + break; #endif - default: - abort (); - } - } + 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; - } + /* 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; - } + { + 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; + { /* 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); + /* 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); + /* 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; - } + 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 (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; - } + { + 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; + { /* 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); + /* 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); + /* 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; - } + 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 (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; - } + { + 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; + { /* 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); + /* 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); + /* 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; - } + 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 (); - } - } + 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 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T - else if (dp->conversion == 's' + else if (dp->conversion == 's' # if WIDE_CHAR_VERSION - && a.arg[dp->arg_index].type != TYPE_WIDE_STRING + && a.arg[dp->arg_index].type != TYPE_WIDE_STRING # else - && a.arg[dp->arg_index].type == TYPE_WIDE_STRING + && 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; - } - } + ) + { + /* 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. */ + /* %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)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count; + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + 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 (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)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (;;) - { - int count; + arg_end = arg; + characters = 0; + for (;;) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + 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 (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)); + 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; + 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); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + 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 (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)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - while (arg < arg_end) - { - wchar_t wc; - int count; + while (arg < arg_end) + { + wchar_t wc; + int count; # if HAVE_MBRTOWC - count = mbrtowc (&wc, arg, arg_end - arg, &state); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + 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; - } - } + 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; + /* %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'. */ - typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; - TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; + TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; # endif - size_t w; + size_t w; - if (has_precision) - { - /* Use only as many wide characters as needed to produce - at most PRECISION bytes, from the left. */ + if (has_precision) + { + /* Use only as many wide characters as needed to produce + at most PRECISION bytes, from the left. */ # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (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; + 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 - count = wcrtomb (cbuf, *arg_end, &state); + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (cbuf, *arg_end); + 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 (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 if (has_width) # else - else + else # endif - { - /* Use the entire string, and count the number of - bytes. */ + { + /* Use the entire string, and count the number of + bytes. */ # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (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; + 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 - count = wcrtomb (cbuf, *arg_end, &state); + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (cbuf, *arg_end); + 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 (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; - } + 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; + /* 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 - mbstate_t state; - memset (&state, '\0', sizeof (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; + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; - if (*arg == 0) - abort (); + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + 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); + 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 (has_width) + { # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, characters); + /* Outside POSIX, it's preferrable 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; + /* 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; - } + } + 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 (has_precision || has_width) + { + /* We know the number of bytes in advance. */ + size_t remaining; # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (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 (); + 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 - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + 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 (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (result + length, cbuf, count); + length += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + else + { # if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (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; + while (arg < arg_end) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; - if (*arg == 0) - abort (); + if (*arg == 0) + abort (); # if HAVE_WCRTOMB - count = wcrtomb (cbuf, *arg, &state); + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (cbuf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - ENSURE_ALLOCATION (xsum (length, count)); - memcpy (result + length, cbuf, count); - length += count; - arg++; - } - } + if (count <= 0) + /* Inconsistency. */ + abort (); + 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; + 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; - } - } - } + 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') + else if ((dp->conversion == 'a' || dp->conversion == 'A') # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) - && (0 + && (0 # if NEED_PRINTF_DOUBLE - || a.arg[dp->arg_index].type == TYPE_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE # endif # if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + || 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) - { + ) + { + 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'; + 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++; + { + 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++; - } + 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 (); - } + END_LONG_DOUBLE_ROUNDING (); + } # else - abort (); + abort (); # endif - } - else - { + } + 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'; + 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++; + { + 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++; - } + 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 (); + 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; - } - } + } + /* 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 + 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 + || 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)) + || (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 + || 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)) + || (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; + 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. */ + 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); + 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); + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); # elif NEED_PRINTF_LONG_DOUBLE - tmp_length = LDBL_DIG + 1; + tmp_length = LDBL_DIG + 1; # elif NEED_PRINTF_DOUBLE - tmp_length = DBL_DIG + 1; + tmp_length = DBL_DIG + 1; # else - tmp_length = 0; + tmp_length = 0; # endif - if (tmp_length < precision) - tmp_length = precision; + if (tmp_length < precision) + tmp_length = precision; # if NEED_PRINTF_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) + 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; - } - } + 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) + 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; - } - } + 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); + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); - if (tmp_length < width) - tmp_length = width; + if (tmp_length < width) + tmp_length = width; - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + 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 (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; - } + 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; + 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) + 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 - { + { + 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' */ + 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++; + { + 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++; - } + 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' */ + } + 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++; + { + 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++; - } + 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 (); + 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 (); + /* 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 (); - } - } + END_LONG_DOUBLE_ROUNDING (); + } + } # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - else + 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 - { + { + 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' */ + 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. */ + { + 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' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + 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. */ + { + 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"; + "%+.3d"; # else - "%+.2d"; + "%+.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++; - } - } + 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' */ + } + 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. */ + { + 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' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + 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. */ + { + 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"; + "%+.3d"; # else - "%+.2d"; + "%+.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++; - } - } + 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 (); + 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. */ + /* 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'; + *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 (); + *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; - } - } + /* 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; + else + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int has_width; - size_t width; + int has_width; + size_t width; #endif #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION - int has_precision; - size_t precision; + int has_precision; + size_t precision; #endif #if NEED_PRINTF_UNBOUNDED_PRECISION - int prec_ourselves; + int prec_ourselves; #else -# define prec_ourselves 0 +# define prec_ourselves 0 #endif #if NEED_PRINTF_FLAG_LEFTADJUST -# define pad_ourselves 1 +# define pad_ourselves 1 #elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int pad_ourselves; + int pad_ourselves; #else -# define pad_ourselves 0 +# define pad_ourselves 0 #endif - TCHAR_T *fbp; - unsigned int prefix_count; - int prefixes[2] IF_LINT (= { 0 }); + TCHAR_T *fbp; + unsigned int prefix_count; + int prefixes[2] IF_LINT (= { 0 }); #if !USE_SNPRINTF - size_t tmp_length; - TCHAR_T tmpbuf[700]; - TCHAR_T *tmp; + size_t tmp_length; + TCHAR_T tmpbuf[700]; + TCHAR_T *tmp; #endif #if !USE_SNPRINTF || !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; - } + 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 || 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; - } - } + 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. */ + /* 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; - } + 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. */ + /* 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) - { + 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': + /* 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': + 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; - } + pad_ourselves = 1; + break; + default: + pad_ourselves = prec_ourselves; + break; + } #endif #if !USE_SNPRINTF - /* Allocate a temporary buffer of sufficient size for calling - sprintf. */ - { - switch (dp->conversion) - { + /* Allocate a temporary buffer of sufficient size for calling + sprintf. */ + { + switch (dp->conversion) + { - case 'd': case 'i': case 'u': + 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 + 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 (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 + 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 (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 + 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 (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 + if (type == TYPE_WIDE_CHAR) + tmp_length = MB_CUR_MAX; + else # endif - tmp_length = 1; - break; + tmp_length = 1; + break; - case 's': + case 's': # if HAVE_WCHAR_T - if (type == TYPE_WIDE_STRING) - { + 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 = - a.arg[dp->arg_index].a.a_wide_string; - - if (has_precision) - tmp_length = local_wcsnlen (arg, precision); - else - tmp_length = local_wcslen (arg); + /* 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 = + a.arg[dp->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 above. */ - abort (); + /* 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 above. */ + abort (); # endif - } - else + } + 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 above. */ - abort (); + /* 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 above. */ + 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 = a.arg[dp->arg_index].a.a_string; - - if (has_precision) - tmp_length = local_strnlen (arg, precision); - else - tmp_length = strlen (arg); + /* 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 = a.arg[dp->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) - { + } + 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); + /* 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; + /* 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 */ - } - - 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; - } + } + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + } + + 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++ = '%'; + /* 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. */ + /* 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++ = '\''; + 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 (!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 (flags & FLAG_LEFT) + *fbp++ = '-'; + if (flags & FLAG_SHOWSIGN) + *fbp++ = '+'; + if (flags & FLAG_SPACE) + *fbp++ = ' '; + if (flags & FLAG_ALT) + *fbp++ = '#'; + 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: + case TYPE_LONGLONGINT: + case TYPE_ULONGLONGINT: # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *fbp++ = 'I'; - *fbp++ = '6'; - *fbp++ = '4'; - break; + *fbp++ = 'I'; + *fbp++ = '6'; + *fbp++ = '4'; + break; # else - *fbp++ = 'l'; - /*FALLTHROUGH*/ + *fbp++ = 'l'; + /*FALLTHROUGH*/ # endif #endif - case TYPE_LONGINT: - case TYPE_ULONGINT: + case TYPE_LONGINT: + case TYPE_ULONGINT: #if HAVE_WINT_T - case TYPE_WIDE_CHAR: + case TYPE_WIDE_CHAR: #endif #if HAVE_WCHAR_T - case TYPE_WIDE_STRING: + case TYPE_WIDE_STRING: #endif - *fbp++ = 'l'; - break; - case TYPE_LONGDOUBLE: - *fbp++ = 'L'; - break; - default: - break; - } + *fbp++ = 'l'; + break; + case TYPE_LONGDOUBLE: + *fbp++ = 'L'; + break; + default: + break; + } #if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - *fbp = 'f'; - else + if (dp->conversion == 'F') + *fbp = 'f'; + else #endif - *fbp = dp->conversion; + *fbp = dp->conversion; #if USE_SNPRINTF # if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) - fbp[1] = '%'; - fbp[2] = 'n'; - fbp[3] = '\0'; + 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 returns value conforms to - ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. - 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 Win32 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 Win32 systems (such as mingw) where the OS is - Windows Vista, the use of %n in format strings by default - crashes the program. See - and - - So we should avoid %n in this situation. */ - fbp[1] = '\0'; + /* On glibc2 systems from glibc >= 2.3 - probably also older + ones - we know that snprintf's returns value conforms to + ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. + 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 Win32 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 Win32 systems (such as mingw) where the OS is + Windows Vista, the use of %n in format strings by default + crashes the program. See + and + + So we should avoid %n in this situation. */ + fbp[1] = '\0'; # endif #else - fbp[1] = '\0'; + 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; - } + /* 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). */ + /* 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'; + /* 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 - for (;;) - { - int count = -1; + 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; + 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 (); \ - } + 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 (); \ - } + 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 - 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; + 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; + 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; + 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; + 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; + 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; + 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 (); - } + 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) - { - /* 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. */ - size_t bigger_need = - xsum (xtimes (allocated, 2), 12); - ENSURE_ALLOCATION (bigger_need); - continue; - } - else - count = retcount; - } - } + /* 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) + { + /* 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. */ + size_t bigger_need = + xsum (xtimes (allocated, 2), 12); + ENSURE_ALLOCATION (bigger_need); + continue; + } + else + count = retcount; + } + } #endif - /* Attempt to handle failure. */ - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EINVAL; - return NULL; - } + /* Attempt to handle failure. */ + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = 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; - } - } + /* 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 (prec_ourselves) + { + /* Handle the precision. */ + TCHAR_T *prec_ptr = # if USE_SNPRINTF - (TCHAR_T *) (result + length); + (TCHAR_T *) (result + length); # else - tmp; + 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; + 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); + 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; + prec_end = prec_ptr + count; + prec_ptr += prefix_count; - while (prec_end > prec_ptr) - { - prec_end--; - prec_end[insert] = prec_end[0]; - } + 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); + prec_end += insert; + do + *--prec_end = '0'; + while (prec_end > prec_ptr); - count += insert; - } - } + count += insert; + } + } #endif #if !USE_SNPRINTF - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); + 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'. */ - typedef int TCHAR_T_verify - [2 * (sizeof (TCHAR_T) == 1) - 1]; + /* 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'. */ + typedef int TCHAR_T_verify + [2 * (sizeof (TCHAR_T) == 1) - 1]; # if USE_SNPRINTF - tmpsrc = (TCHAR_T *) (result + length); + tmpsrc = (TCHAR_T *) (result + length); # else - tmpsrc = tmp; + 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. */ + 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)) + /* 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; + { + 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); - } + 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)); + 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; - } - } + 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); - } + /* 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. */ + /* Here count <= allocated - length. */ - /* Perform padding. */ + /* 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 (pad_ourselves && has_width) + { + size_t w; # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, count); + /* Outside POSIX, it's preferrable 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; + /* 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 (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; + length += count; + ENSURE_ALLOCATION (n); + length -= count; # else - ENSURE_ALLOCATION (n); + ENSURE_ALLOCATION (n); # endif - } - /* Here count + pad <= allocated - length. */ + } + /* Here count + pad <= allocated - length. */ - { + { # if !DCHAR_IS_TCHAR || USE_SNPRINTF - DCHAR_T * const rp = result + length; + DCHAR_T * const rp = result + length; # else - DCHAR_T * const rp = tmp; + DCHAR_T * const rp = tmp; # endif - DCHAR_T *p = rp + count; - DCHAR_T *end = p + pad; - DCHAR_T *pad_ptr; + 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 + 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++ = ' '; - } - } - } - } + { + 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. */ + /* Here still count <= allocated - length. */ #if !DCHAR_IS_TCHAR || USE_SNPRINTF - /* The snprintf() result did fit. */ + /* The snprintf() result did fit. */ #else - /* Append the sprintf() result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + /* Append the sprintf() result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); #endif #if !USE_SNPRINTF - if (tmp != tmpbuf) - free (tmp); + 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'; - } + 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; - } - } - } + length += count; + break; + } + } + } } /* Add the final NUL. */ @@ -5432,12 +5432,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, if (result != resultbuf && length + 1 < allocated) { - /* Shrink the allocated memory if possible. */ - DCHAR_T *memory; + /* Shrink the allocated memory if possible. */ + DCHAR_T *memory; - memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); - if (memory != NULL) - result = memory; + memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); + if (memory != NULL) + result = memory; } if (buf_malloced != NULL) diff --git a/lib/vdprintf.c b/lib/vdprintf.c index 37512ed74..2b0da8a28 100644 --- a/lib/vdprintf.c +++ b/lib/vdprintf.c @@ -46,11 +46,11 @@ vdprintf (int fd, const char *format, va_list args) if (full_write (fd, output, len) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/verify.h b/lib/verify.h index fac53f6fc..3fbb63935 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -110,8 +110,8 @@ #if 4 <= __GNUC__ # define verify(R) \ - extern int (* verify_function__ (void)) \ - [__builtin_constant_p (R) && (R) ? 1 : -1] + extern int (* verify_function__ (void)) \ + [__builtin_constant_p (R) && (R) ? 1 : -1] #endif * In C++, any struct definition inside sizeof is invalid. diff --git a/lib/verror.c b/lib/verror.c index 0a7981ea2..9535ce76a 100644 --- a/lib/verror.c +++ b/lib/verror.c @@ -59,8 +59,8 @@ verror_at_line (int status, int errnum, const char *file, 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. */ + 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 diff --git a/lib/version-etc.c b/lib/version-etc.c index d76aa7c4d..abd5dbdf4 100644 --- a/lib/version-etc.c +++ b/lib/version-etc.c @@ -60,9 +60,9 @@ enum { COPYRIGHT_YEAR = 2009 }; 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) + 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); @@ -72,7 +72,7 @@ version_etc_arn (FILE *stream, #ifdef PACKAGE_PACKAGER # ifdef PACKAGE_PACKAGER_VERSION fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER, - PACKAGE_PACKAGER_VERSION); + PACKAGE_PACKAGER_VERSION); # else fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER); # endif @@ -90,7 +90,7 @@ 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); + stream); switch (n_authors) { @@ -108,66 +108,66 @@ There is NO WARRANTY, to the extent permitted by law.\n\ case 3: /* TRANSLATORS: Each %s denotes an author name. */ fprintf (stream, _("Written by %s, %s, and %s.\n"), - authors[0], authors[1], authors[2]); + 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. */ + 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]); + 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. */ + 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]); + 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. */ + 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]); + 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. */ + 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]); + 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. */ + 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]); + 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. */ + 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]); + 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. */ + 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. */ + 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]); + authors[0], authors[1], authors[2], authors[3], authors[4], + authors[5], authors[6], authors[7], authors[8]); break; } } @@ -178,8 +178,8 @@ Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"), 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) + const char *command_name, const char *package, + const char *version, const char * const * authors) { size_t n_authors; @@ -194,19 +194,19 @@ version_etc_ar (FILE *stream, 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) + 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; + && (authtab[n_authors] = va_arg (authors, const char *)) != NULL; n_authors++) ; version_etc_arn (stream, command_name, package, version, - authtab, n_authors); + authtab, n_authors); } @@ -225,8 +225,8 @@ version_etc_va (FILE *stream, NULL argument at the end. */ void version_etc (FILE *stream, - const char *command_name, const char *package, - const char *version, /* const char *author1, ...*/ ...) + const char *command_name, const char *package, + const char *version, /* const char *author1, ...*/ ...) { va_list authors; @@ -245,14 +245,14 @@ emit_bug_reporting_address (void) 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); + PACKAGE_PACKAGER_BUG_REPORTS); #endif #ifdef PACKAGE_URL printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL); #else printf (_("%s home page: \n"), - PACKAGE_NAME, PACKAGE); + PACKAGE_NAME, PACKAGE); #endif fputs (_("General help using GNU software: \n"), - stdout); + stdout); } diff --git a/lib/version-etc.h b/lib/version-etc.h index 8ce02fecb..75cd4b81b 100644 --- a/lib/version-etc.h +++ b/lib/version-etc.h @@ -50,26 +50,26 @@ extern const char version_etc_copyright[]; /* 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); + 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); + 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); + 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 */ ...) + const char *command_name, const char *package, + const char *version, + /* const char *author1, ..., NULL */ ...) ATTRIBUTE_SENTINEL; /* Display the usual `Report bugs to' stanza */ diff --git a/lib/vfprintf.c b/lib/vfprintf.c index b240b0d98..6e3d595f8 100644 --- a/lib/vfprintf.c +++ b/lib/vfprintf.c @@ -52,11 +52,11 @@ vfprintf (FILE *fp, const char *format, va_list args) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/vsnprintf.c b/lib/vsnprintf.c index 043999d35..08b607819 100644 --- a/lib/vsnprintf.c +++ b/lib/vsnprintf.c @@ -52,11 +52,11 @@ vsnprintf (char *str, size_t size, const char *format, va_list args) if (output != str) { if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } free (output); } diff --git a/lib/w32spawn.h b/lib/w32spawn.h index 693b11970..10efd0a26 100644 --- a/lib/w32spawn.h +++ b/lib/w32spawn.h @@ -79,13 +79,13 @@ undup_safer_noinherit (int tempfd, int origfd) { if (dup2 (tempfd, origfd) < 0) error (EXIT_FAILURE, errno, _("cannot restore fd %d: dup2 failed"), - origfd); + 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. */ + state. This is (nearly) equivalent to the original state. */ close (origfd); } } @@ -143,68 +143,68 @@ prepare_spawn (char **argv) const char *string = argv[i]; if (string[0] == '\0') - new_argv[i] = xstrdup ("\"\""); + 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; - } + { + 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[i] = (char *) string; } new_argv[argc] = NULL; diff --git a/lib/wait-process.c b/lib/wait-process.c index cf55ec19e..aec560392 100644 --- a/lib/wait-process.c +++ b/lib/wait-process.c @@ -88,17 +88,17 @@ cleanup_slaves (void) /* Get the last registered slave. */ size_t n = slaves_count; if (n == 0) - break; + break; n--; slaves_count = n; /* Skip unused entries in the slaves array. */ if (slaves[n].used) - { - pid_t slave = slaves[n].child; + { + pid_t slave = slaves[n].child; - /* Kill the slave. */ - kill (slave, TERMINATOR); - } + /* Kill the slave. */ + kill (slave, TERMINATOR); + } } } @@ -124,42 +124,42 @@ register_slave_subprocess (pid_t child) 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; - } + { + /* 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. */ + 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)); + (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 (); - } + { + /* 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_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); + 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 @@ -191,9 +191,9 @@ unregister_slave_subprocess (pid_t child) 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) + 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 @@ -212,24 +212,24 @@ wait_subprocess (pid_t child, const char *progname, for (;;) { if (waitid (P_PID, child, &info, WEXITED | (slave_process ? WNOWAIT : 0)) - < 0) - { + < 0) + { # ifdef EINTR - if (errno == EINTR) - continue; + if (errno == EINTR) + continue; # endif - if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, errno, - _("%s subprocess"), progname); - return 127; - } + 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. */ + 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; + || info.si_code == CLD_KILLED || info.si_code == CLD_DUMPED) + break; } /* The child process has exited or was signalled. */ @@ -237,26 +237,26 @@ wait_subprocess (pid_t child, const char *progname, 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. */ + 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) - { + { + if (waitid (P_PID, child, &info, WEXITED) < 0) + { # ifdef EINTR - if (errno == EINTR) - continue; + 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; - } + if (exit_on_error || !null_stderr) + error (exit_on_error ? EXIT_FAILURE : 0, errno, + _("%s subprocess"), progname); + return 127; + } + break; + } } switch (info.si_code) @@ -264,24 +264,24 @@ wait_subprocess (pid_t child, const char *progname, case CLD_KILLED: case CLD_DUMPED: if (termsigp != NULL) - *termsigp = info.si_status; /* TODO: or info.si_signo? */ + *termsigp = info.si_status; /* TODO: or info.si_signo? */ # ifdef SIGPIPE if (info.si_status == SIGPIPE && ignore_sigpipe) - return 0; + 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); + 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; - } + { + 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 (); @@ -298,31 +298,31 @@ wait_subprocess (pid_t child, const char *progname, int result = waitpid (child, &status, 0); if (result != child) - { + { # ifdef EINTR - if (errno == EINTR) - continue; + if (errno == EINTR) + continue; # endif # if 0 /* defined ECHILD */ - if (errno == ECHILD) - { - /* Child process nonexistent?! Assume it terminated - successfully. */ - status = 0; - break; - } + 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; - } + 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. */ + must always be true, since we did not specify WCONTINUED in the + waitpid() call. Loop until the program terminates. */ if (!WIFSTOPPED (status)) - break; + break; } /* The child process has exited or was signalled. */ @@ -336,15 +336,15 @@ wait_subprocess (pid_t child, const char *progname, if (WIFSIGNALED (status)) { if (termsigp != NULL) - *termsigp = WTERMSIG (status); + *termsigp = WTERMSIG (status); # ifdef SIGPIPE if (WTERMSIG (status) == SIGPIPE && ignore_sigpipe) - return 0; + 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)); + error (exit_on_error ? EXIT_FAILURE : 0, 0, + _("%s subprocess got fatal signal %d"), + progname, (int) WTERMSIG (status)); return 127; } if (!WIFEXITED (status)) @@ -352,8 +352,8 @@ wait_subprocess (pid_t child, const char *progname, if (WEXITSTATUS (status) == 127) { if (exit_on_error || !null_stderr) - error (exit_on_error ? EXIT_FAILURE : 0, 0, - _("%s subprocess failed"), progname); + error (exit_on_error ? EXIT_FAILURE : 0, 0, + _("%s subprocess failed"), progname); return 127; } return WEXITSTATUS (status); diff --git a/lib/wait-process.h b/lib/wait-process.h index cb24fd71d..34e98c71b 100644 --- a/lib/wait-process.h +++ b/lib/wait-process.h @@ -55,9 +55,9 @@ extern "C" { 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); + 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 diff --git a/lib/wcrtomb.c b/lib/wcrtomb.c index 79df99f23..a8ab16dd0 100644 --- a/lib/wcrtomb.c +++ b/lib/wcrtomb.c @@ -43,11 +43,11 @@ wcrtomb (char *s, wchar_t wc, mbstate_t *ps) int ret = wctomb (s, wc); if (ret >= 0) - return ret; + return ret; else - { - errno = EILSEQ; - return (size_t)(-1); - } + { + errno = EILSEQ; + return (size_t)(-1); + } } } diff --git a/lib/wcsnrtombs.c b/lib/wcsnrtombs.c index 23eebc510..0e8e419b2 100644 --- a/lib/wcsnrtombs.c +++ b/lib/wcsnrtombs.c @@ -42,55 +42,55 @@ wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate if (dest != NULL) { - char *destptr = dest; - - for (; srclen > 0 && len > 0; src++, srclen--) - { - wchar_t wc = *src; - size_t ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps); - - if (ret == (size_t)(-1)) - goto bad_input; - if (!(ret <= cur_max)) - abort (); - if (len < ret) - break; - if (len < cur_max) - memcpy (destptr, buf, ret); - if (wc == 0) - { - src = NULL; - /* Here mbsinit (ps). */ - break; - } - destptr += ret; - len -= ret; - } - *srcp = src; - return destptr - dest; + char *destptr = dest; + + for (; srclen > 0 && len > 0; src++, srclen--) + { + wchar_t wc = *src; + size_t ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps); + + if (ret == (size_t)(-1)) + goto bad_input; + if (!(ret <= cur_max)) + abort (); + if (len < ret) + break; + if (len < cur_max) + memcpy (destptr, buf, ret); + if (wc == 0) + { + src = NULL; + /* Here mbsinit (ps). */ + break; + } + destptr += ret; + len -= ret; + } + *srcp = src; + return destptr - dest; } else { - /* Ignore dest and len, don't store *srcp at the end, and - don't clobber *ps. */ - mbstate_t state = *ps; - size_t totalcount = 0; - - for (; srclen > 0; src++, srclen--) - { - wchar_t wc = *src; - size_t ret = wcrtomb (buf, wc, &state); - - if (ret == (size_t)(-1)) - goto bad_input2; - if (wc == 0) - { - /* Here mbsinit (&state). */ - break; - } - totalcount += ret; - } - return totalcount; + /* Ignore dest and len, don't store *srcp at the end, and + don't clobber *ps. */ + mbstate_t state = *ps; + size_t totalcount = 0; + + for (; srclen > 0; src++, srclen--) + { + wchar_t wc = *src; + size_t ret = wcrtomb (buf, wc, &state); + + if (ret == (size_t)(-1)) + goto bad_input2; + if (wc == 0) + { + /* Here mbsinit (&state). */ + break; + } + totalcount += ret; + } + return totalcount; } bad_input: diff --git a/lib/wcsrtombs.c b/lib/wcsrtombs.c index 5abbac481..49f50ec33 100644 --- a/lib/wcsrtombs.c +++ b/lib/wcsrtombs.c @@ -66,55 +66,55 @@ wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) if (dest != NULL) { - char *destptr = dest; - - for (; len > 0; src++) - { - wchar_t wc = *src; - size_t ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps); - - if (ret == (size_t)(-1)) - goto bad_input; - if (!(ret <= cur_max)) - abort (); - if (len < ret) - break; - if (len < cur_max) - memcpy (destptr, buf, ret); - if (wc == 0) - { - src = NULL; - /* Here mbsinit (ps). */ - break; - } - destptr += ret; - len -= ret; - } - *srcp = src; - return destptr - dest; + char *destptr = dest; + + for (; len > 0; src++) + { + wchar_t wc = *src; + size_t ret = wcrtomb (len >= cur_max ? destptr : buf, wc, ps); + + if (ret == (size_t)(-1)) + goto bad_input; + if (!(ret <= cur_max)) + abort (); + if (len < ret) + break; + if (len < cur_max) + memcpy (destptr, buf, ret); + if (wc == 0) + { + src = NULL; + /* Here mbsinit (ps). */ + break; + } + destptr += ret; + len -= ret; + } + *srcp = src; + return destptr - dest; } else { - /* Ignore dest and len, don't store *srcp at the end, and - don't clobber *ps. */ - mbstate_t state = *ps; - size_t totalcount = 0; - - for (;; src++) - { - wchar_t wc = *src; - size_t ret = wcrtomb (buf, wc, &state); - - if (ret == (size_t)(-1)) - goto bad_input2; - if (wc == 0) - { - /* Here mbsinit (&state). */ - break; - } - totalcount += ret; - } - return totalcount; + /* Ignore dest and len, don't store *srcp at the end, and + don't clobber *ps. */ + mbstate_t state = *ps; + size_t totalcount = 0; + + for (;; src++) + { + wchar_t wc = *src; + size_t ret = wcrtomb (buf, wc, &state); + + if (ret == (size_t)(-1)) + goto bad_input2; + if (wc == 0) + { + /* Here mbsinit (&state). */ + break; + } + totalcount += ret; + } + return totalcount; } bad_input: diff --git a/lib/wctype.in.h b/lib/wctype.in.h index 835185f46..4bae6d0ca 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -109,7 +109,7 @@ static inline int iswalnum (wint_t wc) { return ((wc >= '0' && wc <= '9') - || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); } static inline int @@ -158,15 +158,15 @@ static inline int iswpunct (wint_t wc) { return (wc >= '!' && wc <= '~' - && !((wc >= '0' && wc <= '9') - || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); + && !((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); } static inline int iswspace (wint_t wc) { return (wc == ' ' || wc == '\t' - || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); + || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); } static inline int @@ -179,7 +179,7 @@ static inline int iswxdigit (wint_t wc) { return ((wc >= '0' && wc <= '9') - || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); } static inline wint_t diff --git a/lib/wcwidth.c b/lib/wcwidth.c index 4885071d0..63e196a3b 100644 --- a/lib/wcwidth.c +++ b/lib/wcwidth.c @@ -36,7 +36,7 @@ rpl_wcwidth (wchar_t wc) if (STREQ (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. */ + Unicode character. */ return uc_width (wc, encoding); } else diff --git a/lib/write.c b/lib/write.c index 5f0131d17..24cc25c83 100644 --- a/lib/write.c +++ b/lib/write.c @@ -46,14 +46,14 @@ rpl_write (int fd, const void *buf, size_t count) if (ret < 0) { if (GetLastError () == ERROR_NO_DATA - && 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; - } + && 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; + } } return ret; } diff --git a/lib/xalloc.h b/lib/xalloc.h index 57a13e0af..f8fef8ac6 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -161,9 +161,9 @@ xnrealloc (void *p, size_t n, size_t s) void append_int (int value) { - if (used == allocated) - p = x2nrealloc (p, &allocated, sizeof *p); - p[used++] = 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 @@ -181,12 +181,12 @@ xnrealloc (void *p, size_t n, size_t s) void append_int (int value) { - if (used == allocated) - { - p = x2nrealloc (p, &allocated1, sizeof *p); - allocated = allocated1; - } - p[used++] = value; + if (used == allocated) + { + p = x2nrealloc (p, &allocated1, sizeof *p); + allocated = allocated1; + } + p[used++] = value; } */ @@ -199,25 +199,25 @@ x2nrealloc (void *p, size_t *pn, size_t s) if (! p) { if (! n) - { - /* The approximate size to use for initial small allocation - requests, when the invoking code specifies an old size of - zero. 64 bytes is the largest "small" request for the - GNU C library malloc. */ - enum { DEFAULT_MXFAST = 64 }; - - n = DEFAULT_MXFAST / s; - n += !n; - } + { + /* The approximate size to use for initial small allocation + requests, when the invoking code specifies an old size of + zero. 64 bytes is the largest "small" request for the + GNU C library malloc. */ + enum { DEFAULT_MXFAST = 64 }; + + 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. */ + 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 (); + xalloc_die (); n += (n + 1) / 2; } diff --git a/lib/xconcat-filename.c b/lib/xconcat-filename.c index 2726036a0..c4a340d83 100644 --- a/lib/xconcat-filename.c +++ b/lib/xconcat-filename.c @@ -29,7 +29,7 @@ Return a freshly allocated filename. */ char * xconcatenated_filename (const char *directory, const char *filename, - const char *suffix) + const char *suffix) { char *result; diff --git a/lib/xgetdomainname.c b/lib/xgetdomainname.c index 1d557d65b..aa764f2f4 100644 --- a/lib/xgetdomainname.c +++ b/lib/xgetdomainname.c @@ -61,14 +61,14 @@ xgetdomainname (void) domainname[k] = '\0'; err = getdomainname (domainname, size); if (err >= 0 && domainname[k] == '\0') - break; + break; else if (err < 0 && errno != EINVAL) - { - int saved_errno = errno; - free (domainname); - errno = saved_errno; - return NULL; - } + { + int saved_errno = errno; + free (domainname); + errno = saved_errno; + return NULL; + } size *= 2; domainname = xrealloc (domainname, size); } diff --git a/lib/xgethostname.c b/lib/xgethostname.c index d649b8dcf..136acbeac 100644 --- a/lib/xgethostname.c +++ b/lib/xgethostname.c @@ -45,8 +45,8 @@ xgethostname (void) while (1) { /* Use SIZE_1 here rather than SIZE to work around the bug in - SunOS 5.5's gethostname whereby it NUL-terminates HOSTNAME - even when the name is as long as the supplied buffer. */ + SunOS 5.5's gethostname whereby it NUL-terminates HOSTNAME + even when the name is as long as the supplied buffer. */ size_t size_1; hostname = x2realloc (hostname, &size); @@ -55,19 +55,19 @@ xgethostname (void) errno = 0; if (gethostname (hostname, size_1) == 0) - { - if (! hostname[size_1 - 1]) - break; - } + { + if (! hostname[size_1 - 1]) + break; + } else if (errno != 0 && errno != ENAMETOOLONG && errno != EINVAL - /* OSX/Darwin does this when the buffer is not large enough */ - && errno != ENOMEM) - { - int saved_errno = errno; - free (hostname); - errno = saved_errno; - return NULL; - } + /* OSX/Darwin does this when the buffer is not large enough */ + && errno != ENOMEM) + { + int saved_errno = errno; + free (hostname); + errno = saved_errno; + return NULL; + } } return hostname; diff --git a/lib/xmalloca.h b/lib/xmalloca.h index bd4c5a917..eab60b244 100644 --- a/lib/xmalloca.h +++ b/lib/xmalloca.h @@ -32,7 +32,7 @@ extern "C" { the function returns. Upon failure, it exits with an error message. */ #if HAVE_ALLOCA # define xmalloca(N) \ - ((N) < 4032 - sa_increment \ + ((N) < 4032 - sa_increment \ ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \ : xmmalloca (N)) extern void * xmmalloca (size_t n); diff --git a/lib/xmemcoll.c b/lib/xmemcoll.c index 393e6d50a..0a8455324 100644 --- a/lib/xmemcoll.c +++ b/lib/xmemcoll.c @@ -48,9 +48,9 @@ xmemcoll (char *s1, size_t s1len, char *s2, size_t s2len) error (0, collation_errno, _("string comparison failed")); error (0, 0, _("Set LC_ALL='C' to work around the problem.")); error (exit_failure, 0, - _("The strings compared were %s and %s."), - quotearg_n_style_mem (0, locale_quoting_style, s1, s1len), - quotearg_n_style_mem (1, locale_quoting_style, s2, s2len)); + _("The strings compared were %s and %s."), + quotearg_n_style_mem (0, locale_quoting_style, s1, s1len), + quotearg_n_style_mem (1, locale_quoting_style, s2, s2len)); } return diff; diff --git a/lib/xnanosleep.c b/lib/xnanosleep.c index 1c7de6241..64bc7d29a 100644 --- a/lib/xnanosleep.c +++ b/lib/xnanosleep.c @@ -57,10 +57,10 @@ xnanosleep (double seconds) in some rare (perhaps theoretical) cases but that is better than undefined behavior. */ bool overflow = ((time_t) ((double) TIME_T_MAX / 2) == TIME_T_MAX / 2 - ? TIME_T_MAX < seconds - : (time_t) ((long double) TIME_T_MAX / 2) == TIME_T_MAX / 2 - ? TIME_T_MAX < (long double) seconds - : TIME_T_MAX <= (long double) seconds); + ? TIME_T_MAX < seconds + : (time_t) ((long double) TIME_T_MAX / 2) == TIME_T_MAX / 2 + ? TIME_T_MAX < (long double) seconds + : TIME_T_MAX <= (long double) seconds); struct timespec ts_sleep; @@ -74,45 +74,45 @@ xnanosleep (double seconds) ts_sleep.tv_sec = floor_seconds; /* Round up to the next whole number, if necessary, so that we - always sleep for at least the requested amount of time. Assuming - the default rounding mode, we don't have to worry about the - rounding error when computing 'ns' above, since the error won't - cause 'ns' to drop below an integer boundary. */ + always sleep for at least the requested amount of time. Assuming + the default rounding mode, we don't have to worry about the + rounding error when computing 'ns' above, since the error won't + cause 'ns' to drop below an integer boundary. */ ts_sleep.tv_nsec = ns; ts_sleep.tv_nsec += (ts_sleep.tv_nsec < ns); /* Normalize the interval length. nanosleep requires this. */ if (BILLION <= ts_sleep.tv_nsec) - { - if (ts_sleep.tv_sec == TIME_T_MAX) - overflow = true; - else - { - ts_sleep.tv_sec++; - ts_sleep.tv_nsec -= BILLION; - } - } + { + if (ts_sleep.tv_sec == TIME_T_MAX) + overflow = true; + else + { + ts_sleep.tv_sec++; + ts_sleep.tv_nsec -= BILLION; + } + } } for (;;) { if (overflow) - { - ts_sleep.tv_sec = TIME_T_MAX; - ts_sleep.tv_nsec = BILLION - 1; - } + { + ts_sleep.tv_sec = TIME_T_MAX; + ts_sleep.tv_nsec = BILLION - 1; + } /* Linux-2.6.8.1's nanosleep returns -1, but doesn't set errno - when resumed after being suspended. Earlier versions would - set errno to EINTR. nanosleep from linux-2.6.10, as well as - implementations by (all?) other vendors, doesn't return -1 - in that case; either it continues sleeping (if time remains) - or it returns zero (if the wake-up time has passed). */ + when resumed after being suspended. Earlier versions would + set errno to EINTR. nanosleep from linux-2.6.10, as well as + implementations by (all?) other vendors, doesn't return -1 + in that case; either it continues sleeping (if time remains) + or it returns zero (if the wake-up time has passed). */ errno = 0; if (nanosleep (&ts_sleep, NULL) == 0) - break; + break; if (errno != EINTR && errno != 0) - return -1; + return -1; } return 0; diff --git a/lib/xprintf.h b/lib/xprintf.h index d11e270e9..a26157d2b 100644 --- a/lib/xprintf.h +++ b/lib/xprintf.h @@ -23,7 +23,7 @@ #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) -# define __attribute__(Spec) /* empty */ +# define __attribute__(Spec) /* empty */ # endif /* The __-protected variants of `format' and `printf' attributes are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ @@ -40,7 +40,7 @@ extern int xvprintf (char const *restrict format, va_list args) extern int xfprintf (FILE *restrict stream, char const *restrict format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); extern int xvfprintf (FILE *restrict stream, char const *restrict format, - va_list args) + va_list args) __attribute__ ((__format__ (__printf__, 2, 0))); #endif diff --git a/lib/xstriconv.c b/lib/xstriconv.c index 14d8775cb..2fc7d24ad 100644 --- a/lib/xstriconv.c +++ b/lib/xstriconv.c @@ -30,7 +30,7 @@ int xmem_cd_iconv (const char *src, size_t srclen, iconv_t cd, - char **resultp, size_t *lengthp) + char **resultp, size_t *lengthp) { int retval = mem_cd_iconv (src, srclen, cd, resultp, lengthp); diff --git a/lib/xstriconv.h b/lib/xstriconv.h index a8a197102..437459d82 100644 --- a/lib/xstriconv.h +++ b/lib/xstriconv.h @@ -43,7 +43,7 @@ extern "C" { in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is unchanged if no dynamic memory allocation was necessary. */ extern int xmem_cd_iconv (const char *src, size_t srclen, iconv_t cd, - char **resultp, size_t *lengthp); + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -67,7 +67,7 @@ extern char * xstr_cd_iconv (const char *src, iconv_t cd); Return value: the freshly allocated resulting NUL-terminated string if successful, otherwise NULL and errno set. */ extern char * xstr_iconv (const char *src, - const char *from_codeset, const char *to_codeset); + const char *from_codeset, const char *to_codeset); #ifdef __cplusplus diff --git a/lib/xstriconveh.c b/lib/xstriconveh.c index 46f850c13..cda0c4f76 100644 --- a/lib/xstriconveh.c +++ b/lib/xstriconveh.c @@ -30,10 +30,10 @@ int xmem_cd_iconveh (const char *src, size_t srclen, - const iconveh_t *cd, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const iconveh_t *cd, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { int retval = mem_cd_iconveh (src, srclen, cd, handler, offsets, resultp, lengthp); @@ -45,8 +45,8 @@ xmem_cd_iconveh (const char *src, size_t srclen, char * xstr_cd_iconveh (const char *src, - const iconveh_t *cd, - enum iconv_ilseq_handler handler) + const iconveh_t *cd, + enum iconv_ilseq_handler handler) { char *result = str_cd_iconveh (src, cd, handler); @@ -59,14 +59,14 @@ xstr_cd_iconveh (const char *src, int xmem_iconveh (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { int retval = mem_iconveh (src, srclen, from_codeset, to_codeset, handler, offsets, - resultp, lengthp); + resultp, lengthp); if (retval < 0 && errno == ENOMEM) xalloc_die (); @@ -75,8 +75,8 @@ xmem_iconveh (const char *src, size_t srclen, char * xstr_iconveh (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler) { char *result = str_iconveh (src, from_codeset, to_codeset, handler); diff --git a/lib/xstriconveh.h b/lib/xstriconveh.h index e4b0bf878..5f188aba5 100644 --- a/lib/xstriconveh.h +++ b/lib/xstriconveh.h @@ -50,10 +50,10 @@ extern "C" { unchanged if no dynamic memory allocation was necessary. */ extern int xmem_cd_iconveh (const char *src, size_t srclen, - const iconveh_t *cd, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const iconveh_t *cd, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -67,8 +67,8 @@ extern int successful, otherwise NULL and errno set. */ extern char * xstr_cd_iconveh (const char *src, - const iconveh_t *cd, - enum iconv_ilseq_handler handler); + const iconveh_t *cd, + enum iconv_ilseq_handler handler); #endif @@ -88,10 +88,10 @@ extern char * unchanged if no dynamic memory allocation was necessary. */ extern int xmem_iconveh (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -103,8 +103,8 @@ extern int successful, otherwise NULL and errno set. */ extern char * xstr_iconveh (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler); + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler); #ifdef __cplusplus diff --git a/lib/xstrtod.c b/lib/xstrtod.c index 8b4a72c8b..c55c05b27 100644 --- a/lib/xstrtod.c +++ b/lib/xstrtod.c @@ -43,7 +43,7 @@ bool XSTRTOD (char const *str, char const **ptr, DOUBLE *result, - DOUBLE (*convert) (char const *, char **)) + DOUBLE (*convert) (char const *, char **)) { DOUBLE val; char *terminator; @@ -58,9 +58,9 @@ XSTRTOD (char const *str, char const **ptr, DOUBLE *result, else { /* Allow underflow (in which case CONVERT returns zero), - but flag overflow as an error. */ + but flag overflow as an error. */ if (val != 0 && errno == ERANGE) - ok = false; + ok = false; } if (ptr != NULL) diff --git a/lib/xstrtod.h b/lib/xstrtod.h index 949d6d469..cbfe781ab 100644 --- a/lib/xstrtod.h +++ b/lib/xstrtod.h @@ -23,8 +23,8 @@ # include bool xstrtod (const char *str, const char **ptr, double *result, - double (*convert) (char const *, char **)); + double (*convert) (char const *, char **)); bool xstrtold (const char *str, const char **ptr, long double *result, - long double (*convert) (char const *, char **)); + long double (*convert) (char const *, char **)); #endif /* not XSTRTOD_H */ diff --git a/lib/xstrtol-error.c b/lib/xstrtol-error.c index 67b5bf065..b38f93ef6 100644 --- a/lib/xstrtol-error.c +++ b/lib/xstrtol-error.c @@ -45,9 +45,9 @@ static void xstrtol_error (enum strtol_error err, - int opt_idx, char c, struct option const *long_options, - char const *arg, - int exit_status) + int opt_idx, char c, struct option const *long_options, + char const *arg, + int exit_status) { char const *hyphens = "--"; char const *msgid; @@ -90,8 +90,8 @@ xstrtol_error (enum strtol_error err, void xstrtol_fatal (enum strtol_error err, - int opt_idx, char c, struct option const *long_options, - char const *arg) + int opt_idx, char c, struct option const *long_options, + char const *arg) { xstrtol_error (err, opt_idx, c, long_options, arg, exit_failure); abort (); diff --git a/lib/xstrtol.c b/lib/xstrtol.c index 1804fe586..dfede5c8b 100644 --- a/lib/xstrtol.c +++ b/lib/xstrtol.c @@ -73,7 +73,7 @@ bkm_scale_by_power (__strtol_t *x, int base, int power) strtol_error __xstrtol (const char *s, char **ptr, int strtol_base, - __strtol_t *val, const char *valid_suffixes) + __strtol_t *val, const char *valid_suffixes) { char *t_ptr; char **p; @@ -89,9 +89,9 @@ __xstrtol (const char *s, char **ptr, int strtol_base, const char *q = s; unsigned char ch = *q; while (isspace (ch)) - ch = *++q; + ch = *++q; if (ch == '-') - return LONGINT_INVALID; + return LONGINT_INVALID; } errno = 0; @@ -100,16 +100,16 @@ __xstrtol (const char *s, char **ptr, int strtol_base, if (*p == s) { /* If there is no number but there is a valid suffix, assume the - number is 1. The string is invalid otherwise. */ + number is 1. The string is invalid otherwise. */ if (valid_suffixes && **p && strchr (valid_suffixes, **p)) - tmp = 1; + tmp = 1; else - return LONGINT_INVALID; + return LONGINT_INVALID; } else if (errno != 0) { if (errno != ERANGE) - return LONGINT_INVALID; + return LONGINT_INVALID; err = LONGINT_OVERFLOW; } @@ -129,98 +129,98 @@ __xstrtol (const char *s, char **ptr, int strtol_base, strtol_error overflow; if (!strchr (valid_suffixes, **p)) - { - *val = tmp; - return err | LONGINT_INVALID_SUFFIX_CHAR; - } + { + *val = tmp; + return err | LONGINT_INVALID_SUFFIX_CHAR; + } if (strchr (valid_suffixes, '0')) - { - /* The ``valid suffix'' '0' is a special flag meaning that - an optional second suffix is allowed, which can change - the base. A suffix "B" (e.g. "100MB") stands for a power - of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for - a power of 1024. If no suffix (e.g. "100M"), assume - power-of-1024. */ - - switch (p[0][1]) - { - case 'i': - if (p[0][2] == 'B') - suffixes += 2; - break; - - case 'B': - case 'D': /* 'D' is obsolescent */ - base = 1000; - suffixes++; - break; - } - } + { + /* The ``valid suffix'' '0' is a special flag meaning that + an optional second suffix is allowed, which can change + the base. A suffix "B" (e.g. "100MB") stands for a power + of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for + a power of 1024. If no suffix (e.g. "100M"), assume + power-of-1024. */ + + switch (p[0][1]) + { + case 'i': + if (p[0][2] == 'B') + suffixes += 2; + break; + + case 'B': + case 'D': /* 'D' is obsolescent */ + base = 1000; + suffixes++; + break; + } + } switch (**p) - { - case 'b': - overflow = bkm_scale (&tmp, 512); - break; - - case 'B': - overflow = bkm_scale (&tmp, 1024); - break; - - case 'c': - overflow = 0; - break; - - case 'E': /* exa or exbi */ - overflow = bkm_scale_by_power (&tmp, base, 6); - break; - - case 'G': /* giga or gibi */ - case 'g': /* 'g' is undocumented; for compatibility only */ - overflow = bkm_scale_by_power (&tmp, base, 3); - break; - - case 'k': /* kilo */ - case 'K': /* kibi */ - overflow = bkm_scale_by_power (&tmp, base, 1); - break; - - case 'M': /* mega or mebi */ - case 'm': /* 'm' is undocumented; for compatibility only */ - overflow = bkm_scale_by_power (&tmp, base, 2); - break; - - case 'P': /* peta or pebi */ - overflow = bkm_scale_by_power (&tmp, base, 5); - break; - - case 'T': /* tera or tebi */ - case 't': /* 't' is undocumented; for compatibility only */ - overflow = bkm_scale_by_power (&tmp, base, 4); - break; - - case 'w': - overflow = bkm_scale (&tmp, 2); - break; - - case 'Y': /* yotta or 2**80 */ - overflow = bkm_scale_by_power (&tmp, base, 8); - break; - - case 'Z': /* zetta or 2**70 */ - overflow = bkm_scale_by_power (&tmp, base, 7); - break; - - default: - *val = tmp; - return err | LONGINT_INVALID_SUFFIX_CHAR; - } + { + case 'b': + overflow = bkm_scale (&tmp, 512); + break; + + case 'B': + overflow = bkm_scale (&tmp, 1024); + break; + + case 'c': + overflow = 0; + break; + + case 'E': /* exa or exbi */ + overflow = bkm_scale_by_power (&tmp, base, 6); + break; + + case 'G': /* giga or gibi */ + case 'g': /* 'g' is undocumented; for compatibility only */ + overflow = bkm_scale_by_power (&tmp, base, 3); + break; + + case 'k': /* kilo */ + case 'K': /* kibi */ + overflow = bkm_scale_by_power (&tmp, base, 1); + break; + + case 'M': /* mega or mebi */ + case 'm': /* 'm' is undocumented; for compatibility only */ + overflow = bkm_scale_by_power (&tmp, base, 2); + break; + + case 'P': /* peta or pebi */ + overflow = bkm_scale_by_power (&tmp, base, 5); + break; + + case 'T': /* tera or tebi */ + case 't': /* 't' is undocumented; for compatibility only */ + overflow = bkm_scale_by_power (&tmp, base, 4); + break; + + case 'w': + overflow = bkm_scale (&tmp, 2); + break; + + case 'Y': /* yotta or 2**80 */ + overflow = bkm_scale_by_power (&tmp, base, 8); + break; + + case 'Z': /* zetta or 2**70 */ + overflow = bkm_scale_by_power (&tmp, base, 7); + break; + + default: + *val = tmp; + return err | LONGINT_INVALID_SUFFIX_CHAR; + } err |= overflow; *p += suffixes; if (**p) - err |= LONGINT_INVALID_SUFFIX_CHAR; + err |= LONGINT_INVALID_SUFFIX_CHAR; } *val = tmp; diff --git a/lib/xstrtol.h b/lib/xstrtol.h index 9ac168bf3..1dd468202 100644 --- a/lib/xstrtol.h +++ b/lib/xstrtol.h @@ -33,7 +33,7 @@ enum strtol_error LONGINT_INVALID_SUFFIX_CHAR = 2, LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR - | LONGINT_OVERFLOW), + | LONGINT_OVERFLOW), LONGINT_INVALID = 4 }; typedef enum strtol_error strtol_error; @@ -72,7 +72,7 @@ _DECLARE_XSTRTOL (xstrtoumax, uintmax_t) After reporting an error, exit with a failure status. */ void xstrtol_fatal (enum strtol_error, - int, char, struct option const *, - char const *) ATTRIBUTE_NORETURN; + int, char, struct option const *, + char const *) ATTRIBUTE_NORETURN; #endif /* not XSTRTOL_H_ */ diff --git a/lib/xtime.h b/lib/xtime.h index 1be9ad768..1676f3010 100644 --- a/lib/xtime.h +++ b/lib/xtime.h @@ -60,10 +60,10 @@ static inline xtime_t xtime_sec (xtime_t t) { return (XTIME_PRECISION == 1 - ? t - : t < 0 - ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 - : xtime_nonnegative_sec (t)); + ? t + : t < 0 + ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 + : xtime_nonnegative_sec (t)); } /* Return the number of nanoseconds in T, which must be nonnegative. */ diff --git a/lib/xvasprintf.c b/lib/xvasprintf.c index fd7f21b10..f7f6cf4c7 100644 --- a/lib/xvasprintf.c +++ b/lib/xvasprintf.c @@ -86,23 +86,23 @@ xvasprintf (const char *format, va_list args) 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 (*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 (); + xalloc_die (); return NULL; } diff --git a/m4/absolute-header.m4 b/m4/absolute-header.m4 index bc2571105..768443aa0 100644 --- a/m4/absolute-header.m4 +++ b/m4/absolute-header.m4 @@ -49,10 +49,10 @@ m4_foreach_w([gl_HEADER_NAME], [$1], AS_VAR_SET(gl_absolute_header, [`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{ - s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1# - s#^/[^/]#//&# - p - q + s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1# + s#^/[^/]#//&# + p + q }'`]) fi AS_VAR_POPDEF([ac_header_exists])dnl diff --git a/m4/acl.m4 b/m4/acl.m4 index 784f4ea2e..8d6d2c019 100644 --- a/m4/acl.m4 +++ b/m4/acl.m4 @@ -26,90 +26,90 @@ AC_DEFUN([gl_FUNC_ACL], dnl Test for POSIX-draft-like API (Linux, FreeBSD, MacOS X, IRIX, Tru64). dnl -lacl is needed on Linux, -lpacl is needed on OSF/1. if test $use_acl = 0; then - AC_SEARCH_LIBS([acl_get_file], [acl pacl], - [if test "$ac_cv_search_acl_get_file" != "none required"; then - LIB_ACL=$ac_cv_search_acl_get_file + AC_SEARCH_LIBS([acl_get_file], [acl pacl], + [if test "$ac_cv_search_acl_get_file" != "none required"; then + LIB_ACL=$ac_cv_search_acl_get_file fi - AC_CHECK_FUNCS( - [acl_get_file acl_get_fd acl_set_file acl_set_fd \ - acl_free acl_from_mode acl_from_text \ - acl_delete_def_file acl_extended_file \ - acl_delete_fd_np acl_delete_file_np \ - acl_copy_ext_native acl_create_entry_np \ - acl_to_short_text acl_free_text]) - # If the acl_get_file bug is detected, don't enable the ACL support. - gl_ACL_GET_FILE([use_acl=1], []) - if test $use_acl = 1; then - dnl On Linux, additional API is declared in . - AC_CHECK_HEADERS([acl/libacl.h]) - AC_REPLACE_FUNCS([acl_entries]) - AC_CACHE_CHECK([for ACL_FIRST_ENTRY], - [gl_cv_acl_ACL_FIRST_ENTRY], - [AC_COMPILE_IFELSE( + AC_CHECK_FUNCS( + [acl_get_file acl_get_fd acl_set_file acl_set_fd \ + acl_free acl_from_mode acl_from_text \ + acl_delete_def_file acl_extended_file \ + acl_delete_fd_np acl_delete_file_np \ + acl_copy_ext_native acl_create_entry_np \ + acl_to_short_text acl_free_text]) + # If the acl_get_file bug is detected, don't enable the ACL support. + gl_ACL_GET_FILE([use_acl=1], []) + if test $use_acl = 1; then + dnl On Linux, additional API is declared in . + AC_CHECK_HEADERS([acl/libacl.h]) + AC_REPLACE_FUNCS([acl_entries]) + AC_CACHE_CHECK([for ACL_FIRST_ENTRY], + [gl_cv_acl_ACL_FIRST_ENTRY], + [AC_COMPILE_IFELSE( [[#include #include int type = ACL_FIRST_ENTRY;]], - [gl_cv_acl_ACL_FIRST_ENTRY=yes], - [gl_cv_acl_ACL_FIRST_ENTRY=no])]) - if test $gl_cv_acl_ACL_FIRST_ENTRY = yes; then - AC_DEFINE([HAVE_ACL_FIRST_ENTRY], [1], - [Define to 1 if the constant ACL_FIRST_ENTRY exists.]) - fi - dnl On MacOS X, other types of ACLs are supported. - AC_CACHE_CHECK([for ACL_TYPE_EXTENDED], - [gl_cv_acl_ACL_TYPE_EXTENDED], - [AC_COMPILE_IFELSE( + [gl_cv_acl_ACL_FIRST_ENTRY=yes], + [gl_cv_acl_ACL_FIRST_ENTRY=no])]) + if test $gl_cv_acl_ACL_FIRST_ENTRY = yes; then + AC_DEFINE([HAVE_ACL_FIRST_ENTRY], [1], + [Define to 1 if the constant ACL_FIRST_ENTRY exists.]) + fi + dnl On MacOS X, other types of ACLs are supported. + AC_CACHE_CHECK([for ACL_TYPE_EXTENDED], + [gl_cv_acl_ACL_TYPE_EXTENDED], + [AC_COMPILE_IFELSE( [[#include #include int type = ACL_TYPE_EXTENDED;]], - [gl_cv_acl_ACL_TYPE_EXTENDED=yes], - [gl_cv_acl_ACL_TYPE_EXTENDED=no])]) - if test $gl_cv_acl_ACL_TYPE_EXTENDED = yes; then - AC_DEFINE([HAVE_ACL_TYPE_EXTENDED], [1], - [Define to 1 if the ACL type ACL_TYPE_EXTENDED exists.]) - fi - else - LIB_ACL= - fi - ]) + [gl_cv_acl_ACL_TYPE_EXTENDED=yes], + [gl_cv_acl_ACL_TYPE_EXTENDED=no])]) + if test $gl_cv_acl_ACL_TYPE_EXTENDED = yes; then + AC_DEFINE([HAVE_ACL_TYPE_EXTENDED], [1], + [Define to 1 if the ACL type ACL_TYPE_EXTENDED exists.]) + fi + else + LIB_ACL= + fi + ]) fi dnl Test for Solaris API (Solaris, Cygwin). if test $use_acl = 0; then - AC_CHECK_FUNCS([acl]) - if test $ac_cv_func_acl = yes; then - AC_SEARCH_LIBS([acl_trivial], [sec], - [if test "$ac_cv_search_acl_trivial" != "none required"; then - LIB_ACL=$ac_cv_search_acl_trivial - fi - ]) - AC_CHECK_FUNCS([acl_trivial]) - use_acl=1 - fi + AC_CHECK_FUNCS([acl]) + if test $ac_cv_func_acl = yes; then + AC_SEARCH_LIBS([acl_trivial], [sec], + [if test "$ac_cv_search_acl_trivial" != "none required"; then + LIB_ACL=$ac_cv_search_acl_trivial + fi + ]) + AC_CHECK_FUNCS([acl_trivial]) + use_acl=1 + fi fi dnl Test for HP-UX API. if test $use_acl = 0 || test "$ac_cv_func_acl" = yes; then - AC_CHECK_FUNCS([getacl]) - if test $ac_cv_func_getacl = yes; then - use_acl=1 - fi + AC_CHECK_FUNCS([getacl]) + if test $ac_cv_func_getacl = yes; then + use_acl=1 + fi fi dnl Test for AIX API (AIX 5.3 or newer). if test $use_acl = 0; then - AC_CHECK_FUNCS([aclx_get]) - if test $ac_cv_func_aclx_get = yes; then - use_acl=1 - fi + AC_CHECK_FUNCS([aclx_get]) + if test $ac_cv_func_aclx_get = yes; then + use_acl=1 + fi fi dnl Test for older AIX API. if test $use_acl = 0 || test "$ac_cv_func_aclx_get" = yes; then - AC_CHECK_FUNCS([statacl]) - if test $ac_cv_func_statacl = yes; then - use_acl=1 - fi + AC_CHECK_FUNCS([statacl]) + if test $ac_cv_func_statacl = yes; then + use_acl=1 + fi fi LIBS=$ac_save_LIBS @@ -139,12 +139,12 @@ AC_DEFUN([gl_ACL_GET_FILE], AC_CACHE_CHECK([for working acl_get_file], [gl_cv_func_working_acl_get_file], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( - [[#include - #include - #include - ]], - [[return !! (!acl_get_file (".", ACL_TYPE_ACCESS) - && errno == ENOENT);]])], + [[#include + #include + #include + ]], + [[return !! (!acl_get_file (".", ACL_TYPE_ACCESS) + && errno == ENOENT);]])], [gl_cv_func_working_acl_get_file=yes], [gl_cv_func_working_acl_get_file=no], [gl_cv_func_working_acl_get_file=cross-compiling])]) diff --git a/m4/afs.m4 b/m4/afs.m4 index f4b067cf7..1a2f9db58 100644 --- a/m4/afs.m4 +++ b/m4/afs.m4 @@ -8,8 +8,8 @@ AC_DEFUN([gl_AFS], [ AC_ARG_WITH([afs], - AS_HELP_STRING([--with-afs], - [support for the Andrew File System [[default=no]]]), + AS_HELP_STRING([--with-afs], + [support for the Andrew File System [[default=no]]]), test "$withval" = no || with_afs=yes, with_afs=no) if test "$with_afs" = yes; then AC_DEFINE([AFS], [1], [Define if you have the Andrew File System.]) diff --git a/m4/argp.m4 b/m4/argp.m4 index b2a694050..86e08905d 100644 --- a/m4/argp.m4 +++ b/m4/argp.m4 @@ -17,13 +17,13 @@ AC_DEFUN([gl_ARGP], AC_CHECK_DECL([program_invocation_name], [AC_DEFINE([HAVE_DECL_PROGRAM_INVOCATION_NAME], [1], [Define if program_invocation_name is declared])], - [AC_DEFINE([GNULIB_PROGRAM_INVOCATION_NAME], [1], + [AC_DEFINE([GNULIB_PROGRAM_INVOCATION_NAME], [1], [Define to 1 to add extern declaration of program_invocation_name to argp.h])], [#include ]) AC_CHECK_DECL([program_invocation_short_name], [AC_DEFINE([HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME], [1], [Define if program_invocation_short_name is declared])], - [AC_DEFINE([GNULIB_PROGRAM_INVOCATION_SHORT_NAME], [1], + [AC_DEFINE([GNULIB_PROGRAM_INVOCATION_SHORT_NAME], [1], [Define to 1 to add extern declaration of program_invocation_short_name to argp.h])], [#include ]) diff --git a/m4/argz.m4 b/m4/argz.m4 index b77d48ab9..2119e0a24 100644 --- a/m4/argz.m4 +++ b/m4/argz.m4 @@ -43,30 +43,30 @@ AS_IF([test -z "$ARGZ_H"], [if argz actually works], [lt_cv_sys_argz_works], [[case $host_os in #( - *cygwin*) - lt_cv_sys_argz_works=no - if test "$cross_compiling" != no; then - lt_cv_sys_argz_works="guessing no" - else - lt_sed_extract_leading_digits='s/^\([0-9\.]*\).*/\1/' - save_IFS=$IFS - IFS=-. - set x `uname -r | sed -e "$lt_sed_extract_leading_digits"` - IFS=$save_IFS - lt_os_major=${2-0} - lt_os_minor=${3-0} - lt_os_micro=${4-0} - if test "$lt_os_major" -gt 1 \ - || { test "$lt_os_major" -eq 1 \ - && { test "$lt_os_minor" -gt 5 \ - || { test "$lt_os_minor" -eq 5 \ - && test "$lt_os_micro" -gt 24; }; }; }; then - lt_cv_sys_argz_works=yes - fi - fi - ;; #( - *) lt_cv_sys_argz_works=yes ;; - esac]]) + *cygwin*) + lt_cv_sys_argz_works=no + if test "$cross_compiling" != no; then + lt_cv_sys_argz_works="guessing no" + else + lt_sed_extract_leading_digits='s/^\([0-9\.]*\).*/\1/' + save_IFS=$IFS + IFS=-. + set x `uname -r | sed -e "$lt_sed_extract_leading_digits"` + IFS=$save_IFS + lt_os_major=${2-0} + lt_os_minor=${3-0} + lt_os_micro=${4-0} + if test "$lt_os_major" -gt 1 \ + || { test "$lt_os_major" -eq 1 \ + && { test "$lt_os_minor" -gt 5 \ + || { test "$lt_os_minor" -eq 5 \ + && test "$lt_os_micro" -gt 24; }; }; }; then + lt_cv_sys_argz_works=yes + fi + fi + ;; #( + *) lt_cv_sys_argz_works=yes ;; + esac]]) AS_IF([test $lt_cv_sys_argz_works = yes], [AC_DEFINE([HAVE_WORKING_ARGZ], [1], [This value is set to 1 to indicate that the system argz facility works])], diff --git a/m4/assert.m4 b/m4/assert.m4 index fb90cb365..41fbda7f0 100644 --- a/m4/assert.m4 +++ b/m4/assert.m4 @@ -15,7 +15,7 @@ AC_DEFUN([gl_ASSERT], [AS_HELP_STRING([--disable-assert], [turn off assertions])], [AS_IF([test "x$enableval" = xno], [AC_DEFINE([NDEBUG], [1], - [Define to 1 if assertions should be disabled.])], + [Define to 1 if assertions should be disabled.])], [test "x$enableval" != xyes], [AC_MSG_WARN([invalid argument supplied to --enable-assert]) enable_assert=yes])], diff --git a/m4/c-stack.m4 b/m4/c-stack.m4 index 2a89696a9..1272dadb7 100644 --- a/m4/c-stack.m4 +++ b/m4/c-stack.m4 @@ -116,9 +116,9 @@ AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC], return c_stack_action () || recurse (0); } ]])], - [ac_cv_sys_stack_overflow_works=yes], - [ac_cv_sys_stack_overflow_works=no], - [ac_cv_sys_stack_overflow_works=cross-compiling])]) + [ac_cv_sys_stack_overflow_works=yes], + [ac_cv_sys_stack_overflow_works=no], + [ac_cv_sys_stack_overflow_works=cross-compiling])]) if test $ac_cv_sys_stack_overflow_works = yes; then AC_DEFINE([HAVE_STACK_OVERFLOW_HANDLING], [1], @@ -132,7 +132,7 @@ AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC], AC_CACHE_CHECK([for correct stack_t interpretation], [gl_cv_sigaltstack_low_base], [ AC_RUN_IFELSE([ - AC_LANG_SOURCE([[ + AC_LANG_SOURCE([[ #include #include #if HAVE_SYS_SIGNAL_H @@ -183,9 +183,9 @@ int main () [gl_cv_sigaltstack_low_base=cross-compiling])]) if test "$gl_cv_sigaltstack_low_base" = no; then AC_DEFINE([SIGALTSTACK_SS_REVERSED], [1], - [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.]) + [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.]) fi AC_CACHE_CHECK([for precise C stack overflow detection], @@ -302,19 +302,19 @@ int main () return c_stack_action () || recurse (0); } ]])], - [ac_cv_sys_xsi_stack_overflow_heuristic=yes], - [ac_cv_sys_xsi_stack_overflow_heuristic=no], - [ac_cv_sys_xsi_stack_overflow_heuristic=cross-compiling])]) + [ac_cv_sys_xsi_stack_overflow_heuristic=yes], + [ac_cv_sys_xsi_stack_overflow_heuristic=no], + [ac_cv_sys_xsi_stack_overflow_heuristic=cross-compiling])]) if test $ac_cv_sys_xsi_stack_overflow_heuristic = yes; then AC_DEFINE([HAVE_XSI_STACK_OVERFLOW_HEURISTIC], [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.]) + 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.]) fi fi]) diff --git a/m4/c-strtod.m4 b/m4/c-strtod.m4 index ba954354f..440b0d662 100644 --- a/m4/c-strtod.m4 +++ b/m4/c-strtod.m4 @@ -14,17 +14,17 @@ AC_DEFUN([gl_C99_STRTOLD], [AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[/* On HP-UX before 11.23, strtold returns a struct instead of - long double. Reject implementations like that, by requiring - compatibility with the C99 prototype. */ - #include - static long double (*p) (char const *, char **) = strtold; - static long double - test (char const *nptr, char **endptr) - { - long double r; - r = strtold (nptr, endptr); - return r; - }]], + long double. Reject implementations like that, by requiring + compatibility with the C99 prototype. */ + #include + static long double (*p) (char const *, char **) = strtold; + static long double + test (char const *nptr, char **endptr) + { + long double r; + r = strtold (nptr, endptr); + return r; + }]], [[return test ("1.0", NULL) != 1 || p ("1.0", NULL) != 1;]])], [gl_cv_func_c99_strtold=yes], [gl_cv_func_c99_strtold=no])]) diff --git a/m4/calloc.m4 b/m4/calloc.m4 index b0637b44a..3bb899126 100644 --- a/m4/calloc.m4 +++ b/m4/calloc.m4 @@ -19,10 +19,10 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF], [AC_REQUIRE([AC_TYPE_SIZE_T])dnl AC_CACHE_CHECK([for GNU libc compatible calloc], [ac_cv_func_calloc_0_nonnull], [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], - [[exit (!calloc (0, 0) || calloc ((size_t) -1 / 8 + 1, 8));]])], - [ac_cv_func_calloc_0_nonnull=yes], - [ac_cv_func_calloc_0_nonnull=no], - [ac_cv_func_calloc_0_nonnull=no])]) + [[exit (!calloc (0, 0) || calloc ((size_t) -1 / 8 + 1, 8));]])], + [ac_cv_func_calloc_0_nonnull=yes], + [ac_cv_func_calloc_0_nonnull=no], + [ac_cv_func_calloc_0_nonnull=no])]) AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2]) ])# AC_FUNC_CALLOC @@ -34,8 +34,8 @@ AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2]) AC_DEFUN([AC_FUNC_CALLOC], [_AC_FUNC_CALLOC_IF( [AC_DEFINE([HAVE_CALLOC], [1], - [Define to 1 if your system has a GNU libc compatible `calloc' - function, and to 0 otherwise.])], + [Define to 1 if your system has a GNU libc compatible `calloc' + function, and to 0 otherwise.])], [AC_DEFINE([HAVE_CALLOC], [0]) AC_LIBOBJ([calloc]) AC_DEFINE([calloc], [rpl_calloc], diff --git a/m4/chown.m4 b/m4/chown.m4 index 0dced4bce..8c3ae5573 100644 --- a/m4/chown.m4 +++ b/m4/chown.m4 @@ -110,24 +110,24 @@ AC_DEFUN_ONCE([gl_FUNC_CHOWN_FOLLOWS_SYMLINK], #include #include - int - main () - { - char const *dangling_symlink = "conftest.dangle"; + int + main () + { + char const *dangling_symlink = "conftest.dangle"; - unlink (dangling_symlink); - if (symlink ("conftest.no-such", dangling_symlink)) - abort (); + unlink (dangling_symlink); + if (symlink ("conftest.no-such", dangling_symlink)) + abort (); - /* Exit successfully on a conforming system, - i.e., where chown must fail with ENOENT. */ - exit ( ! (chown (dangling_symlink, getuid (), getgid ()) != 0 - && errno == ENOENT)); - } - ]])], - [gl_cv_func_chown_follows_symlink=yes], - [gl_cv_func_chown_follows_symlink=no], - [gl_cv_func_chown_follows_symlink=yes] + /* Exit successfully on a conforming system, + i.e., where chown must fail with ENOENT. */ + exit ( ! (chown (dangling_symlink, getuid (), getgid ()) != 0 + && errno == ENOENT)); + } + ]])], + [gl_cv_func_chown_follows_symlink=yes], + [gl_cv_func_chown_follows_symlink=no], + [gl_cv_func_chown_follows_symlink=yes] ) ] ) diff --git a/m4/d-ino.m4 b/m4/d-ino.m4 index 9bab8f149..e4ea6ea33 100644 --- a/m4/d-ino.m4 +++ b/m4/d-ino.m4 @@ -14,25 +14,25 @@ dnl AC_DEFUN([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO], [AC_CACHE_CHECK([for d_ino member in directory struct], - gl_cv_struct_dirent_d_ino, + gl_cv_struct_dirent_d_ino, [AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [[#include - #include - #include - ]], - [[DIR *dp = opendir ("."); - struct dirent *e; - struct stat st; - if (! dp) - return 1; - e = readdir (dp); - return ! (e - && stat (e->d_name, &st) == 0 - && e->d_ino == st.st_ino);]])], - [gl_cv_struct_dirent_d_ino=yes], - [gl_cv_struct_dirent_d_ino=no], - [gl_cv_struct_dirent_d_ino=no])]) + [AC_LANG_PROGRAM( + [[#include + #include + #include + ]], + [[DIR *dp = opendir ("."); + struct dirent *e; + struct stat st; + if (! dp) + return 1; + e = readdir (dp); + return ! (e + && stat (e->d_name, &st) == 0 + && e->d_ino == st.st_ino);]])], + [gl_cv_struct_dirent_d_ino=yes], + [gl_cv_struct_dirent_d_ino=no], + [gl_cv_struct_dirent_d_ino=no])]) if test $gl_cv_struct_dirent_d_ino = yes; then AC_DEFINE([D_INO_IN_DIRENT], [1], [Define if struct dirent has a member d_ino that actually works.]) diff --git a/m4/d-type.m4 b/m4/d-type.m4 index 97e8852de..bceeb952e 100644 --- a/m4/d-type.m4 +++ b/m4/d-type.m4 @@ -13,12 +13,12 @@ dnl AC_DEFUN([gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE], [AC_CACHE_CHECK([for d_type member in directory struct], - gl_cv_struct_dirent_d_type, + gl_cv_struct_dirent_d_type, [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include #include - ]], - [[struct dirent dp; dp.d_type = 0;]])], + ]], + [[struct dirent dp; dp.d_type = 0;]])], [gl_cv_struct_dirent_d_type=yes], [gl_cv_struct_dirent_d_type=no]) ] diff --git a/m4/dirfd.m4 b/m4/dirfd.m4 index 02ddc9f78..fe0975df4 100644 --- a/m4/dirfd.m4 +++ b/m4/dirfd.m4 @@ -46,34 +46,34 @@ AC_DEFUN([gl_FUNC_DIRFD], = no,no,no; then AC_REPLACE_FUNCS([dirfd]) AC_CACHE_CHECK( - [how to get the file descriptor associated with an open DIR*], - gl_cv_sys_dir_fd_member_name, + [how to get the file descriptor associated with an open DIR*], + gl_cv_sys_dir_fd_member_name, [ - dirfd_save_CFLAGS=$CFLAGS - for ac_expr in d_fd dd_fd; do + dirfd_save_CFLAGS=$CFLAGS + for ac_expr in d_fd dd_fd; do - CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #include - #include ]], - [[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;]])], - [dir_fd_found=yes] - ) - CFLAGS=$dirfd_save_CFLAGS - test "$dir_fd_found" = yes && break - done - test "$dir_fd_found" = yes || ac_expr=no_such_member + CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #include + #include ]], + [[DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;]])], + [dir_fd_found=yes] + ) + CFLAGS=$dirfd_save_CFLAGS + test "$dir_fd_found" = yes && break + done + test "$dir_fd_found" = yes || ac_expr=no_such_member - gl_cv_sys_dir_fd_member_name=$ac_expr + gl_cv_sys_dir_fd_member_name=$ac_expr ] ) if test $gl_cv_sys_dir_fd_member_name != no_such_member; then AC_DEFINE_UNQUOTED([DIR_FD_MEMBER_NAME], - $gl_cv_sys_dir_fd_member_name, - [the name of the file descriptor member of DIR]) + $gl_cv_sys_dir_fd_member_name, + [the name of the file descriptor member of DIR]) fi AH_VERBATIM(DIR_TO_FD, - [#ifdef DIR_FD_MEMBER_NAME + [#ifdef DIR_FD_MEMBER_NAME # define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME) #else # define DIR_TO_FD(Dir_p) -1 diff --git a/m4/dos.m4 b/m4/dos.m4 index 231ddc0cf..5c3593c27 100644 --- a/m4/dos.m4 +++ b/m4/dos.m4 @@ -14,31 +14,31 @@ AC_DEFUN([gl_AC_DOS], [ AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ #if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ neither MSDOS nor Windows #endif]])], - [ac_cv_win_or_dos=yes], - [ac_cv_win_or_dos=no]) + [ac_cv_win_or_dos=yes], + [ac_cv_win_or_dos=no]) ]) if test x"$ac_cv_win_or_dos" = xyes; then ac_fs_accepts_drive_letter_prefix=1 ac_fs_backslash_is_file_name_separator=1 AC_CACHE_CHECK([whether drive letter can start relative path], - [ac_cv_drive_letter_can_be_relative], - [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ + [ac_cv_drive_letter_can_be_relative], + [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ #if defined __CYGWIN__ drive letters are always absolute #endif]])], - [ac_cv_drive_letter_can_be_relative=yes], - [ac_cv_drive_letter_can_be_relative=no]) - ]) + [ac_cv_drive_letter_can_be_relative=yes], + [ac_cv_drive_letter_can_be_relative=no]) + ]) if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then - ac_fs_drive_letter_can_be_relative=1 + ac_fs_drive_letter_can_be_relative=1 else - ac_fs_drive_letter_can_be_relative=0 + ac_fs_drive_letter_can_be_relative=0 fi else ac_fs_accepts_drive_letter_prefix=0 diff --git a/m4/double-slash-root.m4 b/m4/double-slash-root.m4 index 8c6841bc8..b98259415 100644 --- a/m4/double-slash-root.m4 +++ b/m4/double-slash-root.m4 @@ -9,27 +9,27 @@ AC_DEFUN([gl_DOUBLE_SLASH_ROOT], AC_REQUIRE([AC_CANONICAL_HOST]) AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root], [ if test x"$cross_compiling" = xyes ; then - # When cross-compiling, there is no way to tell whether // is special - # short of a list of hosts. However, the only known hosts to date - # that have a distinct // are Apollo DomainOS (too old to port to), - # Cygwin, and z/OS. If anyone knows of another system for which // has - # special semantics and is distinct from /, please report it to - # . - case $host in - *-cygwin | i370-ibm-openedition) - gl_cv_double_slash_root=yes ;; - *) - # Be optimistic and assume that / and // are the same when we - # don't know. - gl_cv_double_slash_root='unknown, assuming no' ;; - esac + # When cross-compiling, there is no way to tell whether // is special + # short of a list of hosts. However, the only known hosts to date + # that have a distinct // are Apollo DomainOS (too old to port to), + # Cygwin, and z/OS. If anyone knows of another system for which // has + # special semantics and is distinct from /, please report it to + # . + case $host in + *-cygwin | i370-ibm-openedition) + gl_cv_double_slash_root=yes ;; + *) + # Be optimistic and assume that / and // are the same when we + # don't know. + gl_cv_double_slash_root='unknown, assuming no' ;; + esac else - set x `ls -di / // 2>/dev/null` - if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then - gl_cv_double_slash_root=no - else - gl_cv_double_slash_root=yes - fi + set x `ls -di / // 2>/dev/null` + if test "$[2]" = "$[4]" && wc //dev/null >/dev/null 2>&1; then + gl_cv_double_slash_root=no + else + gl_cv_double_slash_root=yes + fi fi]) if test "$gl_cv_double_slash_root" = yes; then AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], [1], diff --git a/m4/dup2.m4 b/m4/dup2.m4 index 26a6f60e3..73a32092d 100644 --- a/m4/dup2.m4 +++ b/m4/dup2.m4 @@ -28,19 +28,19 @@ AC_DEFUN([gl_FUNC_DUP2], return 0; ]) ], - [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no], - [case "$host_os" in - mingw*) # on this platform, dup2 always returns 0 for success - gl_cv_func_dup2_works=no;; - cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0 - gl_cv_func_dup2_works=no;; - linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a - # closed fd may yield -EBADF instead of -1 / errno=EBADF. - gl_cv_func_dup2_works=no;; + [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no], + [case "$host_os" in + mingw*) # on this platform, dup2 always returns 0 for success + gl_cv_func_dup2_works=no;; + cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0 + gl_cv_func_dup2_works=no;; + linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a + # closed fd may yield -EBADF instead of -1 / errno=EBADF. + gl_cv_func_dup2_works=no;; freebsd*) # on FreeBSD 6.1, dup2(1,1000000) gives EMFILE, not EBADF. - gl_cv_func_dup2_works=no;; - *) gl_cv_func_dup2_works=yes;; - esac]) + gl_cv_func_dup2_works=no;; + *) gl_cv_func_dup2_works=yes;; + esac]) ]) if test "$gl_cv_func_dup2_works" = no; then gl_REPLACE_DUP2 diff --git a/m4/extensions.m4 b/m4/extensions.m4 index ba6d5e190..99fba9f63 100644 --- a/m4/extensions.m4 +++ b/m4/extensions.m4 @@ -74,8 +74,8 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl [ac_cv_safe_to_define___extensions__], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[ -# define __EXTENSIONS__ 1 - ]AC_INCLUDES_DEFAULT])], +# define __EXTENSIONS__ 1 + ]AC_INCLUDES_DEFAULT])], [ac_cv_safe_to_define___extensions__=yes], [ac_cv_safe_to_define___extensions__=no])]) test $ac_cv_safe_to_define___extensions__ = yes && diff --git a/m4/fcntl_h.m4 b/m4/fcntl_h.m4 index 223fa4830..40a18034d 100644 --- a/m4/fcntl_h.m4 +++ b/m4/fcntl_h.m4 @@ -26,53 +26,53 @@ AC_DEFUN([gl_FCNTL_O_FLAGS], AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( - [[#include - #include - #include - #include - #ifndef O_NOATIME - #define O_NOATIME 0 - #endif - #ifndef O_NOFOLLOW - #define O_NOFOLLOW 0 - #endif - static int const constants[] = - { - O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, - O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY - }; - ]], - [[ - int status = !constants; - { - static char const sym[] = "conftest.sym"; - if (symlink (".", sym) != 0 - || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0) - status |= 32; - unlink (sym); - } - { - static char const file[] = "confdefs.h"; - int fd = open (file, O_RDONLY | O_NOATIME); - char c; - struct stat st0, st1; - if (fd < 0 - || fstat (fd, &st0) != 0 - || sleep (1) != 0 - || read (fd, &c, 1) != 1 - || close (fd) != 0 - || stat (file, &st1) != 0 - || st0.st_atime != st1.st_atime) - status |= 64; - } - return status;]])], + [[#include + #include + #include + #include + #ifndef O_NOATIME + #define O_NOATIME 0 + #endif + #ifndef O_NOFOLLOW + #define O_NOFOLLOW 0 + #endif + static int const constants[] = + { + O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, + O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY + }; + ]], + [[ + int status = !constants; + { + static char const sym[] = "conftest.sym"; + if (symlink (".", sym) != 0 + || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0) + status |= 32; + unlink (sym); + } + { + static char const file[] = "confdefs.h"; + int fd = open (file, O_RDONLY | O_NOATIME); + char c; + struct stat st0, st1; + if (fd < 0 + || fstat (fd, &st0) != 0 + || sleep (1) != 0 + || read (fd, &c, 1) != 1 + || close (fd) != 0 + || stat (file, &st1) != 0 + || st0.st_atime != st1.st_atime) + status |= 64; + } + return status;]])], [gl_cv_header_working_fcntl_h=yes], [case $? in #( - 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( - 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( - 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( - *) gl_cv_header_working_fcntl_h='no';; - esac], + 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( + 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( + 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( + *) gl_cv_header_working_fcntl_h='no';; + esac], [gl_cv_header_working_fcntl_h=cross-compiling])]) case $gl_cv_header_working_fcntl_h in #( diff --git a/m4/fdopendir.m4 b/m4/fdopendir.m4 index 0ffb7fbbe..0ae80b382 100644 --- a/m4/fdopendir.m4 +++ b/m4/fdopendir.m4 @@ -26,9 +26,9 @@ AC_DEFUN([gl_FUNC_FDOPENDIR], ]], [int fd = open ("conftest.h", O_RDONLY); if (fd < 0) return 2; return !!fdopendir (fd);])], - [gl_cv_func_fdopendir_works=yes], - [gl_cv_func_fdopendir_works=no], - [gl_cv_func_fdopendir_works="guessing no"])]) + [gl_cv_func_fdopendir_works=yes], + [gl_cv_func_fdopendir_works=no], + [gl_cv_func_fdopendir_works="guessing no"])]) if test "$gl_cv_func_fdopendir_works" != yes; then REPLACE_FDOPENDIR=1 gl_REPLACE_DIRENT_H diff --git a/m4/fflush.m4 b/m4/fflush.m4 index da30e1fe6..aae51046b 100644 --- a/m4/fflush.m4 +++ b/m4/fflush.m4 @@ -20,40 +20,40 @@ AC_DEFUN([gl_FUNC_FFLUSH], #include #include ]], [[FILE *f = fopen ("conftest.txt", "r"); - char buffer[10]; - int fd; - int c; - if (f == NULL) - return 1; - fd = fileno (f); - if (fd < 0 || fread (buffer, 1, 5, f) != 5) - return 2; - /* For deterministic results, ensure f read a bigger buffer. */ - if (lseek (fd, 0, SEEK_CUR) == 5) - return 3; - /* POSIX requires fflush-fseek to set file offset of fd. This fails - on BSD systems and on mingw. */ - if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0) - return 4; - if (lseek (fd, 0, SEEK_CUR) != 5) - return 5; - /* Verify behaviour of fflush after ungetc. See - */ - /* Verify behaviour of fflush after a backup ungetc. This fails on - mingw. */ - c = fgetc (f); - ungetc (c, f); - fflush (f); - if (fgetc (f) != c) - return 6; - /* Verify behaviour of fflush after a non-backup ungetc. This fails - on glibc 2.8 and on BSD systems. */ - c = fgetc (f); - ungetc ('@', f); - fflush (f); - if (fgetc (f) != c) - return 7; - return 0; + char buffer[10]; + int fd; + int c; + if (f == NULL) + return 1; + fd = fileno (f); + if (fd < 0 || fread (buffer, 1, 5, f) != 5) + return 2; + /* For deterministic results, ensure f read a bigger buffer. */ + if (lseek (fd, 0, SEEK_CUR) == 5) + return 3; + /* POSIX requires fflush-fseek to set file offset of fd. This fails + on BSD systems and on mingw. */ + if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0) + return 4; + if (lseek (fd, 0, SEEK_CUR) != 5) + return 5; + /* Verify behaviour of fflush after ungetc. See + */ + /* Verify behaviour of fflush after a backup ungetc. This fails on + mingw. */ + c = fgetc (f); + ungetc (c, f); + fflush (f); + if (fgetc (f) != c) + return 6; + /* Verify behaviour of fflush after a non-backup ungetc. This fails + on glibc 2.8 and on BSD systems. */ + c = fgetc (f); + ungetc ('@', f); + fflush (f); + if (fgetc (f) != c) + return 7; + return 0; ]])], [gl_cv_func_fflush_stdin=yes], [gl_cv_func_fflush_stdin=no], [dnl Pessimistically assume fflush is broken. gl_cv_func_fflush_stdin=no]) diff --git a/m4/flexmember.m4 b/m4/flexmember.m4 index 271889b20..c2314f4e4 100644 --- a/m4/flexmember.m4 +++ b/m4/flexmember.m4 @@ -14,15 +14,15 @@ AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER], ac_cv_c_flexmember, [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[#include - #include - #include - struct s { int n; double d[]; };]], - [[int m = getchar (); - struct s *p = malloc (offsetof (struct s, d) - + m * sizeof (double)); - p->d[0] = 0.0; - return p->d != (double *) NULL;]])], + [[#include + #include + #include + struct s { int n; double d[]; };]], + [[int m = getchar (); + struct s *p = malloc (offsetof (struct s, d) + + m * sizeof (double)); + p->d[0] = 0.0; + return p->d != (double *) NULL;]])], [ac_cv_c_flexmember=yes], [ac_cv_c_flexmember=no])]) if test $ac_cv_c_flexmember = yes; then diff --git a/m4/fpending.m4 b/m4/fpending.m4 index fecf3f315..4f3cacaa8 100644 --- a/m4/fpending.m4 +++ b/m4/fpending.m4 @@ -26,53 +26,53 @@ AC_DEFUN([gl_FUNC_FPENDING], AC_CHECK_DECLS([__fpending], , , $fp_headers) if test $ac_cv_func___fpending = no; then AC_CACHE_CHECK( - [how to determine the number of pending output bytes on a stream], - ac_cv_sys_pending_output_n_bytes, + [how to determine the number of pending output bytes on a stream], + ac_cv_sys_pending_output_n_bytes, [ - for ac_expr in \ - \ - '# glibc2' \ - 'fp->_IO_write_ptr - fp->_IO_write_base' \ - \ - '# traditional Unix' \ - 'fp->_ptr - fp->_base' \ - \ - '# BSD' \ - 'fp->_p - fp->_bf._base' \ - \ - '# SCO, Unixware' \ - '(fp->__ptr ? fp->__ptr - fp->__base : 0)' \ - \ - '# QNX' \ - '(fp->_Mode & 0x2000 /*_MWRITE*/ ? fp->_Next - fp->_Buf : 0)' \ - \ - '# old glibc?' \ - 'fp->__bufp - fp->__buffer' \ - \ - '# old glibc iostream?' \ - 'fp->_pptr - fp->_pbase' \ - \ - '# emx+gcc' \ - 'fp->_ptr - fp->_buffer' \ - \ - '# VMS' \ - '(*fp)->_ptr - (*fp)->_base' \ - \ - '# e.g., DGUX R4.11; the info is not available' \ - 1 \ - ; do + for ac_expr in \ + \ + '# glibc2' \ + 'fp->_IO_write_ptr - fp->_IO_write_base' \ + \ + '# traditional Unix' \ + 'fp->_ptr - fp->_base' \ + \ + '# BSD' \ + 'fp->_p - fp->_bf._base' \ + \ + '# SCO, Unixware' \ + '(fp->__ptr ? fp->__ptr - fp->__base : 0)' \ + \ + '# QNX' \ + '(fp->_Mode & 0x2000 /*_MWRITE*/ ? fp->_Next - fp->_Buf : 0)' \ + \ + '# old glibc?' \ + 'fp->__bufp - fp->__buffer' \ + \ + '# old glibc iostream?' \ + 'fp->_pptr - fp->_pbase' \ + \ + '# emx+gcc' \ + 'fp->_ptr - fp->_buffer' \ + \ + '# VMS' \ + '(*fp)->_ptr - (*fp)->_base' \ + \ + '# e.g., DGUX R4.11; the info is not available' \ + 1 \ + ; do - # Skip each embedded comment. - case "$ac_expr" in '#'*) continue;; esac + # Skip each embedded comment. + case "$ac_expr" in '#'*) continue;; esac - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[FILE *fp = stdin; (void) ($ac_expr);]])], - [fp_done=yes] - ) - test "$fp_done" = yes && break - done + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[FILE *fp = stdin; (void) ($ac_expr);]])], + [fp_done=yes] + ) + test "$fp_done" = yes && break + done - ac_cv_sys_pending_output_n_bytes=$ac_expr + ac_cv_sys_pending_output_n_bytes=$ac_expr ] ) AC_DEFINE_UNQUOTED([PENDING_OUTPUT_N_BYTES], diff --git a/m4/fpurge.m4 b/m4/fpurge.m4 index 4dba2ec0b..c245515c0 100644 --- a/m4/fpurge.m4 +++ b/m4/fpurge.m4 @@ -15,21 +15,21 @@ AC_DEFUN([gl_FUNC_FPURGE], AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works], [AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include ]], [FILE *f = fopen ("conftest.txt", "w+"); - if (!f) return 1; - if (fputc ('a', f) != 'a') return 2; - rewind (f); - if (fgetc (f) != 'a') return 3; - if (fgetc (f) != EOF) return 4; - if (fpurge (f) != 0) return 5; - if (putc ('b', f) != 'b') return 6; - if (fclose (f) != 0) return 7; - if ((f = fopen ("conftest.txt", "r")) == NULL) return 8; - if (fgetc (f) != 'a') return 9; - if (fgetc (f) != 'b') return 10; - if (fgetc (f) != EOF) return 11; - if (fclose (f) != 0) return 12; - if (remove ("conftest.txt") != 0) return 13; - return 0;])], + if (!f) return 1; + if (fputc ('a', f) != 'a') return 2; + rewind (f); + if (fgetc (f) != 'a') return 3; + if (fgetc (f) != EOF) return 4; + if (fpurge (f) != 0) return 5; + if (putc ('b', f) != 'b') return 6; + if (fclose (f) != 0) return 7; + if ((f = fopen ("conftest.txt", "r")) == NULL) return 8; + if (fgetc (f) != 'a') return 9; + if (fgetc (f) != 'b') return 10; + if (fgetc (f) != EOF) return 11; + if (fclose (f) != 0) return 12; + if (remove ("conftest.txt") != 0) return 13; + return 0;])], [gl_cv_func_fpurge_works=yes], [gl_cv_func_fpurge_works=no], [gl_cv_func_fpurge_works='guessing no'])]) if test "x$gl_cv_func_fpurge_works" != xyes; then diff --git a/m4/free.m4 b/m4/free.m4 index 05c3038df..ef6022b84 100644 --- a/m4/free.m4 +++ b/m4/free.m4 @@ -20,12 +20,12 @@ AC_DEFUN([gl_FUNC_FREE], [gl_cv_func_free], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[@%:@include ]], - [[@%:@if _POSIX_VERSION < 199009L && \ - (defined unix || defined _unix || defined _unix_ \ - || defined __unix || defined __unix__) - @%:@error "'free (NULL)' is not known to work" - @%:@endif]])], + [[@%:@include ]], + [[@%:@if _POSIX_VERSION < 199009L && \ + (defined unix || defined _unix || defined _unix_ \ + || defined __unix || defined __unix__) + @%:@error "'free (NULL)' is not known to work" + @%:@endif]])], [gl_cv_func_free=yes], [gl_cv_func_free=no])]) diff --git a/m4/fseeko.m4 b/m4/fseeko.m4 index a370648e9..feba6ab8e 100644 --- a/m4/fseeko.m4 +++ b/m4/fseeko.m4 @@ -17,7 +17,7 @@ AC_DEFUN([gl_FUNC_FSEEKO], [ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [fseeko (stdin, 0, 0);])], - [gl_cv_func_fseeko=yes], [gl_cv_func_fseeko=no]) + [gl_cv_func_fseeko=yes], [gl_cv_func_fseeko=no]) ]) if test $gl_cv_func_fseeko = no; then HAVE_FSEEKO=0 diff --git a/m4/fsusage.m4 b/m4/fsusage.m4 index ae699dff9..b8b89e439 100644 --- a/m4/fsusage.m4 +++ b/m4/fsusage.m4 @@ -46,7 +46,7 @@ ac_fsusage_space=no if test $ac_fsusage_space = no; then # SVR4 AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs], - [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include #if defined __GLIBC__ && defined __linux__ Do not use statvfs on systems with GNU libc on Linux, because that function stats all preceding entries in /proc/mounts, and that makes df hang if even @@ -60,13 +60,13 @@ a system call. #endif #include ]], - [[struct statvfs fsd; statvfs (0, &fsd);]])], - [fu_cv_sys_stat_statvfs=yes], - [fu_cv_sys_stat_statvfs=no])]) + [[struct statvfs fsd; statvfs (0, &fsd);]])], + [fu_cv_sys_stat_statvfs=yes], + [fu_cv_sys_stat_statvfs=no])]) if test $fu_cv_sys_stat_statvfs = yes; then ac_fsusage_space=yes AC_DEFINE([STAT_STATVFS], [1], - [ Define if there is a function named statvfs. (SVR4)]) + [ Define if there is a function named statvfs. (SVR4)]) fi fi @@ -92,7 +92,7 @@ if test $ac_fsusage_space = no; then if test $fu_cv_sys_stat_statfs3_osf1 = yes; then ac_fsusage_space=yes AC_DEFINE([STAT_STATFS3_OSF1], [1], - [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)]) + [ Define if statfs takes 3 args. (DEC Alpha running OSF/1)]) fi fi @@ -150,7 +150,7 @@ if test $ac_fsusage_space = no; then if test $fu_cv_sys_stat_statfs4 = yes; then ac_fsusage_space=yes AC_DEFINE([STAT_STATFS4], [1], - [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)]) + [ Define if statfs takes 4 args. (SVR3, Dynix, Irix, Dolphin)]) fi fi diff --git a/m4/ftello.m4 b/m4/ftello.m4 index 51308ef53..7c3932200 100644 --- a/m4/ftello.m4 +++ b/m4/ftello.m4 @@ -16,7 +16,7 @@ AC_DEFUN([gl_FUNC_FTELLO], AC_CACHE_CHECK([for ftello], [gl_cv_func_ftello], [ AC_TRY_LINK([#include ], [ftello (stdin);], - [gl_cv_func_ftello=yes], [gl_cv_func_ftello=no]) + [gl_cv_func_ftello=yes], [gl_cv_func_ftello=no]) ]) if test $gl_cv_func_ftello = no; then HAVE_FTELLO=0 diff --git a/m4/ftruncate.m4 b/m4/ftruncate.m4 index e43c15f2a..8d9dabade 100644 --- a/m4/ftruncate.m4 +++ b/m4/ftruncate.m4 @@ -30,10 +30,10 @@ AC_DEFUN([gl_FUNC_FTRUNCATE], # a bug report to inform us about it. if test x"$SKIP_FTRUNCATE_CHECK" != xyes; then AC_MSG_FAILURE([Your system lacks the ftruncate function. - Please report this, along with the output of "uname -a", to the - bug-coreutils@gnu.org mailing list. To continue past this point, - rerun configure with SKIP_FTRUNCATE_CHECK=yes. - E.g., ./configure SKIP_FTRUNCATE_CHECK=yes]) + Please report this, along with the output of "uname -a", to the + bug-coreutils@gnu.org mailing list. To continue past this point, + rerun configure with SKIP_FTRUNCATE_CHECK=yes. + E.g., ./configure SKIP_FTRUNCATE_CHECK=yes]) fi esac fi diff --git a/m4/gc-random.m4 b/m4/gc-random.m4 index 3bbfdafab..2ca27a190 100644 --- a/m4/gc-random.m4 +++ b/m4/gc-random.m4 @@ -39,23 +39,23 @@ AC_DEFUN([gl_GC_RANDOM], AC_MSG_CHECKING([device with (strong) random data...]) AC_ARG_ENABLE([random-device], - AS_HELP_STRING([--enable-random-device], - [device with (strong) randomness (for Nettle)]), - NAME_OF_RANDOM_DEVICE=$enableval) + AS_HELP_STRING([--enable-random-device], + [device with (strong) randomness (for Nettle)]), + NAME_OF_RANDOM_DEVICE=$enableval) AC_MSG_RESULT([$NAME_OF_RANDOM_DEVICE]) AC_MSG_CHECKING([device with pseudo random data...]) AC_ARG_ENABLE([pseudo-random-device], - AS_HELP_STRING([--enable-pseudo-random-device], - [device with pseudo randomness (for Nettle)]), - NAME_OF_PSEUDO_RANDOM_DEVICE=$enableval) + AS_HELP_STRING([--enable-pseudo-random-device], + [device with pseudo randomness (for Nettle)]), + NAME_OF_PSEUDO_RANDOM_DEVICE=$enableval) AC_MSG_RESULT([$NAME_OF_PSEUDO_RANDOM_DEVICE]) AC_MSG_CHECKING([device with unpredictable data for nonces...]) AC_ARG_ENABLE([nonce-device], - AS_HELP_STRING([--enable-nonce-device], - [device with unpredictable nonces (for Nettle)]), - NAME_OF_NONCE_DEVICE=$enableval) + AS_HELP_STRING([--enable-nonce-device], + [device with unpredictable nonces (for Nettle)]), + NAME_OF_NONCE_DEVICE=$enableval) AC_MSG_RESULT([$NAME_OF_NONCE_DEVICE]) if test "$cross_compiling" != yes; then @@ -80,7 +80,7 @@ AC_DEFUN([gl_GC_RANDOM], AC_DEFINE_UNQUOTED([NAME_OF_RANDOM_DEVICE], ["$NAME_OF_RANDOM_DEVICE"], [defined to the name of the (strong) random device]) AC_DEFINE_UNQUOTED([NAME_OF_PSEUDO_RANDOM_DEVICE], - "$NAME_OF_PSEUDO_RANDOM_DEVICE", + "$NAME_OF_PSEUDO_RANDOM_DEVICE", [defined to the name of the pseudo random device]) AC_DEFINE_UNQUOTED([NAME_OF_NONCE_DEVICE], ["$NAME_OF_NONCE_DEVICE"], [defined to the name of the unpredictable nonce device]) diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4 index 526dce5ba..4445072fc 100644 --- a/m4/getaddrinfo.m4 +++ b/m4/getaddrinfo.m4 @@ -39,7 +39,7 @@ AC_DEFUN([gl_GETADDRINFO], [gl_cv_func_getaddrinfo=no])]) if test $gl_cv_func_getaddrinfo = no; then AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32], - gl_cv_w32_getaddrinfo, [ + gl_cv_w32_getaddrinfo, [ gl_cv_w32_getaddrinfo=no am_save_LIBS="$LIBS" LIBS="$LIBS -lws2_32" diff --git a/m4/getcwd-abort-bug.m4 b/m4/getcwd-abort-bug.m4 index 07e2c18cc..4660460fb 100644 --- a/m4/getcwd-abort-bug.m4 +++ b/m4/getcwd-abort-bug.m4 @@ -23,7 +23,7 @@ AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG], ac_clean_files="$ac_clean_files confdir-14B---" AC_RUN_IFELSE( [AC_LANG_SOURCE( - [[ + [[ #include #include #include @@ -69,14 +69,14 @@ main () initial_cwd_len = strlen (cwd); free (cwd); desired_depth = ((TARGET_LEN - 1 - initial_cwd_len) - / (1 + strlen (dir_name))); + / (1 + strlen (dir_name))); for (d = 0; d < desired_depth; d++) { if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0) - { - fail = 3; /* Unable to construct deep hierarchy. */ - break; - } + { + fail = 3; /* Unable to construct deep hierarchy. */ + break; + } } /* If libc has the bug in question, this invocation of getcwd @@ -91,7 +91,7 @@ main () while (0 < d--) { if (chdir ("..") < 0) - break; + break; rmdir (dir_name); } diff --git a/m4/getcwd-path-max.m4 b/m4/getcwd-path-max.m4 index 14784999d..b2be01cb4 100644 --- a/m4/getcwd-path-max.m4 +++ b/m4/getcwd-path-max.m4 @@ -23,7 +23,7 @@ AC_DEFUN([gl_FUNC_GETCWD_PATH_MAX], ac_clean_files="$ac_clean_files confdir3" AC_RUN_IFELSE( [AC_LANG_SOURCE( - [[ + [[ #include #include #include @@ -77,7 +77,7 @@ main () exit (0); #else char buf[PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1) - + DIR_NAME_SIZE + BUF_SLOP]; + + DIR_NAME_SIZE + BUF_SLOP]; char *cwd = getcwd (buf, PATH_MAX); size_t initial_cwd_len; size_t cwd_len; @@ -96,58 +96,58 @@ main () cwd_len += DIR_NAME_SIZE; /* If mkdir or chdir fails, it could be that this system cannot create - any file with an absolute name longer than PATH_MAX, such as cygwin. - If so, leave fail as 0, because the current working directory can't - be too long for getcwd if it can't even be created. For other - errors, be pessimistic and consider that as a failure, too. */ + any file with an absolute name longer than PATH_MAX, such as cygwin. + If so, leave fail as 0, because the current working directory can't + be too long for getcwd if it can't even be created. For other + errors, be pessimistic and consider that as a failure, too. */ if (mkdir (DIR_NAME, S_IRWXU) < 0 || chdir (DIR_NAME) < 0) - { - if (! (errno == ERANGE || is_ENAMETOOLONG (errno))) - fail = 2; - break; - } + { + if (! (errno == ERANGE || is_ENAMETOOLONG (errno))) + fail = 2; + break; + } if (PATH_MAX <= cwd_len && cwd_len < PATH_MAX + DIR_NAME_SIZE) - { - c = getcwd (buf, PATH_MAX); - if (!c && errno == ENOENT) - { - fail = 1; - break; - } - if (c || ! (errno == ERANGE || is_ENAMETOOLONG (errno))) - { - fail = 2; - break; - } - } + { + c = getcwd (buf, PATH_MAX); + if (!c && errno == ENOENT) + { + fail = 1; + break; + } + if (c || ! (errno == ERANGE || is_ENAMETOOLONG (errno))) + { + fail = 2; + break; + } + } if (dotdot_max <= cwd_len - initial_cwd_len) - { - if (dotdot_max + DIR_NAME_SIZE < cwd_len - initial_cwd_len) - break; - c = getcwd (buf, cwd_len + 1); - if (!c) - { - if (! (errno == ERANGE || errno == ENOENT - || is_ENAMETOOLONG (errno))) - { - fail = 2; - break; - } - if (AT_FDCWD || errno == ERANGE || errno == ENOENT) - { - fail = 1; - break; - } - } - } + { + if (dotdot_max + DIR_NAME_SIZE < cwd_len - initial_cwd_len) + break; + c = getcwd (buf, cwd_len + 1); + if (!c) + { + if (! (errno == ERANGE || errno == ENOENT + || is_ENAMETOOLONG (errno))) + { + fail = 2; + break; + } + if (AT_FDCWD || errno == ERANGE || errno == ENOENT) + { + fail = 1; + break; + } + } + } if (c && strlen (c) != cwd_len) - { - fail = 2; - break; - } + { + fail = 2; + break; + } ++n_chdirs; } @@ -161,10 +161,10 @@ main () rmdir (DIR_NAME); for (i = 0; i <= n_chdirs; i++) { - if (chdir ("..") < 0) - break; - if (rmdir (DIR_NAME) != 0) - break; + if (chdir ("..") < 0) + break; + if (rmdir (DIR_NAME) != 0) + break; } } diff --git a/m4/getcwd.m4 b/m4/getcwd.m4 index 4b8c4c6ce..abbb0dc1c 100644 --- a/m4/getcwd.m4 +++ b/m4/getcwd.m4 @@ -14,26 +14,26 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL], AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result], [gl_cv_func_getcwd_null], [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ -# include -# ifndef getcwd - char *getcwd (); -# endif +# include +# ifndef getcwd + char *getcwd (); +# endif ]], [[ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* mingw cwd does not start with '/', but getcwd does allocate. */ #else - if (chdir ("/") != 0) - return 1; - else - { - char *f = getcwd (NULL, 0); - return ! (f && f[0] == '/' && !f[1]); - } + if (chdir ("/") != 0) + return 1; + else + { + char *f = getcwd (NULL, 0); + return ! (f && f[0] == '/' && !f[1]); + } #endif - ]])], - [gl_cv_func_getcwd_null=yes], - [gl_cv_func_getcwd_null=no], - [[ + ]])], + [gl_cv_func_getcwd_null=yes], + [gl_cv_func_getcwd_null=no], + [[ case "$host_os" in # Guess yes on glibc systems. *-gnu*) gl_cv_func_getcwd_null="guessing yes";; @@ -44,7 +44,7 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL], # If we don't know, assume the worst. *) gl_cv_func_getcwd_null="guessing no";; esac - ]])]) + ]])]) ]) AC_DEFUN([gl_FUNC_GETCWD], diff --git a/m4/gethrxtime.m4 b/m4/gethrxtime.m4 index ef1758183..33eaec5e4 100644 --- a/m4/gethrxtime.m4 +++ b/m4/gethrxtime.m4 @@ -31,7 +31,7 @@ AC_DEFUN([gl_ARITHMETIC_HRTIME_T], AC_CACHE_CHECK([for arithmetic hrtime_t], [gl_cv_arithmetic_hrtime_t], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[#include ]], - [[hrtime_t x = 0; return x/x;]])], + [[hrtime_t x = 0; return x/x;]])], [gl_cv_arithmetic_hrtime_t=yes], [gl_cv_arithmetic_hrtime_t=no])]) if test $gl_cv_arithmetic_hrtime_t = yes; then @@ -59,14 +59,14 @@ AC_DEFUN([gl_PREREQ_GETHRXTIME], AC_CACHE_CHECK([whether CLOCK_MONOTONIC or CLOCK_REALTIME is defined], gl_cv_have_clock_gettime_macro, [AC_EGREP_CPP([have_clock_gettime_macro], - [ + [ # include # if defined CLOCK_MONOTONIC || defined CLOCK_REALTIME - have_clock_gettime_macro + have_clock_gettime_macro # endif - ], - gl_cv_have_clock_gettime_macro=yes, - gl_cv_have_clock_gettime_macro=no)]) + ], + gl_cv_have_clock_gettime_macro=yes, + gl_cv_have_clock_gettime_macro=no)]) if test $gl_cv_have_clock_gettime_macro = yes; then LIB_GETHRXTIME=$LIB_CLOCK_GETTIME fi diff --git a/m4/getline.m4 b/m4/getline.m4 index 4897bc369..fd01a493c 100644 --- a/m4/getline.m4 +++ b/m4/getline.m4 @@ -23,9 +23,9 @@ AC_DEFUN([gl_FUNC_GETLINE], gl_getline_needs_run_time_check=no AC_CHECK_FUNC([getline], - dnl Found it in some library. Verify that it works. - gl_getline_needs_run_time_check=yes, - am_cv_func_working_getline=no) + dnl Found it in some library. Verify that it works. + gl_getline_needs_run_time_check=yes, + am_cv_func_working_getline=no) if test $gl_getline_needs_run_time_check = yes; then AC_CACHE_CHECK([for working getline function], [am_cv_func_working_getline], [echo fooN |tr -d '\012'|tr N '\012' > conftest.data @@ -40,7 +40,7 @@ AC_DEFUN([gl_FUNC_GETLINE], int len; FILE *in = fopen ("./conftest.data", "r"); if (!in) - return 1; + return 1; len = getline (&line, &siz, in); exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1); } diff --git a/m4/getloadavg.m4 b/m4/getloadavg.m4 index dc4226a30..694976d7a 100644 --- a/m4/getloadavg.m4 +++ b/m4/getloadavg.m4 @@ -60,17 +60,17 @@ if test $gl_have_func = no; then gl_getloadavg_LIBS=$LIBS LIBS="-L/usr/local/lib $LIBS" AC_CHECK_LIB([getloadavg], [getloadavg], - [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS]) + [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS]) fi # Make sure it is really in the library, if we think we found it, # otherwise set up the replacement function. AC_CHECK_FUNCS([getloadavg], [], - [gl_PREREQ_GETLOADAVG]) + [gl_PREREQ_GETLOADAVG]) # Some definitions of getloadavg require that the program be installed setgid. AC_CACHE_CHECK([whether getloadavg requires setgid], - gl_cv_func_getloadavg_setgid, + gl_cv_func_getloadavg_setgid, [AC_EGREP_CPP([Yowza Am I SETGID yet], [#define CONFIGURING_GETLOADAVG #include "$srcdir/$1/getloadavg.c" @@ -78,13 +78,13 @@ AC_CACHE_CHECK([whether getloadavg requires setgid], Yowza Am I SETGID yet #endif ], - gl_cv_func_getloadavg_setgid=yes, - gl_cv_func_getloadavg_setgid=no)]) + gl_cv_func_getloadavg_setgid=yes, + gl_cv_func_getloadavg_setgid=no)]) if test $gl_cv_func_getloadavg_setgid = yes; then NEED_SETGID=true AC_DEFINE([GETLOADAVG_PRIVILEGED], [1], - [Define to 1 if the `getloadavg' function needs to be run setuid - or setgid.]) + [Define to 1 if the `getloadavg' function needs to be run setuid + or setgid.]) else NEED_SETGID=false fi @@ -98,8 +98,8 @@ if test $gl_cv_func_getloadavg_setgid = yes; then test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem` gl_cv_group_kmem=`echo $ac_ls_output \ | sed -ne ['s/[ ][ ]*/ /g - s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/ - / /s/.* //;p']` + s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/ + / /s/.* //;p']` ]) AC_SUBST([KMEM_GROUP], [$gl_cv_group_kmem])dnl fi @@ -154,8 +154,8 @@ if test $gl_have_func = no; then [gl_have_func=yes AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.]) AC_DEFINE([UMAX4_3], [1], - [Define to 1 for Encore UMAX 4.3 that has - instead of .])]) + [Define to 1 for Encore UMAX 4.3 that has + instead of .])]) fi if test $gl_have_func = no; then @@ -169,18 +169,18 @@ fi AC_CHECK_HEADERS([nlist.h], [AC_CHECK_MEMBERS([struct nlist.n_un.n_name], - [AC_DEFINE([NLIST_NAME_UNION], [1], - [Define to 1 if your `struct nlist' has an - `n_un' member. Obsolete, depend on - `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [], - [@%:@include ]) + [AC_DEFINE([NLIST_NAME_UNION], [1], + [Define to 1 if your `struct nlist' has an + `n_un' member. Obsolete, depend on + `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [], + [@%:@include ]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[struct nlist x; - #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME - x.n_un.n_name = ""; - #else - x.n_name = ""; - #endif]])], + [[struct nlist x; + #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME + x.n_un.n_name = ""; + #else + x.n_name = ""; + #endif]])], [AC_DEFINE([N_NAME_POINTER], [1], [Define to 1 if the nlist n_name member is a pointer])]) ])dnl diff --git a/m4/getopt.m4 b/m4/getopt.m4 index 264b57f9f..58098160c 100644 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -191,9 +191,9 @@ main () POSIXLY_CORRECT=1 export POSIXLY_CORRECT AC_RUN_IFELSE( - [AC_LANG_PROGRAM([[#include - #include - #include + [AC_LANG_PROGRAM([[#include + #include + #include #if !HAVE_DECL_OPTRESET # define OPTIND_MIN 0 #else @@ -238,10 +238,10 @@ main () return 7; } return 0; - ]])], - [gl_cv_func_getopt_gnu=yes], - [gl_cv_func_getopt_gnu=no], - [dnl Cross compiling. Guess based on host and declarations. + ]])], + [gl_cv_func_getopt_gnu=yes], + [gl_cv_func_getopt_gnu=no], + [dnl Cross compiling. Guess based on host and declarations. case $host_os:$ac_cv_have_decl_optreset in *-gnu*:* | mingw*:*) gl_cv_func_getopt_gnu=no;; *:yes) gl_cv_func_getopt_gnu=no;; diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4 index 0fec7d42b..ad519630b 100644 --- a/m4/gettimeofday.m4 +++ b/m4/gettimeofday.m4 @@ -17,16 +17,16 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY], [gl_cv_func_gettimeofday_posix_signature], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[#include - struct timeval c; - ]], - [[ - int (*f) (struct timeval *restrict, void *restrict) = gettimeofday; - int x = f (&c, 0); - return !(x | c.tv_sec | c.tv_usec); - ]])], - [gl_cv_func_gettimeofday_posix_signature=yes], - [gl_cv_func_gettimeofday_posix_signature=no])]) + [[#include + struct timeval c; + ]], + [[ + int (*f) (struct timeval *restrict, void *restrict) = gettimeofday; + int x = f (&c, 0); + return !(x | c.tv_sec | c.tv_usec); + ]])], + [gl_cv_func_gettimeofday_posix_signature=yes], + [gl_cv_func_gettimeofday_posix_signature=no])]) gl_FUNC_GETTIMEOFDAY_CLOBBER @@ -56,21 +56,21 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER], [gl_cv_func_gettimeofday_clobber], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( - [[#include - #include - #include - #include - ]], - [[ - time_t t = 0; - struct tm *lt; - struct tm saved_lt; - struct timeval tv; - lt = localtime (&t); - saved_lt = *lt; - gettimeofday (&tv, NULL); - return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0; - ]])], + [[#include + #include + #include + #include + ]], + [[ + time_t t = 0; + struct tm *lt; + struct tm saved_lt; + struct timeval tv; + lt = localtime (&t); + saved_lt = *lt; + gettimeofday (&tv, NULL); + return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0; + ]])], [gl_cv_func_gettimeofday_clobber=no], [gl_cv_func_gettimeofday_clobber=yes], dnl When crosscompiling, assume it is broken. diff --git a/m4/glibc2.m4 b/m4/glibc2.m4 index fe58a0f32..3435aa233 100644 --- a/m4/glibc2.m4 +++ b/m4/glibc2.m4 @@ -12,16 +12,16 @@ AC_DEFUN([gt_GLIBC2], AC_CACHE_CHECK([whether we are using the GNU C Library 2 or newer], [ac_cv_gnu_library_2], [AC_EGREP_CPP([Lucky GNU user], - [ + [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ >= 2) Lucky GNU user #endif #endif - ], - [ac_cv_gnu_library_2=yes], - [ac_cv_gnu_library_2=no]) + ], + [ac_cv_gnu_library_2=yes], + [ac_cv_gnu_library_2=no]) ] ) AC_SUBST([GLIBC2]) diff --git a/m4/glibc21.m4 b/m4/glibc21.m4 index 93fbf4745..12cddfe8b 100644 --- a/m4/glibc21.m4 +++ b/m4/glibc21.m4 @@ -12,16 +12,16 @@ AC_DEFUN([gl_GLIBC21], AC_CACHE_CHECK([whether we are using the GNU C Library 2.1 or newer], [ac_cv_gnu_library_2_1], [AC_EGREP_CPP([Lucky GNU user], - [ + [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) Lucky GNU user #endif #endif - ], - [ac_cv_gnu_library_2_1=yes], - [ac_cv_gnu_library_2_1=no]) + ], + [ac_cv_gnu_library_2_1=yes], + [ac_cv_gnu_library_2_1=no]) ] ) AC_SUBST([GLIBC21]) diff --git a/m4/glob.m4 b/m4/glob.m4 index bc3e67cff..b0330bd07 100644 --- a/m4/glob.m4 +++ b/m4/glob.m4 @@ -27,8 +27,8 @@ AC_DEFUN([gl_GLOB], [ AC_COMPILE_IFELSE( [[#include char a[_GNU_GLOB_INTERFACE_VERSION == 1 ? 1 : -1];]], - [gl_cv_gnu_glob_interface_version_1=yes], - [gl_cv_gnu_glob_interface_version_1=no])]) + [gl_cv_gnu_glob_interface_version_1=yes], + [gl_cv_gnu_glob_interface_version_1=no])]) if test "$gl_cv_gnu_glob_interface_version_1" = "no"; then GLOB_H=glob.h diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index c8fda2033..75da53db0 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -70,13 +70,13 @@ AC_DEFUN([AC_C_RESTRICT], for ac_kw in __restrict __restrict__ _Restrict restrict; do AC_COMPILE_IFELSE([AC_LANG_PROGRAM( [[typedef int * int_ptr; - int foo (int_ptr $ac_kw ip) { - return ip[0]; + int foo (int_ptr $ac_kw ip) { + return ip[0]; }]], [[int s[1]; - int * $ac_kw t = s; - t[0] = 0; - return foo(t)]])], + int * $ac_kw t = s; + t[0] = 0; + return foo(t)]])], [ac_cv_c_restrict=$ac_kw]) test "$ac_cv_c_restrict" != no && break done diff --git a/m4/host-os.m4 b/m4/host-os.m4 index 375210bb6..df40be241 100644 --- a/m4/host-os.m4 +++ b/m4/host-os.m4 @@ -20,60 +20,60 @@ AC_DEFUN([gl_HOST_OS], # These operating system names do not use the default heuristic below. # They are in reverse order, so that more-specific prefixes come first. - winnt*) os='Windows NT';; - vos*) os='VOS';; - sysv*) os='Unix System V';; - superux*) os='SUPER-UX';; - sunos*) os='SunOS';; - stop*) os='STOP';; - sco*) os='SCO Unix';; - riscos*) os='RISC OS';; - riscix*) os='RISCiX';; - qnx*) os='QNX';; - pw32*) os='PW32';; - ptx*) os='ptx';; - plan9*) os='Plan 9';; - osf*) os='Tru64';; - os2*) os='OS/2';; - openbsd*) os='OpenBSD';; - nsk*) os='NonStop Kernel';; - nonstopux*) os='NonStop-UX';; - netbsd*-gnu*) os='GNU/NetBSD';; # NetBSD kernel+libc, GNU userland - netbsd*) os='NetBSD';; - knetbsd*-gnu) os='GNU/kNetBSD';; # NetBSD kernel, GNU libc+userland - kfreebsd*-gnu) os='GNU/kFreeBSD';; # FreeBSD kernel, GNU libc+userland - msdosdjgpp*) os='DJGPP';; - mpeix*) os='MPE/iX';; - mint*) os='MiNT';; - mingw*) os='MinGW';; - lynxos*) os='LynxOS';; - linux*) os='GNU/Linux';; - hpux*) os='HP-UX';; - hiux*) os='HI-UX';; - gnu*) os='GNU';; - freebsd*) os='FreeBSD';; - dgux*) os='DG/UX';; - bsdi*) os='BSD/OS';; - bsd*) os='BSD';; - beos*) os='BeOS';; - aux*) os='A/UX';; - atheos*) os='AtheOS';; - amigaos*) os='Amiga OS';; - aix*) os='AIX';; + winnt*) os='Windows NT';; + vos*) os='VOS';; + sysv*) os='Unix System V';; + superux*) os='SUPER-UX';; + sunos*) os='SunOS';; + stop*) os='STOP';; + sco*) os='SCO Unix';; + riscos*) os='RISC OS';; + riscix*) os='RISCiX';; + qnx*) os='QNX';; + pw32*) os='PW32';; + ptx*) os='ptx';; + plan9*) os='Plan 9';; + osf*) os='Tru64';; + os2*) os='OS/2';; + openbsd*) os='OpenBSD';; + nsk*) os='NonStop Kernel';; + nonstopux*) os='NonStop-UX';; + netbsd*-gnu*) os='GNU/NetBSD';; # NetBSD kernel+libc, GNU userland + netbsd*) os='NetBSD';; + knetbsd*-gnu) os='GNU/kNetBSD';; # NetBSD kernel, GNU libc+userland + kfreebsd*-gnu) os='GNU/kFreeBSD';; # FreeBSD kernel, GNU libc+userland + msdosdjgpp*) os='DJGPP';; + mpeix*) os='MPE/iX';; + mint*) os='MiNT';; + mingw*) os='MinGW';; + lynxos*) os='LynxOS';; + linux*) os='GNU/Linux';; + hpux*) os='HP-UX';; + hiux*) os='HI-UX';; + gnu*) os='GNU';; + freebsd*) os='FreeBSD';; + dgux*) os='DG/UX';; + bsdi*) os='BSD/OS';; + bsd*) os='BSD';; + beos*) os='BeOS';; + aux*) os='A/UX';; + atheos*) os='AtheOS';; + amigaos*) os='Amiga OS';; + aix*) os='AIX';; # The default heuristic takes the initial alphabetic string # from $host_os, but capitalizes its first letter. [A-Za-z]*) - os=` - expr "X$host_os" : 'X\([A-Za-z]\)' | tr '[a-z]' '[A-Z]' - `` - expr "X$host_os" : 'X.\([A-Za-z]*\)' - ` - ;; + os=` + expr "X$host_os" : 'X\([A-Za-z]\)' | tr '[a-z]' '[A-Z]' + `` + expr "X$host_os" : 'X.\([A-Za-z]*\)' + ` + ;; # If $host_os does not start with an alphabetic string, use it unchanged. *) - os=$host_os;; + os=$host_os;; esac gl_cv_host_operating_system=$os]]) AC_DEFINE_UNQUOTED([HOST_OPERATING_SYSTEM], diff --git a/m4/iconv_open.m4 b/m4/iconv_open.m4 index 8eeef9fcf..6bf78bc5e 100644 --- a/m4/iconv_open.m4 +++ b/m4/iconv_open.m4 @@ -90,8 +90,8 @@ int main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -117,8 +117,8 @@ int main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -144,8 +144,8 @@ int main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -171,8 +171,8 @@ int main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -199,8 +199,8 @@ int main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); diff --git a/m4/include_next.m4 b/m4/include_next.m4 index 5e22ded93..2e6273f83 100644 --- a/m4/include_next.m4 +++ b/m4/include_next.m4 @@ -109,11 +109,11 @@ EOF # be # '"///usr/include/foo.h"', or whatever other absolute file name is suitable. # That way, a header file with the following line: -# #@INCLUDE_NEXT@ @NEXT_FOO_H@ +# #@INCLUDE_NEXT@ @NEXT_FOO_H@ # or -# #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@ +# #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@ # behaves (after sed substitution) as if it contained -# #include_next +# #include_next # even if the compiler does not support include_next. # The three "///" are to pacify Sun C 5.8, which otherwise would say # "warning: #include of /usr/include/... may be non-portable". @@ -129,46 +129,46 @@ AC_DEFUN([gl_CHECK_NEXT_HEADERS], m4_foreach_w([gl_HEADER_NAME], [$1], [AS_VAR_PUSHDEF([gl_next_header], - [gl_cv_next_]m4_defn([gl_HEADER_NAME])) + [gl_cv_next_]m4_defn([gl_HEADER_NAME])) if test $gl_cv_have_include_next = yes; then AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) else AC_CACHE_CHECK( - [absolute name of <]m4_defn([gl_HEADER_NAME])[>], - m4_defn([gl_next_header]), - [AS_VAR_PUSHDEF([gl_header_exists], - [ac_cv_header_]m4_defn([gl_HEADER_NAME])) - if test AS_VAR_GET(gl_header_exists) = yes; then - AC_LANG_CONFTEST( - [AC_LANG_SOURCE( - [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] - )]) - dnl AIX "xlc -E" and "cc -E" omit #line directives for header files - dnl that contain only a #include of other header files and no - dnl non-comment tokens of their own. This leads to a failure to - dnl detect the absolute name of , , - dnl and others. The workaround is to force preservation of comments - dnl through option -C. This ensures all necessary #line directives - dnl are present. GCC supports option -C as well. - case "$host_os" in - aix*) gl_absname_cpp="$ac_cpp -C" ;; - *) gl_absname_cpp="$ac_cpp" ;; - esac - dnl eval is necessary to expand gl_absname_cpp. - dnl Ultrix and Pyramid sh refuse to redirect output of eval, - dnl so use subshell. - AS_VAR_SET([gl_next_header], - ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | - sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{ - s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1# - s#^/[^/]#//&# - p - q - }'`'"']) - else - AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) - fi - AS_VAR_POPDEF([gl_header_exists])]) + [absolute name of <]m4_defn([gl_HEADER_NAME])[>], + m4_defn([gl_next_header]), + [AS_VAR_PUSHDEF([gl_header_exists], + [ac_cv_header_]m4_defn([gl_HEADER_NAME])) + if test AS_VAR_GET(gl_header_exists) = yes; then + AC_LANG_CONFTEST( + [AC_LANG_SOURCE( + [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] + )]) + dnl AIX "xlc -E" and "cc -E" omit #line directives for header files + dnl that contain only a #include of other header files and no + dnl non-comment tokens of their own. This leads to a failure to + dnl detect the absolute name of , , + dnl and others. The workaround is to force preservation of comments + dnl through option -C. This ensures all necessary #line directives + dnl are present. GCC supports option -C as well. + case "$host_os" in + aix*) gl_absname_cpp="$ac_cpp -C" ;; + *) gl_absname_cpp="$ac_cpp" ;; + esac + dnl eval is necessary to expand gl_absname_cpp. + dnl Ultrix and Pyramid sh refuse to redirect output of eval, + dnl so use subshell. + AS_VAR_SET([gl_next_header], + ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | + sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{ + s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1# + s#^/[^/]#//&# + p + q + }'`'"']) + else + AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) + fi + AS_VAR_POPDEF([gl_header_exists])]) fi AC_SUBST( AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])), diff --git a/m4/inttypes.m4 b/m4/inttypes.m4 index 8b4e4f852..e1c656d14 100644 --- a/m4/inttypes.m4 +++ b/m4/inttypes.m4 @@ -26,13 +26,13 @@ AC_DEFUN([gl_INTTYPES_H], [gl_cv_header_working_inttypes_h], [gl_cv_header_working_inttypes_h=no if test "$gl_cv_header_working_stdint_h" = yes \ - && test $ac_cv_header_inttypes_h = yes \ - && test "$ac_cv_have_decl_imaxabs" = yes \ - && test "$ac_cv_have_decl_imaxdiv" = yes \ - && test "$ac_cv_have_decl_strtoimax" = yes \ - && test "$ac_cv_have_decl_strtoumax" = yes; then + && test $ac_cv_header_inttypes_h = yes \ + && test "$ac_cv_have_decl_imaxabs" = yes \ + && test "$ac_cv_have_decl_imaxdiv" = yes \ + && test "$ac_cv_have_decl_strtoimax" = yes \ + && test "$ac_cv_have_decl_strtoumax" = yes; then AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([[ + AC_LANG_PROGRAM([[ #include #define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */ #define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */ @@ -131,8 +131,8 @@ const char *l = /* implicit string concatenation */ SCNoPTR SCNuPTR SCNxPTR #endif ; - ]])], - [gl_cv_header_working_inttypes_h=yes]) + ]])], + [gl_cv_header_working_inttypes_h=yes]) fi]) dnl Override always, so that the portability warnings work. @@ -255,25 +255,25 @@ AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION], [gl_cv_test_$1], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[/* Work also in C++ mode. */ - #define __STDC_LIMIT_MACROS 1 + [[/* Work also in C++ mode. */ + #define __STDC_LIMIT_MACROS 1 - /* Work if build is not clean. */ - #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H + /* Work if build is not clean. */ + #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H - #include - #if HAVE_STDINT_H - #include - #endif + #include + #if HAVE_STDINT_H + #include + #endif - #if $2 - #define CONDITION ($3) - #elif HAVE_LONG_LONG_INT - #define CONDITION ($4) - #else - #define CONDITION 0 - #endif - int test[CONDITION ? 1 : -1];]])], + #if $2 + #define CONDITION ($3) + #elif HAVE_LONG_LONG_INT + #define CONDITION ($4) + #else + #define CONDITION 0 + #endif + int test[CONDITION ? 1 : -1];]])], [gl_cv_test_$1=yes], [gl_cv_test_$1=no])]) if test $gl_cv_test_$1 = yes; then diff --git a/m4/isapipe.m4 b/m4/isapipe.m4 index 1f0673666..8f7999cbd 100644 --- a/m4/isapipe.m4 +++ b/m4/isapipe.m4 @@ -24,50 +24,50 @@ AC_DEFUN([gl_PREREQ_ISAPIPE], [gl_cv_pipes_are_fifos], [AC_RUN_IFELSE( [AC_LANG_SOURCE( - [[#include - #include - #include - #include - #ifndef S_ISFIFO - #define S_ISFIFO(m) 0 - #endif - #ifndef S_ISSOCK - #define S_ISSOCK(m) 0 - #endif - int - main (int argc, char **argv) - { - int fd[2]; - struct stat st; - if (pipe (fd) != 0 || fstat (fd[0], &st) != 0) - return 1; - if (2 <= argc && argv[1][0] == '-') - { - char const *yesno = (S_ISFIFO (st.st_mode) ? "yes" : "no"); - if (st.st_nlink <= 1) - { - long int i = st.st_nlink; - if (i != st.st_nlink) - return 1; - printf ("%s (%ld)\n", yesno, i); - } - else - { - unsigned long int i = st.st_nlink; - if (i != st.st_nlink) - return 1; - printf ("%s (%lu)\n", yesno, i); - } - } - else - { - if (! S_ISFIFO (st.st_mode) && ! S_ISSOCK (st.st_mode)) - return 1; - } - return 0; - }]])], + [[#include + #include + #include + #include + #ifndef S_ISFIFO + #define S_ISFIFO(m) 0 + #endif + #ifndef S_ISSOCK + #define S_ISSOCK(m) 0 + #endif + int + main (int argc, char **argv) + { + int fd[2]; + struct stat st; + if (pipe (fd) != 0 || fstat (fd[0], &st) != 0) + return 1; + if (2 <= argc && argv[1][0] == '-') + { + char const *yesno = (S_ISFIFO (st.st_mode) ? "yes" : "no"); + if (st.st_nlink <= 1) + { + long int i = st.st_nlink; + if (i != st.st_nlink) + return 1; + printf ("%s (%ld)\n", yesno, i); + } + else + { + unsigned long int i = st.st_nlink; + if (i != st.st_nlink) + return 1; + printf ("%s (%lu)\n", yesno, i); + } + } + else + { + if (! S_ISFIFO (st.st_mode) && ! S_ISSOCK (st.st_mode)) + return 1; + } + return 0; + }]])], [gl_cv_pipes_are_fifos=`./conftest$ac_exeext -` - test -z "$gl_cv_pipes_are_fifos" && gl_cv_pipes_are_fifos=no], + test -z "$gl_cv_pipes_are_fifos" && gl_cv_pipes_are_fifos=no], [gl_cv_pipes_are_fifos=unknown], [gl_cv_pipes_are_fifos=cross-compiling])]) diff --git a/m4/isinf.m4 b/m4/isinf.m4 index 3d9423106..6edf48697 100644 --- a/m4/isinf.m4 +++ b/m4/isinf.m4 @@ -44,6 +44,6 @@ AC_DEFUN([gl_ISINFL_WORKS], [[return !!isinf(LDBL_MAX);]])], [gl_cv_func_isinfl_works=yes], [gl_cv_func_isinfl_works=no], - [gl_cv_func_isinfl_works="guessing no"]) + [gl_cv_func_isinfl_works="guessing no"]) ]) ]) diff --git a/m4/jm-winsz1.m4 b/m4/jm-winsz1.m4 index 7804c8a0d..4ae148f67 100644 --- a/m4/jm-winsz1.m4 +++ b/m4/jm-winsz1.m4 @@ -10,7 +10,7 @@ dnl From Jim Meyering and Paul Eggert. AC_DEFUN([gl_HEADER_TIOCGWINSZ_IN_TERMIOS_H], [AC_REQUIRE([AC_SYS_POSIX_TERMIOS]) AC_CACHE_CHECK([whether use of TIOCGWINSZ requires termios.h], - gl_cv_sys_tiocgwinsz_needs_termios_h, + gl_cv_sys_tiocgwinsz_needs_termios_h, [gl_cv_sys_tiocgwinsz_needs_termios_h=no if test $ac_cv_sys_posix_termios = yes; then @@ -31,16 +31,16 @@ AC_DEFUN([gl_WINSIZE_IN_PTEM], gl_cv_sys_struct_winsize_needs_sys_ptem_h, [gl_cv_sys_struct_winsize_needs_sys_ptem_h=yes if test $ac_cv_sys_posix_termios = yes; then - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[struct winsize x; - if (sizeof x > 0) return 0;]])], + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[struct winsize x; + if (sizeof x > 0) return 0;]])], [gl_cv_sys_struct_winsize_needs_sys_ptem_h=no]) fi if test $gl_cv_sys_struct_winsize_needs_sys_ptem_h = yes; then - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[struct winsize x; - if (sizeof x > 0) return 0;]])], - [], [gl_cv_sys_struct_winsize_needs_sys_ptem_h=no]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[struct winsize x; + if (sizeof x > 0) return 0;]])], + [], [gl_cv_sys_struct_winsize_needs_sys_ptem_h=no]) fi]) if test $gl_cv_sys_struct_winsize_needs_sys_ptem_h = yes; then AC_DEFINE([WINSIZE_IN_PTEM], [1], diff --git a/m4/jm-winsz2.m4 b/m4/jm-winsz2.m4 index f3155e72e..ba6424f8b 100644 --- a/m4/jm-winsz2.m4 +++ b/m4/jm-winsz2.m4 @@ -8,7 +8,7 @@ AC_DEFUN([gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL], [AC_REQUIRE([gl_HEADER_TIOCGWINSZ_IN_TERMIOS_H]) AC_CACHE_CHECK([whether use of TIOCGWINSZ requires sys/ioctl.h], - gl_cv_sys_tiocgwinsz_needs_sys_ioctl_h, + gl_cv_sys_tiocgwinsz_needs_sys_ioctl_h, [gl_cv_sys_tiocgwinsz_needs_sys_ioctl_h=no if test $gl_cv_sys_tiocgwinsz_needs_termios_h = no; then diff --git a/m4/ld-version-script.m4 b/m4/ld-version-script.m4 index a97888f24..43b725b4a 100644 --- a/m4/ld-version-script.m4 +++ b/m4/ld-version-script.m4 @@ -27,7 +27,7 @@ AC_DEFUN([gl_LD_VERSION_SCRIPT], LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" cat > conftest.map < /dev/null 2>&1; do - ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` + ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; @@ -89,9 +89,9 @@ AC_CACHE_VAL([acl_cv_path_LD], # Break only if it was the GNU/non-GNU ld that we prefer. case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in *GNU* | *'with BFD'*) - test "$with_gnu_ld" != no && break ;; + test "$with_gnu_ld" != no && break ;; *) - test "$with_gnu_ld" != yes && break ;; + test "$with_gnu_ld" != yes && break ;; esac fi done diff --git a/m4/link-follow.m4 b/m4/link-follow.m4 index d2c5dd998..8b7ca1117 100644 --- a/m4/link-follow.m4 +++ b/m4/link-follow.m4 @@ -23,7 +23,7 @@ AC_DEFUN([gl_FUNC_LINK_FOLLOWS_SYMLINK], gl_link_follows_symlinks=0 # assume GNU behavior if test $ac_cv_func_readlink = yes; then AC_CACHE_CHECK([whether link(2) dereferences a symlink], - gl_cv_func_link_follows_symlink, + gl_cv_func_link_follows_symlink, [ # Create a regular file. echo > conftest.file @@ -34,38 +34,38 @@ AC_DEFUN([gl_FUNC_LINK_FOLLOWS_SYMLINK], # include # define SAME_INODE(Stat_buf_1, Stat_buf_2) \ - ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \ - && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev) + ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \ + && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev) - int - main () - { - const char *file = "conftest.file"; - const char *sym = "conftest.sym"; - const char *hard = "conftest.hard"; - struct stat sb_file, sb_hard; + int + main () + { + const char *file = "conftest.file"; + const char *sym = "conftest.sym"; + const char *hard = "conftest.hard"; + struct stat sb_file, sb_hard; - /* Create a symlink to the regular file. */ - if (symlink (file, sym)) - return 2; + /* Create a symlink to the regular file. */ + if (symlink (file, sym)) + return 2; - /* Create a hard link to that symlink. */ - if (link (sym, hard)) - return 3; + /* Create a hard link to that symlink. */ + if (link (sym, hard)) + return 3; - if (lstat (hard, &sb_hard)) - return 4; - if (lstat (file, &sb_file)) - return 5; + if (lstat (hard, &sb_hard)) + return 4; + if (lstat (file, &sb_file)) + return 5; - /* If the dev/inode of hard and file are the same, then - the link call followed the symlink. */ - return SAME_INODE (sb_hard, sb_file) ? 1 : 0; - } + /* If the dev/inode of hard and file are the same, then + the link call followed the symlink. */ + return SAME_INODE (sb_hard, sb_file) ? 1 : 0; + } ]])], - [gl_cv_func_link_follows_symlink=no], dnl GNU behavior - [gl_cv_func_link_follows_symlink=yes], dnl Followed link/compile failed - [gl_cv_func_link_follows_symlink=unknown] dnl We're cross compiling. + [gl_cv_func_link_follows_symlink=no], dnl GNU behavior + [gl_cv_func_link_follows_symlink=yes], dnl Followed link/compile failed + [gl_cv_func_link_follows_symlink=unknown] dnl We're cross compiling. ) rm -f conftest.file conftest.sym conftest.hard ]) diff --git a/m4/longlong.m4 b/m4/longlong.m4 index eedc8d568..6d17ea373 100644 --- a/m4/longlong.m4 +++ b/m4/longlong.m4 @@ -20,30 +20,30 @@ AC_DEFUN([AC_TYPE_LONG_LONG_INT], [AC_LINK_IFELSE( [_AC_TYPE_LONG_LONG_SNIPPET], [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. - dnl If cross compiling, assume the bug isn't important, since - dnl nobody cross compiles for this platform as far as we know. - AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [[@%:@include - @%:@ifndef LLONG_MAX - @%:@ define HALF \ - (1LL << (sizeof (long long int) * CHAR_BIT - 2)) - @%:@ define LLONG_MAX (HALF - 1 + HALF) - @%:@endif]], - [[long long int n = 1; - int i; - for (i = 0; ; i++) - { - long long int m = n << i; - if (m >> i != n) - return 1; - if (LLONG_MAX / 2 < m) - break; - } - return 0;]])], - [ac_cv_type_long_long_int=yes], - [ac_cv_type_long_long_int=no], - [ac_cv_type_long_long_int=yes])], + dnl If cross compiling, assume the bug isn't important, since + dnl nobody cross compiles for this platform as far as we know. + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[@%:@include + @%:@ifndef LLONG_MAX + @%:@ define HALF \ + (1LL << (sizeof (long long int) * CHAR_BIT - 2)) + @%:@ define LLONG_MAX (HALF - 1 + HALF) + @%:@endif]], + [[long long int n = 1; + int i; + for (i = 0; ; i++) + { + long long int m = n << i; + if (m >> i != n) + return 1; + if (LLONG_MAX / 2 < m) + break; + } + return 0;]])], + [ac_cv_type_long_long_int=yes], + [ac_cv_type_long_long_int=no], + [ac_cv_type_long_long_int=yes])], [ac_cv_type_long_long_int=no])]) if test $ac_cv_type_long_long_int = yes; then AC_DEFINE([HAVE_LONG_LONG_INT], [1], @@ -83,24 +83,24 @@ AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET], [ AC_LANG_PROGRAM( [[/* For now, do not test the preprocessor; as of 2007 there are too many - implementations with broken preprocessors. Perhaps this can - be revisited in 2012. In the meantime, code should not expect - #if to work with literals wider than 32 bits. */ + implementations with broken preprocessors. Perhaps this can + be revisited in 2012. In the meantime, code should not expect + #if to work with literals wider than 32 bits. */ /* Test literals. */ long long int ll = 9223372036854775807ll; long long int nll = -9223372036854775807LL; unsigned long long int ull = 18446744073709551615ULL; /* Test constant expressions. */ typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll) - ? 1 : -1)]; + ? 1 : -1)]; typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1 - ? 1 : -1)]; + ? 1 : -1)]; int i = 63;]], [[/* Test availability of runtime routines for shift and division. */ long long int llmax = 9223372036854775807ll; unsigned long long int ullmax = 18446744073709551615ull; return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) - | (llmax / ll) | (llmax % ll) - | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) - | (ullmax / ull) | (ullmax % ull));]]) + | (llmax / ll) | (llmax % ll) + | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i) + | (ullmax / ull) | (ullmax % ull));]]) ]) diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4 index 42a7ade0a..48d16da80 100644 --- a/m4/ls-mntd-fs.m4 +++ b/m4/ls-mntd-fs.m4 @@ -84,7 +84,7 @@ if test -z "$ac_list_mounted_fs"; then yes #endif ], [test $ac_cv_func_listmntent = yes \ - && fu_cv_sys_mounted_cray_listmntent=yes] + && fu_cv_sys_mounted_cray_listmntent=yes] ) ] ) @@ -108,7 +108,7 @@ if test -z "$ac_list_mounted_fs"; then if test $fu_cv_sys_mounted_vmount = yes; then ac_list_mounted_fs=found AC_DEFINE([MOUNTED_VMOUNT], [1], - [Define if there is a function named mntctl that can be used to read + [Define if there is a function named mntctl that can be used to read the list of mounted file systems, and there is a system header file that declares `struct vmount.' (AIX)]) fi @@ -123,27 +123,27 @@ if test $ac_cv_func_getmntent = yes; then # 4.3BSD, SunOS, HP-UX, Dynix, Irix AC_MSG_CHECKING([for one-argument getmntent function]) AC_CACHE_VAL([fu_cv_sys_mounted_getmntent1], - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ /* SunOS 4.1.x /usr/include/mntent.h needs this for FILE */ #include #include #if !defined MOUNTED -# if defined _PATH_MOUNTED /* GNU libc */ +# if defined _PATH_MOUNTED /* GNU libc */ # define MOUNTED _PATH_MOUNTED # endif -# if defined MNT_MNTTAB /* HP-UX. */ +# if defined MNT_MNTTAB /* HP-UX. */ # define MOUNTED MNT_MNTTAB # endif -# if defined MNTTABNAME /* Dynix. */ +# if defined MNTTABNAME /* Dynix. */ # define MOUNTED MNTTABNAME # endif #endif ]], [[ struct mntent *mnt = 0; char *table = MOUNTED; if (sizeof mnt && sizeof table) return 0;]])], - [fu_cv_sys_mounted_getmntent1=yes], - [fu_cv_sys_mounted_getmntent1=no])]) + [fu_cv_sys_mounted_getmntent1=yes], + [fu_cv_sys_mounted_getmntent1=no])]) AC_MSG_RESULT([$fu_cv_sys_mounted_getmntent1]) if test $fu_cv_sys_mounted_getmntent1 = yes; then ac_list_mounted_fs=found @@ -197,7 +197,7 @@ $getfsstat_includes]] if test $fu_cv_sys_mounted_getfsstat = yes; then ac_list_mounted_fs=found AC_DEFINE([MOUNTED_GETFSSTAT], [1], - [Define if there is a function named getfsstat for reading the + [Define if there is a function named getfsstat for reading the list of mounted file systems. (DEC Alpha running OSF/1)]) fi fi @@ -228,8 +228,8 @@ if test -z "$ac_list_mounted_fs"; then AC_CACHE_VAL([fu_cv_sys_mounted_getmntinfo], [ test "$ac_cv_func_getmntinfo" = yes \ - && fu_cv_sys_mounted_getmntinfo=yes \ - || fu_cv_sys_mounted_getmntinfo=no + && fu_cv_sys_mounted_getmntinfo=yes \ + || fu_cv_sys_mounted_getmntinfo=no ]) AC_MSG_RESULT([$fu_cv_sys_mounted_getmntinfo]) if test $fu_cv_sys_mounted_getmntinfo = yes; then @@ -256,13 +256,13 @@ extern int getmntinfo (struct statfs **, int); if test $fu_cv_sys_mounted_getmntinfo2 = no; then ac_list_mounted_fs=found AC_DEFINE([MOUNTED_GETMNTINFO], [1], - [Define if there is a function named getmntinfo for reading the + [Define if there is a function named getmntinfo for reading the list of mounted file systems and it returns an array of 'struct statfs'. (4.4BSD, Darwin)]) else ac_list_mounted_fs=found AC_DEFINE([MOUNTED_GETMNTINFO2], [1], - [Define if there is a function named getmntinfo for reading the + [Define if there is a function named getmntinfo for reading the list of mounted file systems and it returns an array of 'struct statvfs'. (NetBSD 3.0)]) fi @@ -294,7 +294,7 @@ if test -z "$ac_list_mounted_fs"; then AC_MSG_CHECKING([for BEOS mounted file system support functions]) if test $ac_cv_header_fs_info_h = yes \ && test $ac_cv_func_next_dev = yes \ - && test $ac_cv_func_fs_stat_dev = yes; then + && test $ac_cv_func_fs_stat_dev = yes; then fu_result=yes else fu_result=no @@ -319,7 +319,7 @@ if test -z "$ac_list_mounted_fs"; then if test $fu_cv_sys_mounted_fread = yes; then ac_list_mounted_fs=found AC_DEFINE([MOUNTED_FREAD], [1], - [Define if there is no specific function for reading the list of + [Define if there is no specific function for reading the list of mounted file systems. fread will be used to read /etc/mnttab. (SVR2) ]) fi diff --git a/m4/lseek.m4 b/m4/lseek.m4 index f33699070..b40da70a2 100644 --- a/m4/lseek.m4 +++ b/m4/lseek.m4 @@ -19,21 +19,21 @@ int main () /* Exit with success only if stdin is seekable. */ return lseek (0, (off_t)0, SEEK_CUR) < 0; }], - [if test -s conftest$ac_exeext \ - && ./conftest$ac_exeext < conftest.$ac_ext \ - && { echo hi | ./conftest$ac_exeext; test $? = 1; }; then - gl_cv_func_lseek_pipe=yes - else - gl_cv_func_lseek_pipe=no - fi], - [gl_cv_func_lseek_pipe=no]) + [if test -s conftest$ac_exeext \ + && ./conftest$ac_exeext < conftest.$ac_ext \ + && { echo hi | ./conftest$ac_exeext; test $? = 1; }; then + gl_cv_func_lseek_pipe=yes + else + gl_cv_func_lseek_pipe=no + fi], + [gl_cv_func_lseek_pipe=no]) else AC_COMPILE_IFELSE([ #if ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) || defined __BEOS__ /* mingw and BeOS mistakenly return 0 when trying to seek on pipes. */ Choke me. #endif], - [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no]) + [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no]) fi]) if test $gl_cv_func_lseek_pipe = no; then gl_REPLACE_LSEEK @@ -46,5 +46,5 @@ AC_DEFUN([gl_REPLACE_LSEEK], AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) REPLACE_LSEEK=1 AC_DEFINE([LSEEK_PIPE_BROKEN], [1], - [Define to 1 if lseek does not detect pipes.]) + [Define to 1 if lseek does not detect pipes.]) ]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index d941bc334..50ce817a5 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -15,9 +15,9 @@ AC_DEFUN([gl_MATH_H], test only needs to fail when NAN is provided but wrong. */ float f = 1.0f; #ifdef NAN - f = NAN; + f = NAN; #endif - return f == 0;]])], + return f == 0;]])], [gl_cv_header_math_nan_works=yes], [gl_cv_header_math_nan_works=no])]) if test $gl_cv_header_math_nan_works = no; then @@ -26,8 +26,8 @@ AC_DEFUN([gl_MATH_H], AC_CACHE_CHECK([whether HUGE_VAL works], [gl_cv_header_math_huge_val_works], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], [[/* Solaris 10 has a broken definition of HUGE_VAL. */ - double d = HUGE_VAL; - return d == 0;]])], + double d = HUGE_VAL; + return d == 0;]])], [gl_cv_header_math_huge_val_works=yes], [gl_cv_header_math_huge_val_works=no])]) if test $gl_cv_header_math_huge_val_works = no; then diff --git a/m4/mbstate_t.m4 b/m4/mbstate_t.m4 index d4ec6f0fc..08f85d6a5 100644 --- a/m4/mbstate_t.m4 +++ b/m4/mbstate_t.m4 @@ -18,17 +18,17 @@ AC_DEFUN([AC_TYPE_MBSTATE_T], AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t], [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [AC_INCLUDES_DEFAULT[ -# include ]], - [[mbstate_t x; return sizeof x;]])], - [ac_cv_type_mbstate_t=yes], - [ac_cv_type_mbstate_t=no])]) + [AC_LANG_PROGRAM( + [AC_INCLUDES_DEFAULT[ +# include ]], + [[mbstate_t x; return sizeof x;]])], + [ac_cv_type_mbstate_t=yes], + [ac_cv_type_mbstate_t=no])]) if test $ac_cv_type_mbstate_t = yes; then AC_DEFINE([HAVE_MBSTATE_T], [1], - [Define to 1 if declares mbstate_t.]) + [Define to 1 if declares mbstate_t.]) else AC_DEFINE([mbstate_t], [int], - [Define to a type if does not define.]) + [Define to a type if does not define.]) fi ]) diff --git a/m4/memchr.m4 b/m4/memchr.m4 index 1194bac2e..81531ca41 100644 --- a/m4/memchr.m4 +++ b/m4/memchr.m4 @@ -53,11 +53,11 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR], { int pagesize = getpagesize (); char *two_pages = - (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, - flags, fd, 0); + (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, + flags, fd, 0); if (two_pages != (char *)(-1) - && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) - fence = two_pages + pagesize; + && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) + fence = two_pages + pagesize; } #endif if (fence) diff --git a/m4/memcmp.m4 b/m4/memcmp.m4 index 171f4144f..f3600ff50 100644 --- a/m4/memcmp.m4 +++ b/m4/memcmp.m4 @@ -13,10 +13,10 @@ AC_DEFUN([gl_FUNC_MEMCMP], AC_CACHE_CHECK([whether cross-compiling target has memcmp], [ac_cv_func_memcmp_working], [AC_LINK_IFELSE([ - AC_LANG_PROGRAM([[#include - ]], [[int ret = memcmp ("foo", "bar", 0);]])], - [ac_cv_func_memcmp_working=yes], - [ac_cv_func_memcmp_working=no])]) + AC_LANG_PROGRAM([[#include + ]], [[int ret = memcmp ("foo", "bar", 0);]])], + [ac_cv_func_memcmp_working=yes], + [ac_cv_func_memcmp_working=no])]) fi AC_FUNC_MEMCMP dnl Note: AC_FUNC_MEMCMP does AC_LIBOBJ([memcmp]). diff --git a/m4/memmem.m4 b/m4/memmem.m4 index 9e3d3d956..3ef638516 100644 --- a/m4/memmem.m4 +++ b/m4/memmem.m4 @@ -42,19 +42,19 @@ AC_DEFUN([gl_FUNC_MEMMEM], /* Check for quadratic performance. */ if (haystack && needle) { - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - memset (needle, 'A', m); - needle[m] = 'B'; - result = memmem (haystack, 2 * m + 1, needle, m + 1); + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + memset (needle, 'A', m); + needle[m] = 'B'; + result = memmem (haystack, 2 * m + 1, needle, m + 1); } /* Check for empty needle behavior. */ return !result || !memmem ("a", 1, 0, 0);]])], - [gl_cv_func_memmem_works=yes], [gl_cv_func_memmem_works=no], - [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a - dnl memmem that works in linear time. - AC_EGREP_CPP([Lucky user], - [ + [gl_cv_func_memmem_works=yes], [gl_cv_func_memmem_works=no], + [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a + dnl memmem that works in linear time. + AC_EGREP_CPP([Lucky user], + [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2) @@ -67,10 +67,10 @@ AC_DEFUN([gl_FUNC_MEMMEM], Lucky user #endif #endif - ], - [gl_cv_func_memmem_works=yes], - [gl_cv_func_memmem_works="guessing no"]) - ]) + ], + [gl_cv_func_memmem_works=yes], + [gl_cv_func_memmem_works="guessing no"]) + ]) ]) if test "$gl_cv_func_memmem_works" != yes; then REPLACE_MEMMEM=1 diff --git a/m4/mkstemp.m4 b/m4/mkstemp.m4 index 20d8a1b70..b40060e0e 100644 --- a/m4/mkstemp.m4 +++ b/m4/mkstemp.m4 @@ -21,25 +21,25 @@ AC_DEFUN([gl_FUNC_MKSTEMP], [ mkdir conftest.mkstemp AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [AC_INCLUDES_DEFAULT], - [[int i; - off_t large = (off_t) 4294967295u; - if (large < 0) - large = 2147483647; - for (i = 0; i < 70; i++) - { - char templ[] = "conftest.mkstemp/coXXXXXX"; - int (*mkstemp_function) (char *) = mkstemp; - int fd = mkstemp_function (templ); - if (fd < 0 || lseek (fd, large, SEEK_SET) != large) - return 1; - close (fd); - } - return 0;]])], - [gl_cv_func_working_mkstemp=yes], - [gl_cv_func_working_mkstemp=no], - [gl_cv_func_working_mkstemp=no]) + [AC_LANG_PROGRAM( + [AC_INCLUDES_DEFAULT], + [[int i; + off_t large = (off_t) 4294967295u; + if (large < 0) + large = 2147483647; + for (i = 0; i < 70; i++) + { + char templ[] = "conftest.mkstemp/coXXXXXX"; + int (*mkstemp_function) (char *) = mkstemp; + int fd = mkstemp_function (templ); + if (fd < 0 || lseek (fd, large, SEEK_SET) != large) + return 1; + close (fd); + } + return 0;]])], + [gl_cv_func_working_mkstemp=yes], + [gl_cv_func_working_mkstemp=no], + [gl_cv_func_working_mkstemp=no]) rm -rf conftest.mkstemp ]) diff --git a/m4/mktime.m4 b/m4/mktime.m4 index d3e99f990..bea878255 100644 --- a/m4/mktime.m4 +++ b/m4/mktime.m4 @@ -85,8 +85,8 @@ static int mktime_test (time_t now) { return (mktime_test1 (now) - && mktime_test1 ((time_t) (time_t_max - now)) - && mktime_test1 ((time_t) (time_t_min + now))); + && mktime_test1 ((time_t) (time_t_max - now)) + && mktime_test1 ((time_t) (time_t_min + now))); } static int @@ -116,17 +116,17 @@ bigtime_test (int j) { struct tm *lt = localtime (&now); if (! (lt - && lt->tm_year == tm.tm_year - && lt->tm_mon == tm.tm_mon - && lt->tm_mday == tm.tm_mday - && lt->tm_hour == tm.tm_hour - && lt->tm_min == tm.tm_min - && lt->tm_sec == tm.tm_sec - && lt->tm_yday == tm.tm_yday - && lt->tm_wday == tm.tm_wday - && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst) - == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst)))) - return 0; + && lt->tm_year == tm.tm_year + && lt->tm_mon == tm.tm_mon + && lt->tm_mday == tm.tm_mday + && lt->tm_hour == tm.tm_hour + && lt->tm_min == tm.tm_min + && lt->tm_sec == tm.tm_sec + && lt->tm_yday == tm.tm_yday + && lt->tm_wday == tm.tm_wday + && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst) + == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst)))) + return 0; } return 1; } @@ -158,7 +158,7 @@ year_2050_test () to the correct answer that we can assume the discrepancy is due to leap seconds. */ return (t == (time_t) -1 - || (0 < t && answer - 120 <= t && t <= answer + 120)); + || (0 < t && answer - 120 <= t && t <= answer + 120)); } int @@ -176,7 +176,7 @@ main () { t = (time_t_max << 1) + 1; if (t <= time_t_max) - break; + break; time_t_max = t; } time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max; @@ -185,29 +185,29 @@ main () for (i = 0; i < N_STRINGS; i++) { if (tz_strings[i]) - putenv (tz_strings[i]); + putenv (tz_strings[i]); for (t = 0; t <= time_t_max - delta; t += delta) - if (! mktime_test (t)) - return 1; + if (! mktime_test (t)) + return 1; if (! (mktime_test ((time_t) 1) - && mktime_test ((time_t) (60 * 60)) - && mktime_test ((time_t) (60 * 60 * 24)))) - return 1; + && mktime_test ((time_t) (60 * 60)) + && mktime_test ((time_t) (60 * 60 * 24)))) + return 1; for (j = 1; ; j <<= 1) - if (! bigtime_test (j)) - return 1; - else if (INT_MAX / 2 < j) - break; + if (! bigtime_test (j)) + return 1; + else if (INT_MAX / 2 < j) + break; if (! bigtime_test (INT_MAX)) - return 1; + return 1; } return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ()); }]])], - [ac_cv_func_working_mktime=yes], - [ac_cv_func_working_mktime=no], - [ac_cv_func_working_mktime=no])]) + [ac_cv_func_working_mktime=yes], + [ac_cv_func_working_mktime=no], + [ac_cv_func_working_mktime=no])]) if test $ac_cv_func_working_mktime = no; then AC_LIBOBJ([mktime]) fi diff --git a/m4/mountlist.m4 b/m4/mountlist.m4 index f62c57a23..985ff84ee 100644 --- a/m4/mountlist.m4 +++ b/m4/mountlist.m4 @@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_MOUNTLIST], [ gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes], - [gl_cv_list_mounted_fs=no]) + [gl_cv_list_mounted_fs=no]) if test $gl_cv_list_mounted_fs = yes; then AC_LIBOBJ([mountlist]) gl_PREREQ_MOUNTLIST_EXTRA diff --git a/m4/nanosleep.m4 b/m4/nanosleep.m4 index 2251e935e..15df31a3d 100644 --- a/m4/nanosleep.m4 +++ b/m4/nanosleep.m4 @@ -44,51 +44,51 @@ AC_DEFUN([gl_FUNC_NANOSLEEP], [ AC_RUN_IFELSE( [AC_LANG_SOURCE([[ - #include - #include - #include - #if HAVE_SYS_TIME_H - #include - #endif - #include - #include - #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) - #define TYPE_MAXIMUM(t) \ - ((t) (! TYPE_SIGNED (t) \ - ? (t) -1 \ - : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) + #include + #include + #include + #if HAVE_SYS_TIME_H + #include + #endif + #include + #include + #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + #define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) - static void - check_for_SIGALRM (int sig) - { - if (sig != SIGALRM) - _exit (1); - } + static void + check_for_SIGALRM (int sig) + { + if (sig != SIGALRM) + _exit (1); + } - int - main () - { - static struct timespec ts_sleep; - static struct timespec ts_remaining; - static struct sigaction act; - if (! nanosleep) - return 1; - act.sa_handler = check_for_SIGALRM; - sigemptyset (&act.sa_mask); - sigaction (SIGALRM, &act, NULL); - ts_sleep.tv_sec = 0; - ts_sleep.tv_nsec = 1; - alarm (1); - if (nanosleep (&ts_sleep, NULL) != 0) - return 1; - ts_sleep.tv_sec = TYPE_MAXIMUM (time_t); - ts_sleep.tv_nsec = 999999999; - alarm (1); - if (nanosleep (&ts_sleep, &ts_remaining) == -1 && errno == EINTR - && TYPE_MAXIMUM (time_t) - 10 < ts_remaining.tv_sec) - return 0; - return 119; - }]])], + int + main () + { + static struct timespec ts_sleep; + static struct timespec ts_remaining; + static struct sigaction act; + if (! nanosleep) + return 1; + act.sa_handler = check_for_SIGALRM; + sigemptyset (&act.sa_mask); + sigaction (SIGALRM, &act, NULL); + ts_sleep.tv_sec = 0; + ts_sleep.tv_nsec = 1; + alarm (1); + if (nanosleep (&ts_sleep, NULL) != 0) + return 1; + ts_sleep.tv_sec = TYPE_MAXIMUM (time_t); + ts_sleep.tv_nsec = 999999999; + alarm (1); + if (nanosleep (&ts_sleep, &ts_remaining) == -1 && errno == EINTR + && TYPE_MAXIMUM (time_t) - 10 < ts_remaining.tv_sec) + return 0; + return 119; + }]])], [gl_cv_func_nanosleep=yes], [case $? in dnl ( 119) gl_cv_func_nanosleep='no (mishandles large arguments)';; dnl ( @@ -102,7 +102,7 @@ AC_DEFUN([gl_FUNC_NANOSLEEP], REPLACE_NANOSLEEP=1 if test "$gl_cv_func_nanosleep" = 'no (mishandles large arguments)'; then AC_DEFINE([HAVE_BUG_BIG_NANOSLEEP], [1], - [Define to 1 if nanosleep mishandles large arguments.]) + [Define to 1 if nanosleep mishandles large arguments.]) else for ac_lib in $LIBSOCKET; do case " $LIB_NANOSLEEP " in diff --git a/m4/openat.m4 b/m4/openat.m4 index e6ea25ea6..8e2f67195 100644 --- a/m4/openat.m4 +++ b/m4/openat.m4 @@ -74,7 +74,7 @@ AC_DEFUN([gl_FUNC_FCHOWNAT_DEREF_BUG], ln -s conftest.no-such $gl_dangle AC_RUN_IFELSE( [AC_LANG_SOURCE( - [[ + [[ #include #include #include @@ -84,10 +84,10 @@ int main () { return (fchownat (AT_FDCWD, "$gl_dangle", -1, getgid (), - AT_SYMLINK_NOFOLLOW) != 0 - && errno == ENOENT); + AT_SYMLINK_NOFOLLOW) != 0 + && errno == ENOENT); } - ]])], + ]])], [gl_cv_func_fchownat_nofollow_works=yes], [gl_cv_func_fchownat_nofollow_works=no], [gl_cv_func_fchownat_nofollow_works=no], diff --git a/m4/openmp.m4 b/m4/openmp.m4 index 116e6ce61..254511570 100644 --- a/m4/openmp.m4 +++ b/m4/openmp.m4 @@ -61,30 +61,30 @@ AC_DEFUN([AC_OPENMP], AC_CACHE_CHECK([for $CC option to support OpenMP], [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp], [AC_LINK_IFELSE([_AC_LANG_OPENMP], - [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'], - [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported' - dnl Try these flags: - dnl GCC >= 4.2 -fopenmp - dnl SunPRO C -xopenmp - dnl Intel C -openmp - dnl SGI C, PGI C -mp - dnl Tru64 Compaq C -omp - dnl IBM C (AIX, Linux) -qsmp=omp - dnl If in this loop a compiler is passed an option that it doesn't - dnl understand or that it misinterprets, the AC_LINK_IFELSE test - dnl will fail (since we know that it failed without the option), - dnl therefore the loop will continue searching for an option, and - dnl no output file called 'penmp' or 'mp' is created. - for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do - ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS - _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option" - AC_LINK_IFELSE([_AC_LANG_OPENMP], - [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option]) - _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS - if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then - break - fi - done])]) + [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='none needed'], + [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp='unsupported' + dnl Try these flags: + dnl GCC >= 4.2 -fopenmp + dnl SunPRO C -xopenmp + dnl Intel C -openmp + dnl SGI C, PGI C -mp + dnl Tru64 Compaq C -omp + dnl IBM C (AIX, Linux) -qsmp=omp + dnl If in this loop a compiler is passed an option that it doesn't + dnl understand or that it misinterprets, the AC_LINK_IFELSE test + dnl will fail (since we know that it failed without the option), + dnl therefore the loop will continue searching for an option, and + dnl no output file called 'penmp' or 'mp' is created. + for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do + ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $ac_option" + AC_LINK_IFELSE([_AC_LANG_OPENMP], + [ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp=$ac_option]) + _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS + if test "$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != unsupported; then + break + fi + done])]) case $ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp in #( "none needed" | unsupported) ;; #( diff --git a/m4/physmem.m4 b/m4/physmem.m4 index 9f93fa9bf..96e7edc82 100644 --- a/m4/physmem.m4 +++ b/m4/physmem.m4 @@ -8,19 +8,19 @@ dnl with or without modifications, as long as this notice is preserved. # a struct with member `physmem'. AC_DEFUN([gl_SYS__SYSTEM_CONFIGURATION], [AC_CACHE_CHECK([for external symbol _system_configuration], - gl_cv_var__system_configuration, + gl_cv_var__system_configuration, [AC_LINK_IFELSE([AC_LANG_PROGRAM( - [[#include - ]], - [[double x = _system_configuration.physmem; - if (x > 0.0) return 0;]])], + [[#include + ]], + [[double x = _system_configuration.physmem; + if (x > 0.0) return 0;]])], [gl_cv_var__system_configuration=yes], [gl_cv_var__system_configuration=no])]) if test $gl_cv_var__system_configuration = yes; then AC_DEFINE([HAVE__SYSTEM_CONFIGURATION], [1], - [Define to 1 if you have the external variable, - _system_configuration with a member named physmem.]) + [Define to 1 if you have the external variable, + _system_configuration with a member named physmem.]) fi ] ) diff --git a/m4/po.m4 b/m4/po.m4 index 2284fa505..1c3579182 100644 --- a/m4/po.m4 +++ b/m4/po.m4 @@ -411,8 +411,8 @@ changequote([,])dnl frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` cat >> "$ac_file.tmp" <> "$ac_file.tmp" </dev/null \ - && break;; + "$gl_cv_posix_shell" -c "$gl_test_posix_shell_script" 2>/dev/null \ + && break;; esac done]) diff --git a/m4/posix_spawn.m4 b/m4/posix_spawn.m4 index acf122de1..099843745 100644 --- a/m4/posix_spawn.m4 +++ b/m4/posix_spawn.m4 @@ -158,18 +158,18 @@ main () || (err = posix_spawnp (&child, CHILD_PROGRAM_FILENAME, &actions, &attrs, argv, environ)) != 0)) { if (actions_allocated) - posix_spawn_file_actions_destroy (&actions); + posix_spawn_file_actions_destroy (&actions); if (attrs_allocated) - posix_spawnattr_destroy (&attrs); + posix_spawnattr_destroy (&attrs); sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); if (err == ENOENT) - return 0; + return 0; else - { - errno = err; - perror ("subprocess failed"); - exit (1); - } + { + errno = err; + perror ("subprocess failed"); + exit (1); + } } posix_spawn_file_actions_destroy (&actions); posix_spawnattr_destroy (&attrs); diff --git a/m4/pthread.m4 b/m4/pthread.m4 index 2a383076b..c984e2dfb 100644 --- a/m4/pthread.m4 +++ b/m4/pthread.m4 @@ -13,8 +13,8 @@ AC_DEFUN([gl_PTHREAD_CHECK], gl_saved_libs=$LIBS AC_SEARCH_LIBS([pthread_create], [pthread], [if test "$ac_cv_search_pthread_create" != "none required"; then - LIB_PTHREAD="$ac_cv_search_pthread_create" - fi]) + LIB_PTHREAD="$ac_cv_search_pthread_create" + fi]) LIBS="$gl_saved_libs" else PTHREAD_H='pthread.h' diff --git a/m4/pty.m4 b/m4/pty.m4 index ba6a8c02a..4670f31eb 100644 --- a/m4/pty.m4 +++ b/m4/pty.m4 @@ -22,7 +22,7 @@ AC_DEFUN([gl_PTY], AC_MSG_WARN([[Cannot find forkpty, build will likely fail]]) else PTY_H='pty.h' - PTY_HEADER='libutil.h' + PTY_HEADER='libutil.h' fi else PTY_H='pty.h' diff --git a/m4/putenv.m4 b/m4/putenv.m4 index 120f5a4a5..e04f86490 100644 --- a/m4/putenv.m4 +++ b/m4/putenv.m4 @@ -28,11 +28,11 @@ AC_DEFUN([gl_FUNC_PUTENV], return 1; return 0; - ]])], - gl_cv_func_svid_putenv=yes, - gl_cv_func_svid_putenv=no, - dnl When crosscompiling, assume putenv is broken. - gl_cv_func_svid_putenv=no) + ]])], + gl_cv_func_svid_putenv=yes, + gl_cv_func_svid_putenv=no, + dnl When crosscompiling, assume putenv is broken. + gl_cv_func_svid_putenv=no) ]) if test $gl_cv_func_svid_putenv = no; then REPLACE_PUTENV=1 diff --git a/m4/readline.m4 b/m4/readline.m4 index eb44b0ad0..4230ce92b 100644 --- a/m4/readline.m4 +++ b/m4/readline.m4 @@ -42,7 +42,7 @@ AC_DEFUN([gl_FUNC_READLINE], [[readline((char*)0);]])], [gl_cv_lib_readline=" -l$extra_lib"]) if test "$gl_cv_lib_readline" != no; then - break + break fi done LIBS="$am_save_LIBS" diff --git a/m4/regex.m4 b/m4/regex.m4 index aef53d298..fee2f45a0 100644 --- a/m4/regex.m4 +++ b/m4/regex.m4 @@ -18,146 +18,146 @@ AC_DEFUN([gl_REGEX], AC_ARG_WITH([included-regex], [AS_HELP_STRING([--without-included-regex], - [don't compile regex; this is the default on systems - with recent-enough versions of the GNU C Library - (use with caution on other systems).])]) + [don't compile regex; this is the default on systems + with recent-enough versions of the GNU C Library + (use with caution on other systems).])]) case $with_included_regex in #( yes|no) ac_use_included_regex=$with_included_regex - ;; + ;; '') # If the system regex support is good enough that it passes the # following run test, then default to *not* using the included regex.c. # If cross compiling, assume the test would fail and use the included # regex.c. AC_CACHE_CHECK([for working re_compile_pattern], - [gl_cv_func_re_compile_pattern_working], + [gl_cv_func_re_compile_pattern_working], [AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [AC_INCLUDES_DEFAULT[ - #if HAVE_LOCALE_H - #include - #endif - #include - #include - ]], - [[static struct re_pattern_buffer regex; - unsigned char folded_chars[UCHAR_MAX + 1]; - int i; - const char *s; - struct re_registers regs; - - #if HAVE_LOCALE_H - /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html - This test needs valgrind to catch the bug on Debian - GNU/Linux 3.1 x86, but it might catch the bug better - on other platforms and it shouldn't hurt to try the - test here. */ - if (setlocale (LC_ALL, "en_US.UTF-8")) - { - static char const pat[] = "insert into"; - static char const data[] = - "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; - re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE - | RE_ICASE); - memset (®ex, 0, sizeof regex); - s = re_compile_pattern (pat, sizeof pat - 1, ®ex); - if (s) - return 1; - if (re_search (®ex, data, sizeof data - 1, - 0, sizeof data - 1, ®s) - != -1) - return 1; - if (! setlocale (LC_ALL, "C")) - return 1; - } - #endif - - /* This test is from glibc bug 3957, reported by Andrew Mackey. */ - re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE); - memset (®ex, 0, sizeof regex); - s = re_compile_pattern ("a[^x]b", 6, ®ex); - if (s) - return 1; - - /* This should fail, but succeeds for glibc-2.5. */ - if (re_search (®ex, "a\nb", 3, 0, 3, ®s) != -1) - return 1; - - /* This regular expression is from Spencer ere test number 75 - in grep-2.3. */ - re_set_syntax (RE_SYNTAX_POSIX_EGREP); - memset (®ex, 0, sizeof regex); - for (i = 0; i <= UCHAR_MAX; i++) - folded_chars[i] = i; - regex.translate = folded_chars; - s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex); - /* This should fail with _Invalid character class name_ error. */ - if (!s) - return 1; - - /* This should succeed, but does not for glibc-2.1.3. */ - memset (®ex, 0, sizeof regex); - s = re_compile_pattern ("{1", 2, ®ex); - - if (s) - return 1; - - /* The following example is derived from a problem report - against gawk from Jorge Stolfi . */ - memset (®ex, 0, sizeof regex); - s = re_compile_pattern ("[an\371]*n", 7, ®ex); - if (s) - return 1; - - /* This should match, but does not for glibc-2.2.1. */ - if (re_match (®ex, "an", 2, 0, ®s) != 2) - return 1; - - memset (®ex, 0, sizeof regex); - s = re_compile_pattern ("x", 1, ®ex); - if (s) - return 1; - - /* glibc-2.2.93 does not work with a negative RANGE argument. */ - if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) - return 1; - - /* The version of regex.c in older versions of gnulib - ignored RE_ICASE. Detect that problem too. */ - re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); - memset (®ex, 0, sizeof regex); - s = re_compile_pattern ("x", 1, ®ex); - if (s) - return 1; - - if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0) - return 1; - - /* Catch a bug reported by Vin Shelton in - http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html - */ - re_set_syntax (RE_SYNTAX_POSIX_BASIC - & ~RE_CONTEXT_INVALID_DUP - & ~RE_NO_EMPTY_RANGES); - memset (®ex, 0, sizeof regex); - s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, ®ex); - if (s) - return 1; - - /* REG_STARTEND was added to glibc on 2004-01-15. - Reject older versions. */ - if (! REG_STARTEND) - return 1; - - /* Reject hosts whose regoff_t values are too narrow. - These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t - and 32-bit int. */ - if (sizeof (regoff_t) < sizeof (ptrdiff_t) - || sizeof (regoff_t) < sizeof (ssize_t)) - return 1; - - return 0;]])], + [AC_LANG_PROGRAM( + [AC_INCLUDES_DEFAULT[ + #if HAVE_LOCALE_H + #include + #endif + #include + #include + ]], + [[static struct re_pattern_buffer regex; + unsigned char folded_chars[UCHAR_MAX + 1]; + int i; + const char *s; + struct re_registers regs; + + #if HAVE_LOCALE_H + /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html + This test needs valgrind to catch the bug on Debian + GNU/Linux 3.1 x86, but it might catch the bug better + on other platforms and it shouldn't hurt to try the + test here. */ + if (setlocale (LC_ALL, "en_US.UTF-8")) + { + static char const pat[] = "insert into"; + static char const data[] = + "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; + re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE + | RE_ICASE); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern (pat, sizeof pat - 1, ®ex); + if (s) + return 1; + if (re_search (®ex, data, sizeof data - 1, + 0, sizeof data - 1, ®s) + != -1) + return 1; + if (! setlocale (LC_ALL, "C")) + return 1; + } + #endif + + /* This test is from glibc bug 3957, reported by Andrew Mackey. */ + re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("a[^x]b", 6, ®ex); + if (s) + return 1; + + /* This should fail, but succeeds for glibc-2.5. */ + if (re_search (®ex, "a\nb", 3, 0, 3, ®s) != -1) + return 1; + + /* This regular expression is from Spencer ere test number 75 + in grep-2.3. */ + re_set_syntax (RE_SYNTAX_POSIX_EGREP); + memset (®ex, 0, sizeof regex); + for (i = 0; i <= UCHAR_MAX; i++) + folded_chars[i] = i; + regex.translate = folded_chars; + s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex); + /* This should fail with _Invalid character class name_ error. */ + if (!s) + return 1; + + /* This should succeed, but does not for glibc-2.1.3. */ + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("{1", 2, ®ex); + + if (s) + return 1; + + /* The following example is derived from a problem report + against gawk from Jorge Stolfi . */ + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("[an\371]*n", 7, ®ex); + if (s) + return 1; + + /* This should match, but does not for glibc-2.2.1. */ + if (re_match (®ex, "an", 2, 0, ®s) != 2) + return 1; + + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("x", 1, ®ex); + if (s) + return 1; + + /* glibc-2.2.93 does not work with a negative RANGE argument. */ + if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) + return 1; + + /* The version of regex.c in older versions of gnulib + ignored RE_ICASE. Detect that problem too. */ + re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("x", 1, ®ex); + if (s) + return 1; + + if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0) + return 1; + + /* Catch a bug reported by Vin Shelton in + http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html + */ + re_set_syntax (RE_SYNTAX_POSIX_BASIC + & ~RE_CONTEXT_INVALID_DUP + & ~RE_NO_EMPTY_RANGES); + memset (®ex, 0, sizeof regex); + s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, ®ex); + if (s) + return 1; + + /* REG_STARTEND was added to glibc on 2004-01-15. + Reject older versions. */ + if (! REG_STARTEND) + return 1; + + /* Reject hosts whose regoff_t values are too narrow. + These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t + and 32-bit int. */ + if (sizeof (regoff_t) < sizeof (ptrdiff_t) + || sizeof (regoff_t) < sizeof (ssize_t)) + return 1; + + return 0;]])], [gl_cv_func_re_compile_pattern_working=yes], [gl_cv_func_re_compile_pattern_working=no], dnl When crosscompiling, assume it is not working. diff --git a/m4/rmdir-errno.m4 b/m4/rmdir-errno.m4 index b7398bc87..de37f5768 100644 --- a/m4/rmdir-errno.m4 +++ b/m4/rmdir-errno.m4 @@ -25,17 +25,17 @@ AC_DEFUN([gl_FUNC_RMDIR_NOTEMPTY], #ifdef HAVE_UNISTD_H # include #endif - int main () - { - FILE *s; - int val; - rmdir ("confdir2"); - val = errno; - s = fopen ("confdir2/errno", "w"); - fprintf (s, "%d\n", val); - return 0; - } - ]])], + int main () + { + FILE *s; + int val; + rmdir ("confdir2"); + val = errno; + s = fopen ("confdir2/errno", "w"); + fprintf (s, "%d\n", val); + return 0; + } + ]])], [gl_cv_func_rmdir_errno_not_empty=`cat confdir2/errno`], [gl_cv_func_rmdir_errno_not_empty='configure error in rmdir-errno.m4'], [gl_cv_func_rmdir_errno_not_empty=ENOTEMPTY] diff --git a/m4/rmdir.m4 b/m4/rmdir.m4 index 599b78957..ed338dd4a 100644 --- a/m4/rmdir.m4 +++ b/m4/rmdir.m4 @@ -16,10 +16,10 @@ AC_DEFUN([gl_FUNC_RMDIR], # a bug report to inform us about it. if test x"$SKIP_RMDIR_CHECK" != xyes; then AC_MSG_FAILURE([Your system lacks the rmdir function. - Please report this, along with the output of "uname -a", to the - bug-coreutils@gnu.org mailing list. To continue past this point, - rerun configure with SKIP_RMDIR_CHECK=yes. - E.g., ./configure SKIP_RMDIR_CHECK=yes]) + Please report this, along with the output of "uname -a", to the + bug-coreutils@gnu.org mailing list. To continue past this point, + rerun configure with SKIP_RMDIR_CHECK=yes. + E.g., ./configure SKIP_RMDIR_CHECK=yes]) fi else dnl Detect cygwin 1.5.x bug. diff --git a/m4/selinux-context-h.m4 b/m4/selinux-context-h.m4 index 6b0bed16a..4d6197517 100644 --- a/m4/selinux-context-h.m4 +++ b/m4/selinux-context-h.m4 @@ -10,7 +10,7 @@ AC_DEFUN([gl_HEADERS_SELINUX_CONTEXT_H], [ AC_CHECK_HEADERS([selinux/context.h], - [SELINUX_CONTEXT_H=], - [SELINUX_CONTEXT_H=selinux/context.h]) + [SELINUX_CONTEXT_H=], + [SELINUX_CONTEXT_H=selinux/context.h]) AC_SUBST([SELINUX_CONTEXT_H]) ]) diff --git a/m4/selinux-selinux-h.m4 b/m4/selinux-selinux-h.m4 index 767c4f7f1..6eb41796d 100644 --- a/m4/selinux-selinux-h.m4 +++ b/m4/selinux-selinux-h.m4 @@ -20,11 +20,11 @@ AC_DEFUN([gl_HEADERS_SELINUX_SELINUX_H], AC_LIBOBJ([getfilecon]) gl_CHECK_NEXT_HEADERS([selinux/selinux.h]) AC_DEFINE([getfilecon], [rpl_getfilecon], - [Always use our getfilecon wrapper.]) + [Always use our getfilecon wrapper.]) AC_DEFINE([lgetfilecon], [rpl_lgetfilecon], - [Always use our lgetfilecon wrapper.]) + [Always use our lgetfilecon wrapper.]) AC_DEFINE([fgetfilecon], [rpl_fgetfilecon], - [Always use our fgetfilecon wrapper.]) + [Always use our fgetfilecon wrapper.]) fi case "$ac_cv_search_setfilecon:$ac_cv_header_selinux_selinux_h" in diff --git a/m4/socklen.m4 b/m4/socklen.m4 index 80ed5135f..36436ed80 100644 --- a/m4/socklen.m4 +++ b/m4/socklen.m4 @@ -20,30 +20,30 @@ AC_DEFUN([gl_TYPE_SOCKLEN_T], AC_CHECK_TYPE([socklen_t], , [AC_MSG_CHECKING([for socklen_t equivalent]) AC_CACHE_VAL([gl_cv_socklen_t_equiv], - [# Systems have either "struct sockaddr *" or - # "void *" as the second argument to getpeername - gl_cv_socklen_t_equiv= - for arg2 in "struct sockaddr" void; do - for t in int size_t "unsigned int" "long int" "unsigned long int"; do - AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [# Systems have either "struct sockaddr *" or + # "void *" as the second argument to getpeername + gl_cv_socklen_t_equiv= + for arg2 in "struct sockaddr" void; do + for t in int size_t "unsigned int" "long int" "unsigned long int"; do + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( [[#include #include int getpeername (int, $arg2 *, $t *);]], [[$t len; getpeername (0, 0, &len);]])], - [gl_cv_socklen_t_equiv="$t"]) - test "$gl_cv_socklen_t_equiv" != "" && break - done - test "$gl_cv_socklen_t_equiv" != "" && break - done + [gl_cv_socklen_t_equiv="$t"]) + test "$gl_cv_socklen_t_equiv" != "" && break + done + test "$gl_cv_socklen_t_equiv" != "" && break + done ]) if test "$gl_cv_socklen_t_equiv" = ""; then - AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) + AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) fi AC_MSG_RESULT([$gl_cv_socklen_t_equiv]) AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv], - [type to use in place of socklen_t if not defined])], + [type to use in place of socklen_t if not defined])], [#include #if HAVE_SYS_SOCKET_H # include diff --git a/m4/st_dm_mode.m4 b/m4/st_dm_mode.m4 index 641858cd6..8ac433bcd 100644 --- a/m4/st_dm_mode.m4 +++ b/m4/st_dm_mode.m4 @@ -17,7 +17,7 @@ AC_DEFUN([AC_STRUCT_ST_DM_MODE], if test $ac_cv_struct_st_dm_mode = yes; then AC_DEFINE([HAVE_ST_DM_MODE], [1], - [Define if struct stat has an st_dm_mode member. ]) + [Define if struct stat has an st_dm_mode member. ]) fi ] ) diff --git a/m4/stat-time.m4 b/m4/stat-time.m4 index cdef9d135..efcca6cdf 100644 --- a/m4/stat-time.m4 +++ b/m4/stat-time.m4 @@ -27,35 +27,35 @@ AC_DEFUN([gl_STAT_TIME], [AC_CACHE_CHECK([whether struct stat.st_atim is of type struct timespec], [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM( - [[ - #include - #include - #if HAVE_SYS_TIME_H - # include - #endif - #include - struct timespec ts; - struct stat st; - ]], - [[ - st.st_atim = ts; - ]])], - [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=yes], - [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=no])]) + [[ + #include + #include + #if HAVE_SYS_TIME_H + # include + #endif + #include + struct timespec ts; + struct stat st; + ]], + [[ + st.st_atim = ts; + ]])], + [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=yes], + [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=no])]) if test $ac_cv_typeof_struct_stat_st_atim_is_struct_timespec = yes; then AC_DEFINE([TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC], [1], - [Define to 1 if the type of the st_atim member of a struct stat is - struct timespec.]) + [Define to 1 if the type of the st_atim member of a struct stat is + struct timespec.]) fi], [AC_CHECK_MEMBERS([struct stat.st_atimespec.tv_nsec], [], [AC_CHECK_MEMBERS([struct stat.st_atimensec], [], - [AC_CHECK_MEMBERS([struct stat.st_atim.st__tim.tv_nsec], [], [], - [#include - #include ])], - [#include - #include ])], + [AC_CHECK_MEMBERS([struct stat.st_atim.st__tim.tv_nsec], [], [], + [#include + #include ])], + [#include + #include ])], [#include - #include ])], + #include ])], [#include #include ]) ]) @@ -76,10 +76,10 @@ AC_DEFUN([gl_STAT_BIRTHTIME], AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec], [], [AC_CHECK_MEMBERS([struct stat.st_birthtimensec], [], [AC_CHECK_MEMBERS([struct stat.st_birthtim.tv_nsec], [], [], - [#include - #include ])], + [#include + #include ])], [#include - #include ])], + #include ])], [#include #include ]) ]) diff --git a/m4/stdbool.m4 b/m4/stdbool.m4 index 57c804a80..5e22d7a4b 100644 --- a/m4/stdbool.m4 +++ b/m4/stdbool.m4 @@ -38,77 +38,77 @@ AC_DEFUN([AC_HEADER_STDBOOL], [AC_CACHE_CHECK([for stdbool.h that conforms to C99], [ac_cv_header_stdbool_h], [AC_TRY_COMPILE( - [ - #include - #ifndef bool - "error: bool is not defined" - #endif - #ifndef false - "error: false is not defined" - #endif - #if false - "error: false is not 0" - #endif - #ifndef true - "error: true is not defined" - #endif - #if true != 1 - "error: true is not 1" - #endif - #ifndef __bool_true_false_are_defined - "error: __bool_true_false_are_defined is not defined" - #endif + [ + #include + #ifndef bool + "error: bool is not defined" + #endif + #ifndef false + "error: false is not defined" + #endif + #if false + "error: false is not 0" + #endif + #ifndef true + "error: true is not defined" + #endif + #if true != 1 + "error: true is not 1" + #endif + #ifndef __bool_true_false_are_defined + "error: __bool_true_false_are_defined is not defined" + #endif - struct s { _Bool s: 1; _Bool t; } s; + struct s { _Bool s: 1; _Bool t; } s; - char a[true == 1 ? 1 : -1]; - char b[false == 0 ? 1 : -1]; - char c[__bool_true_false_are_defined == 1 ? 1 : -1]; - char d[(bool) 0.5 == true ? 1 : -1]; - bool e = &s; - char f[(_Bool) 0.0 == false ? 1 : -1]; - char g[true]; - char h[sizeof (_Bool)]; - char i[sizeof s.t]; - enum { j = false, k = true, l = false * true, m = true * 256 }; - _Bool n[m]; - char o[sizeof n == m * sizeof n[0] ? 1 : -1]; - char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; - #if defined __xlc__ || defined __GNUC__ - /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 - reported by James Lemley on 2005-10-05; see - http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html - This test is not quite right, since xlc is allowed to - reject this program, as the initializer for xlcbug is - not one of the forms that C requires support for. - However, doing the test right would require a run-time - test, and that would make cross-compilation harder. - Let us hope that IBM fixes the xlc bug, and also adds - support for this kind of constant expression. In the - meantime, this test will reject xlc, which is OK, since - our stdbool.h substitute should suffice. We also test - this with GCC, where it should work, to detect more - quickly whether someone messes up the test in the - future. */ - char digs[] = "0123456789"; - int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); - #endif - /* Catch a bug in an HP-UX C compiler. See - http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html - http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html - */ - _Bool q = true; - _Bool *pq = &q; - ], - [ - *pq |= q; - *pq |= ! q; - /* Refer to every declared value, to avoid compiler optimizations. */ - return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l - + !m + !n + !o + !p + !q + !pq); - ], - [ac_cv_header_stdbool_h=yes], - [ac_cv_header_stdbool_h=no])]) + char a[true == 1 ? 1 : -1]; + char b[false == 0 ? 1 : -1]; + char c[__bool_true_false_are_defined == 1 ? 1 : -1]; + char d[(bool) 0.5 == true ? 1 : -1]; + bool e = &s; + char f[(_Bool) 0.0 == false ? 1 : -1]; + char g[true]; + char h[sizeof (_Bool)]; + char i[sizeof s.t]; + enum { j = false, k = true, l = false * true, m = true * 256 }; + _Bool n[m]; + char o[sizeof n == m * sizeof n[0] ? 1 : -1]; + char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; + #if defined __xlc__ || defined __GNUC__ + /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 + reported by James Lemley on 2005-10-05; see + http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html + This test is not quite right, since xlc is allowed to + reject this program, as the initializer for xlcbug is + not one of the forms that C requires support for. + However, doing the test right would require a run-time + test, and that would make cross-compilation harder. + Let us hope that IBM fixes the xlc bug, and also adds + support for this kind of constant expression. In the + meantime, this test will reject xlc, which is OK, since + our stdbool.h substitute should suffice. We also test + this with GCC, where it should work, to detect more + quickly whether someone messes up the test in the + future. */ + char digs[] = "0123456789"; + int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); + #endif + /* Catch a bug in an HP-UX C compiler. See + http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html + http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html + */ + _Bool q = true; + _Bool *pq = &q; + ], + [ + *pq |= q; + *pq |= ! q; + /* Refer to every declared value, to avoid compiler optimizations. */ + return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l + + !m + !n + !o + !p + !q + !pq); + ], + [ac_cv_header_stdbool_h=yes], + [ac_cv_header_stdbool_h=no])]) AC_CHECK_TYPES([_Bool]) if test $ac_cv_header_stdbool_h = yes; then AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.]) diff --git a/m4/stdint.m4 b/m4/stdint.m4 index a2e8bdd62..819d629e9 100644 --- a/m4/stdint.m4 +++ b/m4/stdint.m4 @@ -396,12 +396,12 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do case $glsuf in '') gltype1='int';; - l) gltype1='long int';; - ll) gltype1='long long int';; - i64) gltype1='__int64';; - u) gltype1='unsigned int';; - ul) gltype1='unsigned long int';; - ull) gltype1='unsigned long long int';; + l) gltype1='long int';; + ll) gltype1='long long int';; + i64) gltype1='__int64';; + u) gltype1='unsigned int';; + ul) gltype1='unsigned long int';; + ull) gltype1='unsigned long long int';; ui64)gltype1='unsigned __int64';; esac AC_COMPILE_IFELSE( diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index ed828eac8..256efe1cb 100644 --- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -140,6 +140,6 @@ AC_DEFUN([gl_STDIN_LARGE_OFFSET], choke me # endif #endif]])], - [gl_cv_var_stdin_large_offset=yes], - [gl_cv_var_stdin_large_offset=no])]) + [gl_cv_var_stdin_large_offset=yes], + [gl_cv_var_stdin_large_offset=no])]) ]) diff --git a/m4/strcasestr.m4 b/m4/strcasestr.m4 index 62991b160..7a7999030 100644 --- a/m4/strcasestr.m4 +++ b/m4/strcasestr.m4 @@ -50,20 +50,20 @@ AC_DEFUN([gl_FUNC_STRCASESTR], /* Check for quadratic performance. */ if (haystack && needle) { - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = 0; - memset (needle, 'A', m); - needle[m] = 'B'; - needle[m + 1] = 0; - result = strcasestr (haystack, needle); + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = 0; + memset (needle, 'A', m); + needle[m] = 'B'; + needle[m + 1] = 0; + result = strcasestr (haystack, needle); } return !result;]])], - [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no], + [gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no], [dnl Only glibc >= 2.9 and cygwin >= 1.7.0 are known to have a dnl strcasestr that works in linear time. - AC_EGREP_CPP([Lucky user], - [ + AC_EGREP_CPP([Lucky user], + [ #include #ifdef __GNU_LIBRARY__ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 9) || (__GLIBC__ > 2) @@ -76,10 +76,10 @@ AC_DEFUN([gl_FUNC_STRCASESTR], Lucky user #endif #endif - ], - [gl_cv_func_strcasestr_linear=yes], - [gl_cv_func_strcasestr_linear="guessing no"]) - ]) + ], + [gl_cv_func_strcasestr_linear=yes], + [gl_cv_func_strcasestr_linear="guessing no"]) + ]) ]) if test "$gl_cv_func_strcasestr_linear" != yes; then REPLACE_STRCASESTR=1 diff --git a/m4/string_h.m4 b/m4/string_h.m4 index edc5c6e82..e8705342b 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -66,31 +66,31 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL]) GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP]) dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM]) - HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY]) - HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR]) - HAVE_RAWMEMCHR=1; AC_SUBST([HAVE_RAWMEMCHR]) - HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY]) - HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY]) - HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL]) - HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP]) - HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP]) - HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN]) - HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK]) - HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP]) - HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) - HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) - HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR]) - HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) - HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) - REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) - REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) - REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) - REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) - REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) - REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) - REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP]) - REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) - REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R]) - UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) + HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM]) + HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY]) + HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR]) + HAVE_RAWMEMCHR=1; AC_SUBST([HAVE_RAWMEMCHR]) + HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY]) + HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY]) + HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL]) + HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP]) + HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP]) + HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN]) + HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK]) + HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP]) + HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) + HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) + HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR]) + HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) + HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) + REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) + REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) + REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) + REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) + REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) + REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) + REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP]) + REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) + REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R]) + UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) ]) diff --git a/m4/strndup.m4 b/m4/strndup.m4 index 437e7f650..f8ea8f2ca 100644 --- a/m4/strndup.m4 +++ b/m4/strndup.m4 @@ -22,7 +22,7 @@ AC_DEFUN([gl_FUNC_STRNDUP], AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works], [AC_RUN_IFELSE([ AC_LANG_PROGRAM([[#include - #include ]], [[ + #include ]], [[ #ifndef HAVE_DECL_STRNDUP extern char *strndup (const char *, size_t); #endif diff --git a/m4/strsignal.m4 b/m4/strsignal.m4 index d71f0963f..83213831c 100644 --- a/m4/strsignal.m4 +++ b/m4/strsignal.m4 @@ -24,17 +24,17 @@ AC_DEFUN([gl_FUNC_STRSIGNAL], AC_CACHE_CHECK([whether strsignal always returns a string], [gl_cv_func_working_strsignal], [AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [[#include - ]], - [[char *s = strsignal (-1); - return !(s != (char *) 0 && s != (char *) -1);]])], - [gl_cv_func_working_strsignal=yes], - [gl_cv_func_working_strsignal=no], - [case "$host_os" in - solaris* | aix*) gl_cv_func_working_strsignal=no;; - *) gl_cv_func_working_strsignal="guessing yes";; - esac])]) + [AC_LANG_PROGRAM( + [[#include + ]], + [[char *s = strsignal (-1); + return !(s != (char *) 0 && s != (char *) -1);]])], + [gl_cv_func_working_strsignal=yes], + [gl_cv_func_working_strsignal=no], + [case "$host_os" in + solaris* | aix*) gl_cv_func_working_strsignal=no;; + *) gl_cv_func_working_strsignal="guessing yes";; + esac])]) else gl_cv_func_working_strsignal=no fi diff --git a/m4/strstr.m4 b/m4/strstr.m4 index b72df089f..abca44fff 100644 --- a/m4/strstr.m4 +++ b/m4/strstr.m4 @@ -38,13 +38,13 @@ AC_DEFUN([gl_FUNC_STRSTR], /* Check for quadratic performance. */ if (haystack && needle) { - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = 0; - memset (needle, 'A', m); - needle[m] = 'B'; - needle[m + 1] = 0; - result = strstr (haystack, needle); + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = 0; + memset (needle, 'A', m); + needle[m] = 'B'; + needle[m + 1] = 0; + result = strstr (haystack, needle); } return !result;]])], [gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no], diff --git a/m4/strtod.m4 b/m4/strtod.m4 index 3bc877025..72729d81c 100644 --- a/m4/strtod.m4 +++ b/m4/strtod.m4 @@ -73,9 +73,9 @@ numeric_equal (double x, double y) return 1; } ]])], - [gl_cv_func_strtod_works=yes], - [gl_cv_func_strtod_works=no], - [gl_cv_func_strtod_works="guessing no"])]) + [gl_cv_func_strtod_works=yes], + [gl_cv_func_strtod_works=no], + [gl_cv_func_strtod_works="guessing no"])]) if test "$gl_cv_func_strtod_works" != yes; then REPLACE_STRTOD=1 gl_PREREQ_STRTOD diff --git a/m4/sys_select_h.m4 b/m4/sys_select_h.m4 index 0bb097e1a..991c7b742 100644 --- a/m4/sys_select_h.m4 +++ b/m4/sys_select_h.m4 @@ -17,7 +17,7 @@ AC_DEFUN([gl_HEADER_SYS_SELECT], dnl 2. On OSF/1 4.0, provides only a forward declaration dnl of 'struct timeval', and no definition of this type. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], - [[struct timeval b;]])], + [[struct timeval b;]])], [gl_cv_header_sys_select_h_selfcontained=yes], [gl_cv_header_sys_select_h_selfcontained=no]) dnl Test against another bug: diff --git a/m4/sys_time_h.m4 b/m4/sys_time_h.m4 index 13ac5763b..e2f7809fb 100644 --- a/m4/sys_time_h.m4 +++ b/m4/sys_time_h.m4 @@ -30,12 +30,12 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY], AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[#if HAVE_SYS_TIME_H - #include - #endif - #include - ]], - [[static struct timeval x; x.tv_sec = x.tv_usec;]])], + [[#if HAVE_SYS_TIME_H + #include + #endif + #include + ]], + [[static struct timeval x; x.tv_sec = x.tv_usec;]])], [gl_cv_sys_struct_timeval=yes], [gl_cv_sys_struct_timeval=no])]) if test $gl_cv_sys_struct_timeval = yes; then diff --git a/m4/time_h.m4 b/m4/time_h.m4 index 16fefa197..c038b1761 100644 --- a/m4/time_h.m4 +++ b/m4/time_h.m4 @@ -45,9 +45,9 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], [gl_cv_sys_struct_timespec_in_time_h], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[#include - ]], - [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], + [[#include + ]], + [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], [gl_cv_sys_struct_timespec_in_time_h=yes], [gl_cv_sys_struct_timespec_in_time_h=no])]) @@ -59,12 +59,12 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], AC_CACHE_CHECK([for struct timespec in ], [gl_cv_sys_struct_timespec_in_sys_time_h], [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[#include - ]], - [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], - [gl_cv_sys_struct_timespec_in_sys_time_h=yes], - [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) + [AC_LANG_PROGRAM( + [[#include + ]], + [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], + [gl_cv_sys_struct_timespec_in_sys_time_h=yes], + [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 fi diff --git a/m4/timegm.m4 b/m4/timegm.m4 index be323c9b0..f0fa0b606 100644 --- a/m4/timegm.m4 +++ b/m4/timegm.m4 @@ -34,7 +34,7 @@ AC_DEFUN([gl_PREREQ_TIMEGM], [ # so we need to substitute our own mktime implementation. AC_LIBOBJ([mktime]) AC_DEFINE([mktime], [rpl_mktime], - [Define to rpl_mktime if the replacement function should be used.]) + [Define to rpl_mktime if the replacement function should be used.]) gl_PREREQ_MKTIME]) fi ]) diff --git a/m4/tzset.m4 b/m4/tzset.m4 index 4fed1fd7d..9c1b2a72d 100644 --- a/m4/tzset.m4 +++ b/m4/tzset.m4 @@ -34,11 +34,11 @@ main () putenv ("TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"); tzset (); return (p->tm_year != s.tm_year - || p->tm_mon != s.tm_mon - || p->tm_mday != s.tm_mday - || p->tm_hour != s.tm_hour - || p->tm_min != s.tm_min - || p->tm_sec != s.tm_sec); + || p->tm_mon != s.tm_mon + || p->tm_mday != s.tm_mday + || p->tm_hour != s.tm_hour + || p->tm_min != s.tm_min + || p->tm_sec != s.tm_sec); } ]])], [gl_cv_func_tzset_clobber=no], diff --git a/m4/ungetc.m4 b/m4/ungetc.m4 index eb652356b..e2a3f1fff 100644 --- a/m4/ungetc.m4 +++ b/m4/ungetc.m4 @@ -13,21 +13,21 @@ AC_DEFUN_ONCE([gl_FUNC_UNGETC_WORKS], [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ #include ]], [FILE *f; - if (!(f = fopen ("conftest.tmp", "w+"))) return 1; - if (fputs ("abc", f) < 0) return 2; - rewind (f); - if (fgetc (f) != 'a') return 3; - if (fgetc (f) != 'b') return 4; - if (ungetc ('d', f) != 'd') return 5; - if (ftell (f) != 1) return 6; - if (fgetc (f) != 'd') return 7; - if (ftell (f) != 2) return 8; - if (fseek (f, 0, SEEK_CUR) != 0) return 9; - if (ftell (f) != 2) return 10; - if (fgetc (f) != 'c') return 11; - fclose (f); remove ("conftest.tmp");])], - [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no], - [gl_cv_func_ungetc_works='guessing no']) + if (!(f = fopen ("conftest.tmp", "w+"))) return 1; + if (fputs ("abc", f) < 0) return 2; + rewind (f); + if (fgetc (f) != 'a') return 3; + if (fgetc (f) != 'b') return 4; + if (ungetc ('d', f) != 'd') return 5; + if (ftell (f) != 1) return 6; + if (fgetc (f) != 'd') return 7; + if (ftell (f) != 2) return 8; + if (fseek (f, 0, SEEK_CUR) != 0) return 9; + if (ftell (f) != 2) return 10; + if (fgetc (f) != 'c') return 11; + fclose (f); remove ("conftest.tmp");])], + [gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no], + [gl_cv_func_ungetc_works='guessing no']) ]) if test "$gl_cv_func_ungetc_works" != yes; then AC_DEFINE([FUNC_UNGETC_BROKEN], [1], diff --git a/m4/unlink-busy.m4 b/m4/unlink-busy.m4 index a38eb707c..ce7e1c92e 100644 --- a/m4/unlink-busy.m4 +++ b/m4/unlink-busy.m4 @@ -17,11 +17,11 @@ AC_DEFUN([gl_FUNC_UNLINK_BUSY_TEXT], AC_RUN_IFELSE( [AC_LANG_SOURCE( [AC_INCLUDES_DEFAULT[ - int - main (int argc, char **argv) - { - return !argc || unlink (argv[0]) != 0; - }]])], + int + main (int argc, char **argv) + { + return !argc || unlink (argv[0]) != 0; + }]])], gl_cv_func_unlink_busy_text=yes, gl_cv_func_unlink_busy_text=no, gl_cv_func_unlink_busy_text=no diff --git a/m4/uptime.m4 b/m4/uptime.m4 index d2fbd350e..e018d71fc 100644 --- a/m4/uptime.m4 +++ b/m4/uptime.m4 @@ -18,6 +18,6 @@ AC_DEFUN([gl_SYS_PROC_UPTIME], && gl_cv_have_proc_uptime=yes]) if test $gl_cv_have_proc_uptime = yes; then AC_DEFINE([HAVE_PROC_UPTIME], [1], - [ Define if your system has the /proc/uptime special file.]) + [ Define if your system has the /proc/uptime special file.]) fi ]) diff --git a/m4/utimbuf.m4 b/m4/utimbuf.m4 index 062f73627..8953abcb4 100644 --- a/m4/utimbuf.m4 +++ b/m4/utimbuf.m4 @@ -19,15 +19,15 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_UTIMBUF], AC_CACHE_CHECK([for struct utimbuf], [gl_cv_sys_struct_utimbuf], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( - [[#if HAVE_SYS_TIME_H - #include - #endif - #include - #ifdef HAVE_UTIME_H - #include - #endif - ]], - [[static struct utimbuf x; x.actime = x.modtime;]])], + [[#if HAVE_SYS_TIME_H + #include + #endif + #include + #ifdef HAVE_UTIME_H + #include + #endif + ]], + [[static struct utimbuf x; x.actime = x.modtime;]])], [gl_cv_sys_struct_utimbuf=yes], [gl_cv_sys_struct_utimbuf=no])]) diff --git a/m4/utime.m4 b/m4/utime.m4 index f090e7b04..7ad7f6658 100644 --- a/m4/utime.m4 +++ b/m4/utime.m4 @@ -38,23 +38,23 @@ AC_CACHE_CHECK([whether utime accepts a null argument], [ac_cv_func_utime_null], [rm -f conftest.data; >conftest.data # Sequent interprets utime(file, 0) to mean use start of epoch. Wrong. AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT - #ifdef HAVE_UTIME_H - # include - #endif], + #ifdef HAVE_UTIME_H + # include + #endif], [[struct stat s, t; return ! (stat ("conftest.data", &s) == 0 - && utime ("conftest.data", 0) == 0 - && stat ("conftest.data", &t) == 0 - && t.st_mtime >= s.st_mtime - && t.st_mtime - s.st_mtime < 120);]])], - ac_cv_func_utime_null=yes, - ac_cv_func_utime_null=no, - ac_cv_func_utime_null='guessing yes')]) + && utime ("conftest.data", 0) == 0 + && stat ("conftest.data", &t) == 0 + && t.st_mtime >= s.st_mtime + && t.st_mtime - s.st_mtime < 120);]])], + ac_cv_func_utime_null=yes, + ac_cv_func_utime_null=no, + ac_cv_func_utime_null='guessing yes')]) if test "x$ac_cv_func_utime_null" != xno; then ac_cv_func_utime_null=yes AC_DEFINE([HAVE_UTIME_NULL], [1], - [Define to 1 if `utime(file, NULL)' sets file's timestamp to the - present.]) + [Define to 1 if `utime(file, NULL)' sets file's timestamp to the + present.]) fi rm -f conftest.data ]) diff --git a/m4/utimes-null.m4 b/m4/utimes-null.m4 index 91976f1de..9c9157f48 100644 --- a/m4/utimes-null.m4 +++ b/m4/utimes-null.m4 @@ -23,10 +23,10 @@ int main () { struct stat s, t; return ! (stat ("conftest.data", &s) == 0 - && utimes ("conftest.data", 0) == 0 - && stat ("conftest.data", &t) == 0 - && t.st_mtime >= s.st_mtime - && t.st_mtime - s.st_mtime < 120)); + && utimes ("conftest.data", 0) == 0 + && stat ("conftest.data", &t) == 0 + && t.st_mtime >= s.st_mtime + && t.st_mtime - s.st_mtime < 120)); }]])], [ac_cv_func_utimes_null=yes], [ac_cv_func_utimes_null=no], @@ -35,7 +35,7 @@ rm -f core core.* *.core]) if test $ac_cv_func_utimes_null = yes; then AC_DEFINE([HAVE_UTIMES_NULL], [1], - [Define if utimes accepts a null argument]) + [Define if utimes accepts a null argument]) fi ] ) diff --git a/m4/utimes.m4 b/m4/utimes.m4 index 239a0dbe0..ed7d6aaf5 100644 --- a/m4/utimes.m4 +++ b/m4/utimes.m4 @@ -21,7 +21,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_UTIMES], [ AC_CACHE_CHECK([whether the utimes function works], - [gl_cv_func_working_utimes], + [gl_cv_func_working_utimes], [ AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include @@ -45,11 +45,11 @@ main () int fd; int ok = ((f = fopen (file, "w")) - && fclose (f) == 0 - && utimes (file, timeval) == 0 - && lstat (file, &sbuf) == 0 - && sbuf.st_atime == timeval[0].tv_sec - && sbuf.st_mtime == timeval[1].tv_sec); + && fclose (f) == 0 + && utimes (file, timeval) == 0 + && lstat (file, &sbuf) == 0 + && sbuf.st_atime == timeval[0].tv_sec + && sbuf.st_mtime == timeval[1].tv_sec); unlink (file); if (!ok) exit (1); @@ -67,8 +67,8 @@ main () exit (1); ok = (0 <= (fd = open (file, O_WRONLY|O_CREAT, 0444)) - && close (fd) == 0 - && utimes (file, NULL) == 0); + && close (fd) == 0 + && utimes (file, NULL) == 0); unlink (file); exit (!ok); diff --git a/m4/vararrays.m4 b/m4/vararrays.m4 index 65fb4d963..5e2cb499f 100644 --- a/m4/vararrays.m4 +++ b/m4/vararrays.m4 @@ -14,8 +14,8 @@ AC_DEFUN([AC_C_VARARRAYS], AC_CACHE_CHECK([for variable-length arrays], ac_cv_c_vararrays, [AC_COMPILE_IFELSE([AC_LANG_PROGRAM( - [], - [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])], + [], + [[static int x; char a[++x]; a[sizeof a - 1] = 0; return a[0];]])], ac_cv_c_vararrays=yes, ac_cv_c_vararrays=no)]) if test $ac_cv_c_vararrays = yes; then diff --git a/m4/version-etc.m4 b/m4/version-etc.m4 index 14d6eb6dc..87389de5f 100644 --- a/m4/version-etc.m4 +++ b/m4/version-etc.m4 @@ -11,8 +11,8 @@ m4_define([gl_VERSION_ETC_FLAG], AC_ARG_WITH([$1], [AS_HELP_STRING([--with-$1], [$2])], [dnl case $withval in - yes|no) ;; - *) AC_DEFINE_UNQUOTED(AS_TR_CPP([PACKAGE_$1]), ["$withval"], [$2]) ;; + yes|no) ;; + *) AC_DEFINE_UNQUOTED(AS_TR_CPP([PACKAGE_$1]), ["$withval"], [$2]) ;; esac ]) ]) @@ -20,11 +20,11 @@ m4_define([gl_VERSION_ETC_FLAG], AC_DEFUN([gl_VERSION_ETC], [dnl gl_VERSION_ETC_FLAG([packager], - [String identifying the packager of this software]) + [String identifying the packager of this software]) gl_VERSION_ETC_FLAG([packager-version], - [Packager-specific version information]) + [Packager-specific version information]) gl_VERSION_ETC_FLAG([packager-bug-reports], - [Packager info for bug reports (URL/e-mail/...)]) + [Packager info for bug reports (URL/e-mail/...)]) if test "X$with_packager" = "X" && \ test "X$with_packager_version$with_packager_bug_reports" != "X" then diff --git a/m4/warnings.m4 b/m4/warnings.m4 index c32cf4ed6..1639c0360 100644 --- a/m4/warnings.m4 +++ b/m4/warnings.m4 @@ -33,7 +33,7 @@ AC_CACHE_CHECK([whether compiler handles $1], [gl_Warn], [ CPPFLAGS="${CPPFLAGS} $1" AC_PREPROC_IFELSE([AC_LANG_PROGRAM([])], [AS_VAR_SET([gl_Warn], [yes])], - [AS_VAR_SET([gl_Warn], [no])]) + [AS_VAR_SET([gl_Warn], [no])]) CPPFLAGS="$save_CPPFLAGS" ]) AS_VAR_PUSHDEF([gl_Flags], m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]))dnl diff --git a/tests/test-arcfour.c b/tests/test-arcfour.c index a9b50f84e..ad683fb36 100644 --- a/tests/test-arcfour.c +++ b/tests/test-arcfour.c @@ -39,10 +39,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", ciphertext_1[i] & 0xFF); + printf ("%02x ", ciphertext_1[i] & 0xFF); printf ("\n"); return 1; } @@ -56,10 +56,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", plaintext_1[i] & 0xFF); + printf ("%02x ", plaintext_1[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-arctwo.c b/tests/test-arctwo.c index 64d552151..7f97daeaa 100644 --- a/tests/test-arctwo.c +++ b/tests/test-arctwo.c @@ -116,10 +116,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < sizeof (ciphertext_4); i++) - printf ("%02x ", ciphertext_4[i] & 0xFF); + printf ("%02x ", ciphertext_4[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < sizeof (ciphertext_4); i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } @@ -138,10 +138,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < sizeof (ciphertext_5); i++) - printf ("%02x ", ciphertext_5[i] & 0xFF); + printf ("%02x ", ciphertext_5[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < sizeof (ciphertext_5); i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } @@ -160,10 +160,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < sizeof (ciphertext_6); i++) - printf ("%02x ", ciphertext_6[i] & 0xFF); + printf ("%02x ", ciphertext_6[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < sizeof (ciphertext_6); i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-argmatch.c b/tests/test-argmatch.c index e7eaf5529..c7f157fdb 100644 --- a/tests/test-argmatch.c +++ b/tests/test-argmatch.c @@ -27,15 +27,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Some packages define ARGMATCH_DIE and ARGMATCH_DIE_DECL in , and diff --git a/tests/test-argp.c b/tests/test-argp.c index 2831dc13c..f00f563ed 100644 --- a/tests/test-argp.c +++ b/tests/test-argp.c @@ -228,7 +228,7 @@ parse_opt (int key, char *arg, struct argp_state *state) { case ARGP_KEY_INIT: for (i = 0; state->root_argp->children[i].argp; i++) - state->child_inputs[i] = args; + state->child_inputs[i] = args; break; case 't': @@ -348,7 +348,7 @@ test6(struct argp *argp) void test_optional(struct argp *argp, int argc, char **argv, - struct test_args *args, char *val, char *a) + struct test_args *args, char *val, char *a) { int index; if (argp_parse (argp, argc, argv, 0, &index, args)) @@ -359,7 +359,7 @@ test_optional(struct argp *argp, int argc, char **argv, if (!val) { if (args->optional) - fail("option processed incorrectly"); + fail("option processed incorrectly"); } else if (strcmp (args->optional, val)) fail("option processed incorrectly"); @@ -367,9 +367,9 @@ test_optional(struct argp *argp, int argc, char **argv, if (a) { if (index == argc) - fail("expected command line argument not found"); + fail("expected command line argument not found"); else if (strcmp(argv[index], a)) - fail("expected command line argument does not match"); + fail("expected command line argument does not match"); } } diff --git a/tests/test-array-mergesort.c b/tests/test-array-mergesort.c index 8a47b6765..684231d23 100644 --- a/tests/test-array-mergesort.c +++ b/tests/test-array-mergesort.c @@ -28,15 +28,15 @@ struct foo { double x; double index; }; #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define NMAX 257 @@ -305,8 +305,8 @@ static int cmp_double (const void *a, const void *b) { return (*(const double *)a < *(const double *)b ? -1 : - *(const double *)a > *(const double *)b ? 1 : - 0); + *(const double *)a > *(const double *)b ? 1 : + 0); } int @@ -336,15 +336,15 @@ main () /* Verify the result. */ qsort_result = (double *) malloc (n * sizeof (double)); for (i = 0; i < n; i++) - qsort_result[i] = data[i].x; + qsort_result[i] = data[i].x; qsort (qsort_result, n, sizeof (double), cmp_double); for (i = 0; i < n; i++) - ASSERT (dst[i].x == qsort_result[i]); + ASSERT (dst[i].x == qsort_result[i]); /* Verify the stability. */ for (i = 0; i < n; i++) - if (i > 0 && dst[i - 1].x == dst[i].x) - ASSERT (dst[i - 1].index < dst[i].index); + if (i > 0 && dst[i - 1].x == dst[i].x) + ASSERT (dst[i - 1].index < dst[i].index); free (qsort_result); free (tmp); @@ -365,7 +365,7 @@ main () tmp[n].x = 0x587EF149; /* canary */ for (i = 0; i < n; i++) - src[i] = data[i]; + src[i] = data[i]; merge_sort_inplace (src, n, tmp); @@ -376,15 +376,15 @@ main () /* Verify the result. */ qsort_result = (double *) malloc (n * sizeof (double)); for (i = 0; i < n; i++) - qsort_result[i] = data[i].x; + qsort_result[i] = data[i].x; qsort (qsort_result, n, sizeof (double), cmp_double); for (i = 0; i < n; i++) - ASSERT (src[i].x == qsort_result[i]); + ASSERT (src[i].x == qsort_result[i]); /* Verify the stability. */ for (i = 0; i < n; i++) - if (i > 0 && src[i - 1].x == src[i].x) - ASSERT (src[i - 1].index < src[i].index); + if (i > 0 && src[i - 1].x == src[i].x) + ASSERT (src[i - 1].index < src[i].index); free (qsort_result); free (tmp); diff --git a/tests/test-array_list.c b/tests/test-array_list.c index 9426294e7..48619e4fe 100644 --- a/tests/test-array_list.c +++ b/tests/test-array_list.c @@ -31,15 +31,15 @@ static const char *objects[15] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-array_oset.c b/tests/test-array_oset.c index 5aba7e0e5..32fd191a1 100644 --- a/tests/test-array_oset.c +++ b/tests/test-array_oset.c @@ -34,15 +34,15 @@ static const char *objects[30] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] @@ -108,9 +108,9 @@ main (int argc, char *argv[]) { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_add (set1, obj) - == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL - ? false - : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true))); + == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL + ? false + : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true))); check_all (set1, set2); } @@ -123,23 +123,23 @@ main (int argc, char *argv[]) { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_search (set1, obj) - == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL)); + == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL)); } break; case 1: { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_add (set1, obj) - == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL - ? false - : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true))); + == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL + ? false + : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true))); } break; case 2: { const char *obj = RANDOM_OBJECT (); ASSERT (gl_oset_remove (set1, obj) - == gl_sortedlist_remove (set2, (gl_listelement_compar_fn)strcmp, obj)); + == gl_sortedlist_remove (set2, (gl_listelement_compar_fn)strcmp, obj)); } break; } diff --git a/tests/test-avltree_list.c b/tests/test-avltree_list.c index 28b97a0e5..af18059c7 100644 --- a/tests/test-avltree_list.c +++ b/tests/test-avltree_list.c @@ -34,15 +34,15 @@ static const char *objects[15] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-avltree_oset.c b/tests/test-avltree_oset.c index 3bdf0aa98..987237812 100644 --- a/tests/test-avltree_oset.c +++ b/tests/test-avltree_oset.c @@ -36,15 +36,15 @@ static const char *objects[30] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-avltreehash_list.c b/tests/test-avltreehash_list.c index 19feca019..cea8519b6 100644 --- a/tests/test-avltreehash_list.c +++ b/tests/test-avltreehash_list.c @@ -61,15 +61,15 @@ string_hash (const void *x) #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-base64.c b/tests/test-base64.c index 8d4a0c641..c2067284e 100644 --- a/tests/test-base64.c +++ b/tests/test-base64.c @@ -26,16 +26,16 @@ #include "base64.h" -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-binary-io.c b/tests/test-binary-io.c index 7e351086c..335989fc0 100644 --- a/tests/test-binary-io.c +++ b/tests/test-binary-io.c @@ -28,15 +28,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-bitrotate.c b/tests/test-bitrotate.c index 15c378560..db26ef827 100644 --- a/tests/test-bitrotate.c +++ b/tests/test-bitrotate.c @@ -23,17 +23,17 @@ #include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", \ - __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", \ + __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-btowc.c b/tests/test-btowc.c index ce9cfea62..b447d05a1 100644 --- a/tests/test-btowc.c +++ b/tests/test-btowc.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -51,20 +51,20 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - for (c = 0; c < 0x80; c++) - ASSERT (btowc (c) == c); - for (c = 0xA0; c < 0x100; c++) - ASSERT (btowc (c) != WEOF); - return 0; + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + for (c = 0; c < 0x80; c++) + ASSERT (btowc (c) == c); + for (c = 0xA0; c < 0x100; c++) + ASSERT (btowc (c) != WEOF); + return 0; case '2': - /* Locale encoding is UTF-8. */ - for (c = 0; c < 0x80; c++) - ASSERT (btowc (c) == c); - for (c = 0x80; c < 0x100; c++) - ASSERT (btowc (c) == WEOF); - return 0; + /* Locale encoding is UTF-8. */ + for (c = 0; c < 0x80; c++) + ASSERT (btowc (c) == c); + for (c = 0x80; c < 0x100; c++) + ASSERT (btowc (c) == WEOF); + return 0; } return 1; diff --git a/tests/test-byteswap.c b/tests/test-byteswap.c index 78f142d72..55de36bf0 100644 --- a/tests/test-byteswap.c +++ b/tests/test-byteswap.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-c-ctype.c b/tests/test-c-ctype.c index 6d7fe1b7a..e04de2ef9 100644 --- a/tests/test-c-ctype.c +++ b/tests/test-c-ctype.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -46,81 +46,81 @@ test_all (void) ASSERT (c_isascii (c) == (c >= 0 && c < 0x80)); 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': - case '0': case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - ASSERT (c_isalnum (c) == 1); - break; - default: - ASSERT (c_isalnum (c) == 0); - break; - } + { + 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': + case '0': case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + ASSERT (c_isalnum (c) == 1); + break; + default: + ASSERT (c_isalnum (c) == 0); + break; + } 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': - ASSERT (c_isalpha (c) == 1); - break; - default: - ASSERT (c_isalpha (c) == 0); - break; - } + { + 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': + ASSERT (c_isalpha (c) == 1); + break; + default: + ASSERT (c_isalpha (c) == 0); + break; + } switch (c) - { - case '\t': case ' ': - ASSERT (c_isblank (c) == 1); - break; - default: - ASSERT (c_isblank (c) == 0); - break; - } + { + case '\t': case ' ': + ASSERT (c_isblank (c) == 1); + break; + default: + ASSERT (c_isblank (c) == 0); + break; + } ASSERT (c_iscntrl (c) == ((c >= 0 && c < 0x20) || c == 0x7f)); switch (c) - { - case '0': case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - ASSERT (c_isdigit (c) == 1); - break; - default: - ASSERT (c_isdigit (c) == 0); - break; - } + { + case '0': case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + ASSERT (c_isdigit (c) == 1); + break; + default: + ASSERT (c_isdigit (c) == 0); + break; + } 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': - ASSERT (c_islower (c) == 1); - break; - default: - ASSERT (c_islower (c) == 0); - break; - } + { + 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': + ASSERT (c_islower (c) == 1); + break; + default: + ASSERT (c_islower (c) == 0); + break; + } ASSERT (c_isgraph (c) == ((c >= 0x20 && c < 0x7f) && c != ' ')); @@ -129,257 +129,257 @@ test_all (void) ASSERT (c_ispunct (c) == (c_isgraph (c) && !c_isalnum (c))); switch (c) - { - case ' ': case '\t': case '\n': case '\v': case '\f': case '\r': - ASSERT (c_isspace (c) == 1); - break; - default: - ASSERT (c_isspace (c) == 0); - break; - } + { + case ' ': case '\t': case '\n': case '\v': case '\f': case '\r': + ASSERT (c_isspace (c) == 1); + break; + default: + ASSERT (c_isspace (c) == 0); + break; + } 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': - ASSERT (c_isupper (c) == 1); - break; - default: - ASSERT (c_isupper (c) == 0); - break; - } + { + 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': + ASSERT (c_isupper (c) == 1); + break; + default: + ASSERT (c_isupper (c) == 0); + break; + } 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': - ASSERT (c_isxdigit (c) == 1); - break; - default: - ASSERT (c_isxdigit (c) == 0); - break; - } + { + 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': + ASSERT (c_isxdigit (c) == 1); + break; + default: + ASSERT (c_isxdigit (c) == 0); + break; + } switch (c) - { - case 'A': - ASSERT (c_tolower (c) == 'a'); - ASSERT (c_toupper (c) == c); - break; - case 'B': - ASSERT (c_tolower (c) == 'b'); - ASSERT (c_toupper (c) == c); - break; - case 'C': - ASSERT (c_tolower (c) == 'c'); - ASSERT (c_toupper (c) == c); - break; - case 'D': - ASSERT (c_tolower (c) == 'd'); - ASSERT (c_toupper (c) == c); - break; - case 'E': - ASSERT (c_tolower (c) == 'e'); - ASSERT (c_toupper (c) == c); - break; - case 'F': - ASSERT (c_tolower (c) == 'f'); - ASSERT (c_toupper (c) == c); - break; - case 'G': - ASSERT (c_tolower (c) == 'g'); - ASSERT (c_toupper (c) == c); - break; - case 'H': - ASSERT (c_tolower (c) == 'h'); - ASSERT (c_toupper (c) == c); - break; - case 'I': - ASSERT (c_tolower (c) == 'i'); - ASSERT (c_toupper (c) == c); - break; - case 'J': - ASSERT (c_tolower (c) == 'j'); - ASSERT (c_toupper (c) == c); - break; - case 'K': - ASSERT (c_tolower (c) == 'k'); - ASSERT (c_toupper (c) == c); - break; - case 'L': - ASSERT (c_tolower (c) == 'l'); - ASSERT (c_toupper (c) == c); - break; - case 'M': - ASSERT (c_tolower (c) == 'm'); - ASSERT (c_toupper (c) == c); - break; - case 'N': - ASSERT (c_tolower (c) == 'n'); - ASSERT (c_toupper (c) == c); - break; - case 'O': - ASSERT (c_tolower (c) == 'o'); - ASSERT (c_toupper (c) == c); - break; - case 'P': - ASSERT (c_tolower (c) == 'p'); - ASSERT (c_toupper (c) == c); - break; - case 'Q': - ASSERT (c_tolower (c) == 'q'); - ASSERT (c_toupper (c) == c); - break; - case 'R': - ASSERT (c_tolower (c) == 'r'); - ASSERT (c_toupper (c) == c); - break; - case 'S': - ASSERT (c_tolower (c) == 's'); - ASSERT (c_toupper (c) == c); - break; - case 'T': - ASSERT (c_tolower (c) == 't'); - ASSERT (c_toupper (c) == c); - break; - case 'U': - ASSERT (c_tolower (c) == 'u'); - ASSERT (c_toupper (c) == c); - break; - case 'V': - ASSERT (c_tolower (c) == 'v'); - ASSERT (c_toupper (c) == c); - break; - case 'W': - ASSERT (c_tolower (c) == 'w'); - ASSERT (c_toupper (c) == c); - break; - case 'X': - ASSERT (c_tolower (c) == 'x'); - ASSERT (c_toupper (c) == c); - break; - case 'Y': - ASSERT (c_tolower (c) == 'y'); - ASSERT (c_toupper (c) == c); - break; - case 'Z': - ASSERT (c_tolower (c) == 'z'); - ASSERT (c_toupper (c) == c); - break; - case 'a': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'A'); - break; - case 'b': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'B'); - break; - case 'c': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'C'); - break; - case 'd': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'D'); - break; - case 'e': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'E'); - break; - case 'f': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'F'); - break; - case 'g': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'G'); - break; - case 'h': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'H'); - break; - case 'i': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'I'); - break; - case 'j': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'J'); - break; - case 'k': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'K'); - break; - case 'l': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'L'); - break; - case 'm': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'M'); - break; - case 'n': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'N'); - break; - case 'o': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'O'); - break; - case 'p': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'P'); - break; - case 'q': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'Q'); - break; - case 'r': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'R'); - break; - case 's': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'S'); - break; - case 't': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'T'); - break; - case 'u': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'U'); - break; - case 'v': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'V'); - break; - case 'w': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'W'); - break; - case 'x': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'X'); - break; - case 'y': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'Y'); - break; - case 'z': - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == 'Z'); - break; - default: - ASSERT (c_tolower (c) == c); - ASSERT (c_toupper (c) == c); - break; - } + { + case 'A': + ASSERT (c_tolower (c) == 'a'); + ASSERT (c_toupper (c) == c); + break; + case 'B': + ASSERT (c_tolower (c) == 'b'); + ASSERT (c_toupper (c) == c); + break; + case 'C': + ASSERT (c_tolower (c) == 'c'); + ASSERT (c_toupper (c) == c); + break; + case 'D': + ASSERT (c_tolower (c) == 'd'); + ASSERT (c_toupper (c) == c); + break; + case 'E': + ASSERT (c_tolower (c) == 'e'); + ASSERT (c_toupper (c) == c); + break; + case 'F': + ASSERT (c_tolower (c) == 'f'); + ASSERT (c_toupper (c) == c); + break; + case 'G': + ASSERT (c_tolower (c) == 'g'); + ASSERT (c_toupper (c) == c); + break; + case 'H': + ASSERT (c_tolower (c) == 'h'); + ASSERT (c_toupper (c) == c); + break; + case 'I': + ASSERT (c_tolower (c) == 'i'); + ASSERT (c_toupper (c) == c); + break; + case 'J': + ASSERT (c_tolower (c) == 'j'); + ASSERT (c_toupper (c) == c); + break; + case 'K': + ASSERT (c_tolower (c) == 'k'); + ASSERT (c_toupper (c) == c); + break; + case 'L': + ASSERT (c_tolower (c) == 'l'); + ASSERT (c_toupper (c) == c); + break; + case 'M': + ASSERT (c_tolower (c) == 'm'); + ASSERT (c_toupper (c) == c); + break; + case 'N': + ASSERT (c_tolower (c) == 'n'); + ASSERT (c_toupper (c) == c); + break; + case 'O': + ASSERT (c_tolower (c) == 'o'); + ASSERT (c_toupper (c) == c); + break; + case 'P': + ASSERT (c_tolower (c) == 'p'); + ASSERT (c_toupper (c) == c); + break; + case 'Q': + ASSERT (c_tolower (c) == 'q'); + ASSERT (c_toupper (c) == c); + break; + case 'R': + ASSERT (c_tolower (c) == 'r'); + ASSERT (c_toupper (c) == c); + break; + case 'S': + ASSERT (c_tolower (c) == 's'); + ASSERT (c_toupper (c) == c); + break; + case 'T': + ASSERT (c_tolower (c) == 't'); + ASSERT (c_toupper (c) == c); + break; + case 'U': + ASSERT (c_tolower (c) == 'u'); + ASSERT (c_toupper (c) == c); + break; + case 'V': + ASSERT (c_tolower (c) == 'v'); + ASSERT (c_toupper (c) == c); + break; + case 'W': + ASSERT (c_tolower (c) == 'w'); + ASSERT (c_toupper (c) == c); + break; + case 'X': + ASSERT (c_tolower (c) == 'x'); + ASSERT (c_toupper (c) == c); + break; + case 'Y': + ASSERT (c_tolower (c) == 'y'); + ASSERT (c_toupper (c) == c); + break; + case 'Z': + ASSERT (c_tolower (c) == 'z'); + ASSERT (c_toupper (c) == c); + break; + case 'a': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'A'); + break; + case 'b': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'B'); + break; + case 'c': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'C'); + break; + case 'd': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'D'); + break; + case 'e': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'E'); + break; + case 'f': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'F'); + break; + case 'g': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'G'); + break; + case 'h': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'H'); + break; + case 'i': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'I'); + break; + case 'j': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'J'); + break; + case 'k': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'K'); + break; + case 'l': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'L'); + break; + case 'm': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'M'); + break; + case 'n': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'N'); + break; + case 'o': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'O'); + break; + case 'p': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'P'); + break; + case 'q': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'Q'); + break; + case 'r': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'R'); + break; + case 's': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'S'); + break; + case 't': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'T'); + break; + case 'u': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'U'); + break; + case 'v': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'V'); + break; + case 'w': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'W'); + break; + case 'x': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'X'); + break; + case 'y': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'Y'); + break; + case 'z': + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == 'Z'); + break; + default: + ASSERT (c_tolower (c) == c); + ASSERT (c_toupper (c) == c); + break; + } } } diff --git a/tests/test-c-stack.c b/tests/test-c-stack.c index 96ab152c0..b5ff6be65 100644 --- a/tests/test-c-stack.c +++ b/tests/test-c-stack.c @@ -30,15 +30,15 @@ #endif #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) char *program_name; @@ -75,10 +75,10 @@ main (int argc, char **argv) if (c_stack_action (0) == 0) { if (1 < argc) - { - exit_failure = 77; - ++*argv[argc]; /* Intentionally dereference NULL. */ - } + { + exit_failure = 77; + ++*argv[argc]; /* Intentionally dereference NULL. */ + } return recurse (0); } fputs ("skipping test: ", stderr); diff --git a/tests/test-c-strcasecmp.c b/tests/test-c-strcasecmp.c index 16244b9f3..e0c23685d 100644 --- a/tests/test-c-strcasecmp.c +++ b/tests/test-c-strcasecmp.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -44,7 +44,7 @@ main (int argc, char *argv[]) { /* configure should already have checked that the locale is supported. */ if (setlocale (LC_ALL, "") == NULL) - return 1; + return 1; } ASSERT (c_strcasecmp ("paragraph", "Paragraph") == 0); diff --git a/tests/test-c-strcasestr.c b/tests/test-c-strcasestr.c index e3ff0e286..0c8a40db5 100644 --- a/tests/test-c-strcasestr.c +++ b/tests/test-c-strcasestr.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -81,16 +81,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = 'B'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (c_strcasestr (haystack, needle) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (c_strcasestr (haystack, needle) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -105,15 +105,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (c_strcasestr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (c_strcasestr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -124,18 +124,18 @@ main () char *needle = (char *) malloc (m + 2); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = '\0'; - memset (needle, 'a', m); - needle[m] = 'B'; - needle[m + 1] = '\0'; + memset (needle, 'a', m); + needle[m] = 'B'; + needle[m + 1] = '\0'; - result = c_strcasestr (haystack, needle); - ASSERT (result == haystack + m); + result = c_strcasestr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-c-strncasecmp.c b/tests/test-c-strncasecmp.c index 7d6dbf50a..fb5f22003 100644 --- a/tests/test-c-strncasecmp.c +++ b/tests/test-c-strncasecmp.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -44,7 +44,7 @@ main (int argc, char *argv[]) { /* configure should already have checked that the locale is supported. */ if (setlocale (LC_ALL, "") == NULL) - return 1; + return 1; } ASSERT (c_strncasecmp ("paragraph", "Paragraph", 1000000) == 0); diff --git a/tests/test-c-strstr.c b/tests/test-c-strstr.c index 2bd0cf0d4..2b2ebf91c 100644 --- a/tests/test-c-strstr.c +++ b/tests/test-c-strstr.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -74,16 +74,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = 'B'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (c_strstr (haystack, needle) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (c_strstr (haystack, needle) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -98,15 +98,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (c_strstr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (c_strstr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -117,18 +117,18 @@ main () char *needle = (char *) malloc (m + 2); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = '\0'; - memset (needle, 'A', m); - needle[m] = 'B'; - needle[m + 1] = '\0'; + memset (needle, 'A', m); + needle[m] = 'B'; + needle[m + 1] = '\0'; - result = c_strstr (haystack, needle); - ASSERT (result == haystack + m); + result = c_strstr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index ef6bd9d1b..19109d583 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -30,15 +30,15 @@ #include "same-inode.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define BASE "t-can-lgpl.tmp" @@ -68,7 +68,7 @@ main (void) char *result = canonicalize_file_name (BASE "//./..//" BASE "/tra"); ASSERT (result != NULL); ASSERT (strstr (result, "/" BASE "/tra") - == result + strlen (result) - strlen ("/" BASE "/tra")); + == result + strlen (result) - strlen ("/" BASE "/tra")); free (result); errno = 0; result = canonicalize_file_name (""); @@ -104,7 +104,7 @@ main (void) ASSERT (remove (BASE "/tra") == 0); ASSERT (rmdir (BASE) == 0); fputs ("skipping test: symlinks not supported on this file system\n", - stderr); + stderr); return 77; } ASSERT (symlink ("bef", BASE "/plo") == 0); @@ -123,7 +123,7 @@ main (void) ASSERT (result2 != NULL); ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/tra"), - "/" BASE "/tra") == 0); + "/" BASE "/tra") == 0); free (result1); free (result2); } @@ -139,7 +139,7 @@ main (void) ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/lum"), - "/" BASE "/lum") == 0); + "/" BASE "/lum") == 0); free (result1); free (result2); free (result3); @@ -193,13 +193,13 @@ main (void) ASSERT (stat ("//", &st2) == 0); if (SAME_INODE (st1, st2)) { - ASSERT (strcmp (result1, "/") == 0); - ASSERT (strcmp (result2, "/") == 0); + ASSERT (strcmp (result1, "/") == 0); + ASSERT (strcmp (result2, "/") == 0); } else { - ASSERT (strcmp (result1, "//") == 0); - ASSERT (strcmp (result2, "//") == 0); + ASSERT (strcmp (result1, "//") == 0); + ASSERT (strcmp (result2, "//") == 0); } free (result1); free (result2); diff --git a/tests/test-canonicalize.c b/tests/test-canonicalize.c index eeae9e0d9..749cc1eec 100644 --- a/tests/test-canonicalize.c +++ b/tests/test-canonicalize.c @@ -31,15 +31,15 @@ #include "same-inode.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define BASE "t-can.tmp" @@ -67,7 +67,7 @@ main (void) ASSERT (result2 != NULL); ASSERT (strcmp (result1, result2) == 0); ASSERT (strstr (result1, "/" BASE "/tra") - == result1 + strlen (result1) - strlen ("/" BASE "/tra")); + == result1 + strlen (result1) - strlen ("/" BASE "/tra")); free (result1); free (result2); errno = 0; @@ -122,7 +122,7 @@ main (void) ASSERT (remove (BASE "/tra") == 0); ASSERT (rmdir (BASE) == 0); fputs ("skipping test: symlinks not supported on this file system\n", - stderr); + stderr); return 77; } ASSERT (symlink ("bef", BASE "/plo") == 0); diff --git a/tests/test-carray_list.c b/tests/test-carray_list.c index f29f74c14..04c39557f 100644 --- a/tests/test-carray_list.c +++ b/tests/test-carray_list.c @@ -32,15 +32,15 @@ static const char *objects[15] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-ceilf1.c b/tests/test-ceilf1.c index 8931a62af..32419366b 100644 --- a/tests/test-ceilf1.c +++ b/tests/test-ceilf1.c @@ -27,15 +27,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f. diff --git a/tests/test-ceilf2.c b/tests/test-ceilf2.c index 17aac846a..ec0f60849 100644 --- a/tests/test-ceilf2.c +++ b/tests/test-ceilf2.c @@ -29,15 +29,15 @@ #include "isnanf-nolibm.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) @@ -74,27 +74,27 @@ ceilf_reference (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; } @@ -131,9 +131,9 @@ check (float x) return 0; else { - fprintf (stderr, "ceilf %g(%a) = %g(%a) or %g(%a)?\n", - x, x, reference, reference, result, result); - return 1; + fprintf (stderr, "ceilf %g(%a) = %g(%a) or %g(%a)?\n", + x, x, reference, reference, result, result); + return 1; } } } @@ -150,14 +150,14 @@ main () for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++) for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++) { - /* Combine highbits and lowbits into a floating-point number, - sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ - union { float f; uint32_t i; } janus; - janus.i = ((uint32_t) highbits << (32 - NUM_HIGHBITS)) - | ((uint32_t) ((int32_t) ((uint32_t) lowbits << (32 - NUM_LOWBITS)) - >> (32 - NUM_LOWBITS - NUM_HIGHBITS)) - >> NUM_HIGHBITS); - error |= check (janus.f); + /* Combine highbits and lowbits into a floating-point number, + sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ + union { float f; uint32_t i; } janus; + janus.i = ((uint32_t) highbits << (32 - NUM_HIGHBITS)) + | ((uint32_t) ((int32_t) ((uint32_t) lowbits << (32 - NUM_LOWBITS)) + >> (32 - NUM_LOWBITS - NUM_HIGHBITS)) + >> NUM_HIGHBITS); + error |= check (janus.f); } return (error ? 1 : 0); } diff --git a/tests/test-ceill.c b/tests/test-ceill.c index 3d4c9e3e8..764d2beaf 100644 --- a/tests/test-ceill.c +++ b/tests/test-ceill.c @@ -29,15 +29,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On HP-UX 10.20, negating 0.0L does not yield -0.0L. diff --git a/tests/test-copy-acl.c b/tests/test-copy-acl.c index 1ea820680..198d59d80 100644 --- a/tests/test-copy-acl.c +++ b/tests/test-copy-acl.c @@ -30,15 +30,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-copy-file.c b/tests/test-copy-file.c index a1c78932e..a2bb421f1 100644 --- a/tests/test-copy-file.c +++ b/tests/test-copy-file.c @@ -26,15 +26,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-des.c b/tests/test-des.c index af1cb653d..ddd2e7f13 100644 --- a/tests/test-des.c +++ b/tests/test-des.c @@ -42,13 +42,13 @@ main (int argc, char *argv[]) for (i = 0; i < 64; ++i) { - gl_des_setkey (&des, key); - gl_des_ecb_encrypt (&des, input, temp1); - gl_des_ecb_encrypt (&des, temp1, temp2); - gl_des_setkey (&des, temp2); - gl_des_ecb_decrypt (&des, temp1, temp3); - memcpy (key, temp3, 8); - memcpy (input, temp1, 8); + gl_des_setkey (&des, key); + gl_des_ecb_encrypt (&des, input, temp1); + gl_des_ecb_encrypt (&des, temp1, temp2); + gl_des_setkey (&des, temp2); + gl_des_ecb_decrypt (&des, temp1, temp3); + memcpy (key, temp3, 8); + memcpy (input, temp1, 8); } if (memcmp (temp3, result, 8)) return 1; @@ -69,11 +69,11 @@ main (int argc, char *argv[]) for (i = 0; i < 16; ++i) { - gl_3des_set2keys (&des3, key1, key2); - gl_3des_ecb_encrypt (&des3, input, key1); - gl_3des_ecb_decrypt (&des3, input, key2); - gl_3des_set3keys (&des3, key1, input, key2); - gl_3des_ecb_encrypt (&des3, input, input); + gl_3des_set2keys (&des3, key1, key2); + gl_3des_ecb_encrypt (&des3, input, key1); + gl_3des_ecb_decrypt (&des3, input, key2); + gl_3des_set3keys (&des3, key1, input, key2); + gl_3des_ecb_encrypt (&des3, input, input); } if (memcmp (input, result, 8)) return 1; @@ -92,103 +92,103 @@ main (int argc, char *argv[]) } testdata[] = { { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, - { - 0x95, 0xF8, 0xA5, 0xE5, 0xDD, 0x31, 0xD9, 0x00}, - { + { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, + { + 0x95, 0xF8, 0xA5, 0xE5, 0xDD, 0x31, 0xD9, 0x00}, + { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, - { - 0x9D, 0x64, 0x55, 0x5A, 0x9A, 0x10, 0xB8, 0x52,}, - { - 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00} + { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, + { + 0x9D, 0x64, 0x55, 0x5A, 0x9A, 0x10, 0xB8, 0x52,}, + { + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00} }, { - { - 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E, - 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E, - 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E}, - { - 0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A}, - { - 0x71, 0x78, 0x87, 0x6E, 0x01, 0xF1, 0x9B, 0x2A} + { + 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E, + 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E, + 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E}, + { + 0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A}, + { + 0x71, 0x78, 0x87, 0x6E, 0x01, 0xF1, 0x9B, 0x2A} }, { - { - 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6, - 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6, - 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6}, - { - 0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2}, - { - 0xAF, 0x37, 0xFB, 0x42, 0x1F, 0x8C, 0x40, 0x95} + { + 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6, + 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6, + 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6}, + { + 0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2}, + { + 0xAF, 0x37, 0xFB, 0x42, 0x1F, 0x8C, 0x40, 0x95} }, { - { - 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, - { - 0x73, 0x6F, 0x6D, 0x65, 0x64, 0x61, 0x74, 0x61}, - { - 0x3D, 0x12, 0x4F, 0xE2, 0x19, 0x8B, 0xA3, 0x18} + { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, + { + 0x73, 0x6F, 0x6D, 0x65, 0x64, 0x61, 0x74, 0x61}, + { + 0x3D, 0x12, 0x4F, 0xE2, 0x19, 0x8B, 0xA3, 0x18} }, { - { - 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, - { - 0x73, 0x6F, 0x6D, 0x65, 0x64, 0x61, 0x74, 0x61}, - { - 0xFB, 0xAB, 0xA1, 0xFF, 0x9D, 0x05, 0xE9, 0xB1} + { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, + { + 0x73, 0x6F, 0x6D, 0x65, 0x64, 0x61, 0x74, 0x61}, + { + 0xFB, 0xAB, 0xA1, 0xFF, 0x9D, 0x05, 0xE9, 0xB1} }, { - { - 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}, - { - 0x73, 0x6F, 0x6D, 0x65, 0x64, 0x61, 0x74, 0x61}, - { - 0x18, 0xd7, 0x48, 0xe5, 0x63, 0x62, 0x05, 0x72} + { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}, + { + 0x73, 0x6F, 0x6D, 0x65, 0x64, 0x61, 0x74, 0x61}, + { + 0x18, 0xd7, 0x48, 0xe5, 0x63, 0x62, 0x05, 0x72} }, { - { - 0x03, 0x52, 0x02, 0x07, 0x67, 0x20, 0x82, 0x17, - 0x86, 0x02, 0x87, 0x66, 0x59, 0x08, 0x21, 0x98, - 0x64, 0x05, 0x6A, 0xBD, 0xFE, 0xA9, 0x34, 0x57}, - { - 0x73, 0x71, 0x75, 0x69, 0x67, 0x67, 0x6C, 0x65}, - { - 0xc0, 0x7d, 0x2a, 0x0f, 0xa5, 0x66, 0xfa, 0x30} + { + 0x03, 0x52, 0x02, 0x07, 0x67, 0x20, 0x82, 0x17, + 0x86, 0x02, 0x87, 0x66, 0x59, 0x08, 0x21, 0x98, + 0x64, 0x05, 0x6A, 0xBD, 0xFE, 0xA9, 0x34, 0x57}, + { + 0x73, 0x71, 0x75, 0x69, 0x67, 0x67, 0x6C, 0x65}, + { + 0xc0, 0x7d, 0x2a, 0x0f, 0xa5, 0x66, 0xfa, 0x30} }, { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02}, - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - { - 0xe6, 0xe6, 0xdd, 0x5b, 0x7e, 0x72, 0x29, 0x74} + { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02}, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + { + 0xe6, 0xe6, 0xdd, 0x5b, 0x7e, 0x72, 0x29, 0x74} }, { - { - 0x10, 0x46, 0x10, 0x34, 0x89, 0x98, 0x80, 0x20, - 0x91, 0x07, 0xD0, 0x15, 0x89, 0x19, 0x01, 0x01, - 0x19, 0x07, 0x92, 0x10, 0x98, 0x1A, 0x01, 0x01}, - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - { - 0xe1, 0xef, 0x62, 0xc3, 0x32, 0xfe, 0x82, 0x5b} + { + 0x10, 0x46, 0x10, 0x34, 0x89, 0x98, 0x80, 0x20, + 0x91, 0x07, 0xD0, 0x15, 0x89, 0x19, 0x01, 0x01, + 0x19, 0x07, 0x92, 0x10, 0x98, 0x1A, 0x01, 0x01}, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + { + 0xe1, 0xef, 0x62, 0xc3, 0x32, 0xfe, 0x82, 0x5b} } }; @@ -198,20 +198,20 @@ main (int argc, char *argv[]) for (i = 0; i < sizeof (testdata) / sizeof (*testdata); ++i) { - gl_3des_set3keys (&des3, testdata[i].key, - testdata[i].key + 8, testdata[i].key + 16); - - gl_3des_ecb_encrypt (&des3, testdata[i].plain, result); - if (memcmp (testdata[i].cipher, result, 8)) - { - return 1; - } - - gl_3des_ecb_decrypt (&des3, testdata[i].cipher, result); - if (memcmp (testdata[i].plain, result, 8)) - { - return 1; - } + gl_3des_set3keys (&des3, testdata[i].key, + testdata[i].key + 8, testdata[i].key + 16); + + gl_3des_ecb_encrypt (&des3, testdata[i].plain, result); + if (memcmp (testdata[i].cipher, result, 8)) + { + return 1; + } + + gl_3des_ecb_decrypt (&des3, testdata[i].cipher, result); + if (memcmp (testdata[i].plain, result, 8)) + { + return 1; + } } } diff --git a/tests/test-dirname.c b/tests/test-dirname.c index debda3f1c..673c66b66 100644 --- a/tests/test-dirname.c +++ b/tests/test-dirname.c @@ -24,108 +24,108 @@ #include struct test { - const char *name; /* Name under test. */ - const char *dir; /* dir_name (name). */ - const char *last; /* last_component (name). */ - const char *base; /* base_name (name). */ - const char *stripped; /* name after strip_trailing_slashes (name). */ + const char *name; /* Name under test. */ + const char *dir; /* dir_name (name). */ + const char *last; /* last_component (name). */ + const char *base; /* base_name (name). */ + const char *stripped; /* name after strip_trailing_slashes (name). */ bool modified; /* result of strip_trailing_slashes (name). */ - bool absolute; /* IS_ABSOLUTE_FILE_NAME (name). */ + bool absolute; /* IS_ABSOLUTE_FILE_NAME (name). */ }; static struct test tests[] = { - {"d/f", "d", "f", "f", "d/f", false, false}, - {"/d/f", "/d", "f", "f", "/d/f", false, true}, - {"d/f/", "d", "f/", "f/", "d/f", true, false}, - {"d/f//", "d", "f//", "f/", "d/f", true, false}, - {"f", ".", "f", "f", "f", false, false}, - {"/", "/", "", "/", "/", false, true}, + {"d/f", "d", "f", "f", "d/f", false, false}, + {"/d/f", "/d", "f", "f", "/d/f", false, true}, + {"d/f/", "d", "f/", "f/", "d/f", true, false}, + {"d/f//", "d", "f//", "f/", "d/f", true, false}, + {"f", ".", "f", "f", "f", false, false}, + {"/", "/", "", "/", "/", false, true}, #if DOUBLE_SLASH_IS_DISTINCT_ROOT - {"//", "//", "", "//", "//", false, true}, - {"//d", "//", "d", "d", "//d", false, true}, + {"//", "//", "", "//", "//", false, true}, + {"//d", "//", "d", "d", "//d", false, true}, #else - {"//", "/", "", "/", "/", true, true}, - {"//d", "/", "d", "d", "//d", false, true}, + {"//", "/", "", "/", "/", true, true}, + {"//d", "/", "d", "d", "//d", false, true}, #endif - {"///", "/", "", "/", "/", true, true}, - {"///a///", "/", "a///", "a/", "///a", true, true}, + {"///", "/", "", "/", "/", true, true}, + {"///a///", "/", "a///", "a/", "///a", true, true}, /* POSIX requires dirname("") and basename("") to both return ".", but dir_name and base_name are defined differently. */ - {"", ".", "", "", "", false, false}, - {".", ".", ".", ".", ".", false, false}, - {"..", ".", "..", "..", "..", false, false}, + {"", ".", "", "", "", false, false}, + {".", ".", ".", ".", ".", false, false}, + {"..", ".", "..", "..", "..", false, false}, #if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR - {"a\\", ".", "a\\", "a\\", "a", true, false}, - {"a\\b", "a", "b", "b", "a\\b", false, false}, - {"\\", "\\", "", "\\", "\\", false, true}, - {"\\/\\", "\\", "", "\\", "\\", true, true}, - {"\\\\/", "\\", "", "\\", "\\", true, true}, - {"\\//", "\\", "", "\\", "\\", true, true}, - {"//\\", "/", "", "/", "/", true, true}, + {"a\\", ".", "a\\", "a\\", "a", true, false}, + {"a\\b", "a", "b", "b", "a\\b", false, false}, + {"\\", "\\", "", "\\", "\\", false, true}, + {"\\/\\", "\\", "", "\\", "\\", true, true}, + {"\\\\/", "\\", "", "\\", "\\", true, true}, + {"\\//", "\\", "", "\\", "\\", true, true}, + {"//\\", "/", "", "/", "/", true, true}, #else - {"a\\", ".", "a\\", "a\\", "a\\", false, false}, - {"a\\b", ".", "a\\b", "a\\b", "a\\b", false, false}, - {"\\", ".", "\\", "\\", "\\", false, false}, - {"\\/\\", "\\", "\\", "\\", "\\/\\",false, false}, - {"\\\\/", ".", "\\\\/","\\\\/","\\\\", true, false}, - {"\\//", ".", "\\//", "\\/", "\\", true, false}, + {"a\\", ".", "a\\", "a\\", "a\\", false, false}, + {"a\\b", ".", "a\\b", "a\\b", "a\\b", false, false}, + {"\\", ".", "\\", "\\", "\\", false, false}, + {"\\/\\", "\\", "\\", "\\", "\\/\\",false, false}, + {"\\\\/", ".", "\\\\/","\\\\/","\\\\", true, false}, + {"\\//", ".", "\\//", "\\/", "\\", true, false}, # if DOUBLE_SLASH_IS_DISTINCT_ROOT - {"//\\", "//", "\\", "\\", "//\\", false, true}, + {"//\\", "//", "\\", "\\", "//\\", false, true}, # else - {"//\\", "/", "\\", "\\", "//\\", false, true}, + {"//\\", "/", "\\", "\\", "//\\", false, true}, # endif #endif #if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE - {"c:", "c:", "", "c:", "c:", false, false}, - {"c:/", "c:/", "", "c:/", "c:/", false, true}, - {"c://", "c:/", "", "c:/", "c:/", true, true}, - {"c:/d", "c:/", "d", "d", "c:/d", false, true}, - {"c://d", "c:/", "d", "d", "c://d",false, true}, - {"c:/d/", "c:/", "d/", "d/", "c:/d", true, true}, - {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, true}, - {"c:d", "c:.", "d", "d", "c:d", false, false}, - {"c:d/", "c:.", "d/", "d/", "c:d", true, false}, - {"c:d/f", "c:d", "f", "f", "c:d/f",false, false}, - {"a:b:c", "a:.", "b:c", "./b:c","a:b:c",false, false}, - {"a/b:c", "a", "b:c", "./b:c","a/b:c",false, false}, - {"a/b:c/", "a", "b:c/", "./b:c/","a/b:c",true, false}, + {"c:", "c:", "", "c:", "c:", false, false}, + {"c:/", "c:/", "", "c:/", "c:/", false, true}, + {"c://", "c:/", "", "c:/", "c:/", true, true}, + {"c:/d", "c:/", "d", "d", "c:/d", false, true}, + {"c://d", "c:/", "d", "d", "c://d",false, true}, + {"c:/d/", "c:/", "d/", "d/", "c:/d", true, true}, + {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, true}, + {"c:d", "c:.", "d", "d", "c:d", false, false}, + {"c:d/", "c:.", "d/", "d/", "c:d", true, false}, + {"c:d/f", "c:d", "f", "f", "c:d/f",false, false}, + {"a:b:c", "a:.", "b:c", "./b:c","a:b:c",false, false}, + {"a/b:c", "a", "b:c", "./b:c","a/b:c",false, false}, + {"a/b:c/", "a", "b:c/", "./b:c/","a/b:c",true, false}, # else /* ! FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE */ - {"c:", "c:", "", "c:", "c:", false, true}, - {"c:/", "c:", "", "c:", "c:", true, true}, - {"c://", "c:", "", "c:", "c:", true, true}, - {"c:/d", "c:", "d", "d", "c:/d", false, true}, - {"c://d", "c:", "d", "d", "c://d",false, true}, - {"c:/d/", "c:", "d/", "d/", "c:/d", true, true}, - {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, true}, - {"c:d", "c:", "d", "d", "c:d", false, true}, - {"c:d/", "c:", "d/", "d/", "c:d", true, true}, - {"c:d/f", "c:d", "f", "f", "c:d/f",false, true}, - {"a:b:c", "a:", "b:c", "./b:c","a:b:c",false, true}, - {"a/b:c", "a", "b:c", "./b:c","a/b:c",false, false}, - {"a/b:c/", "a", "b:c/", "./b:c/","a/b:c",true, false}, + {"c:", "c:", "", "c:", "c:", false, true}, + {"c:/", "c:", "", "c:", "c:", true, true}, + {"c://", "c:", "", "c:", "c:", true, true}, + {"c:/d", "c:", "d", "d", "c:/d", false, true}, + {"c://d", "c:", "d", "d", "c://d",false, true}, + {"c:/d/", "c:", "d/", "d/", "c:/d", true, true}, + {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, true}, + {"c:d", "c:", "d", "d", "c:d", false, true}, + {"c:d/", "c:", "d/", "d/", "c:d", true, true}, + {"c:d/f", "c:d", "f", "f", "c:d/f",false, true}, + {"a:b:c", "a:", "b:c", "./b:c","a:b:c",false, true}, + {"a/b:c", "a", "b:c", "./b:c","a/b:c",false, false}, + {"a/b:c/", "a", "b:c/", "./b:c/","a/b:c",true, false}, # endif #else /* ! FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX */ - {"c:", ".", "c:", "c:", "c:", false, false}, - {"c:/", ".", "c:/", "c:/", "c:", true, false}, - {"c://", ".", "c://", "c:/", "c:", true, false}, - {"c:/d", "c:", "d", "d", "c:/d", false, false}, - {"c://d", "c:", "d", "d", "c://d",false, false}, - {"c:/d/", "c:", "d/", "d/", "c:/d", true, false}, - {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, false}, - {"c:d", ".", "c:d", "c:d", "c:d", false, false}, - {"c:d/", ".", "c:d/", "c:d/", "c:d", true, false}, - {"c:d/f", "c:d", "f", "f", "c:d/f",false, false}, - {"a:b:c", ".", "a:b:c","a:b:c","a:b:c",false, false}, - {"a/b:c", "a", "b:c", "b:c", "a/b:c",false, false}, - {"a/b:c/", "a", "b:c/", "b:c/", "a/b:c",true, false}, + {"c:", ".", "c:", "c:", "c:", false, false}, + {"c:/", ".", "c:/", "c:/", "c:", true, false}, + {"c://", ".", "c://", "c:/", "c:", true, false}, + {"c:/d", "c:", "d", "d", "c:/d", false, false}, + {"c://d", "c:", "d", "d", "c://d",false, false}, + {"c:/d/", "c:", "d/", "d/", "c:/d", true, false}, + {"c:/d/f", "c:/d", "f", "f", "c:/d/f",false, false}, + {"c:d", ".", "c:d", "c:d", "c:d", false, false}, + {"c:d/", ".", "c:d/", "c:d/", "c:d", true, false}, + {"c:d/f", "c:d", "f", "f", "c:d/f",false, false}, + {"a:b:c", ".", "a:b:c","a:b:c","a:b:c",false, false}, + {"a/b:c", "a", "b:c", "b:c", "a/b:c",false, false}, + {"a/b:c/", "a", "b:c/", "b:c/", "a/b:c",true, false}, #endif - {"1:", ".", "1:", "1:", "1:", false, false}, - {"1:/", ".", "1:/", "1:/", "1:", true, false}, - {"/:", "/", ":", ":", "/:", false, true}, - {"/:/", "/", ":/", ":/", "/:", true, true}, + {"1:", ".", "1:", "1:", "1:", false, false}, + {"1:/", ".", "1:/", "1:/", "1:", true, false}, + {"/:", "/", ":", ":", "/:", false, true}, + {"/:/", "/", ":/", ":/", "/:", true, true}, /* End sentinel. */ - {NULL, NULL, NULL, NULL, NULL, false, false} + {NULL, NULL, NULL, NULL, NULL, false, false} }; int @@ -145,44 +145,44 @@ main (void) bool modified = strip_trailing_slashes (stripped); bool absolute = IS_ABSOLUTE_FILE_NAME (t->name); if (! (strcmp (dir, t->dir) == 0 - && (dirlen == strlen (dir) - || (dirlen + 1 == strlen (dir) && dir[dirlen] == '.')))) - { - ok = false; - printf ("dir_name `%s': got `%s' len %d, expected `%s' len %ld\n", - t->name, dir, dirlen, - t->dir, (unsigned long) strlen (t->dir)); - } + && (dirlen == strlen (dir) + || (dirlen + 1 == strlen (dir) && dir[dirlen] == '.')))) + { + ok = false; + printf ("dir_name `%s': got `%s' len %d, expected `%s' len %ld\n", + t->name, dir, dirlen, + t->dir, (unsigned long) strlen (t->dir)); + } if (strcmp (last, t->last)) - { - ok = false; - printf ("last_component `%s': got `%s', expected `%s'\n", - t->name, last, t->last); - } + { + ok = false; + printf ("last_component `%s': got `%s', expected `%s'\n", + t->name, last, t->last); + } if (! (strcmp (base, t->base) == 0 - && (baselen == strlen (base) - || (baselen + 1 == strlen (base) - && ISSLASH (base[baselen]))))) - { - ok = false; - printf ("base_name `%s': got `%s' len %d, expected `%s' len %ld\n", - t->name, base, baselen, - t->base, (unsigned long) strlen (t->base)); - } + && (baselen == strlen (base) + || (baselen + 1 == strlen (base) + && ISSLASH (base[baselen]))))) + { + ok = false; + printf ("base_name `%s': got `%s' len %d, expected `%s' len %ld\n", + t->name, base, baselen, + t->base, (unsigned long) strlen (t->base)); + } if (strcmp (stripped, t->stripped) || modified != t->modified) - { - ok = false; - printf ("strip_trailing_slashes `%s': got %s %s, expected %s %s\n", - t->name, stripped, modified ? "changed" : "unchanged", - t->stripped, t->modified ? "changed" : "unchanged"); - } + { + ok = false; + printf ("strip_trailing_slashes `%s': got %s %s, expected %s %s\n", + t->name, stripped, modified ? "changed" : "unchanged", + t->stripped, t->modified ? "changed" : "unchanged"); + } if (t->absolute != absolute) - { - ok = false; - printf ("`%s': got %s, expected %s\n", t->name, - absolute ? "absolute" : "relative", - t->absolute ? "absolute" : "relative"); - } + { + ok = false; + printf ("`%s': got %s, expected %s\n", t->name, + absolute ? "absolute" : "relative", + t->absolute ? "absolute" : "relative"); + } free (dir); free (base); free (stripped); diff --git a/tests/test-dprintf-posix.c b/tests/test-dprintf-posix.c index c8eb3f583..384d1efaf 100644 --- a/tests/test-dprintf-posix.c +++ b/tests/test-dprintf-posix.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void diff --git a/tests/test-dup3.c b/tests/test-dup3.c index 9c88e75b1..41fc16ded 100644 --- a/tests/test-dup3.c +++ b/tests/test-dup3.c @@ -36,15 +36,15 @@ #include "binary-io.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Return true if FD is open. */ @@ -99,7 +99,7 @@ main () o_flags = 0; #if defined O_CLOEXEC if (use_cloexec) - o_flags |= O_CLOEXEC; + o_flags |= O_CLOEXEC; #endif /* Assume std descriptors were provided by invoker. */ @@ -141,9 +141,9 @@ main () ASSERT (!is_open (fd + 1)); ASSERT (is_open (fd + 2)); if (use_cloexec) - ASSERT (is_cloexec (fd + 2)); + ASSERT (is_cloexec (fd + 2)); else - ASSERT (!is_cloexec (fd + 2)); + ASSERT (!is_cloexec (fd + 2)); /* Verify that dup3 closes the previous occupant of a fd. */ ASSERT (open ("/dev/null", O_WRONLY, 0600) == fd + 1); diff --git a/tests/test-duplocale.c b/tests/test-duplocale.c index 1989170ad..354e13e8f 100644 --- a/tests/test-duplocale.c +++ b/tests/test-duplocale.c @@ -29,15 +29,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) struct locale_dependent_values @@ -51,10 +51,10 @@ static void get_locale_dependent_values (struct locale_dependent_values *result) { strfmon (result->monetary, sizeof (result->monetary), - "%n", 123.75); + "%n", 123.75); /* result->monetary is usually "$123.75" */ snprintf (result->numeric, sizeof (result->numeric), - "%g", 3.5); + "%g", 3.5); /* result->numeric is usually "3,5" */ strcpy (result->time, nl_langinfo (MON_1)); /* result->time is usually "janvier" */ diff --git a/tests/test-environ.c b/tests/test-environ.c index d9501bbda..b8edc50ea 100644 --- a/tests/test-environ.c +++ b/tests/test-environ.c @@ -36,8 +36,8 @@ main () for (; (string = *remaining_variables) != NULL; remaining_variables++) { if (strncmp (string, "PATH=", 5) == 0) - /* Found the PATH environment variable. */ - return 0; + /* Found the PATH environment variable. */ + return 0; } /* Failed to find the PATH environment variable. */ return 1; diff --git a/tests/test-exclude.c b/tests/test-exclude.c index a729bba36..114c4ddd6 100644 --- a/tests/test-exclude.c +++ b/tests/test-exclude.c @@ -81,30 +81,30 @@ main (int argc, char **argv) { char *opt = *++argv; if (opt[0] == '-') - { - int neg = 0; - int flag; - char *s = opt + 1; - - if (opt[1] == '-' && opt[2] == 0) - { - argc--; - break; - } - if (strlen (s) > 3 && memcmp (s, "no-", 3) == 0) - { - neg = 1; - s += 3; - } - flag = XARGMATCH (opt, s, exclude_keywords, exclude_flags); - if (neg) - exclude_options &= ~flag; - else - exclude_options |= flag; - } + { + int neg = 0; + int flag; + char *s = opt + 1; + + if (opt[1] == '-' && opt[2] == 0) + { + argc--; + break; + } + if (strlen (s) > 3 && memcmp (s, "no-", 3) == 0) + { + neg = 1; + s += 3; + } + flag = XARGMATCH (opt, s, exclude_keywords, exclude_flags); + if (neg) + exclude_options &= ~flag; + else + exclude_options |= flag; + } else if (add_exclude_file (add_exclude, exclude, opt, - exclude_options, '\n') != 0) - error (1, errno, "error loading %s", opt); + exclude_options, '\n') != 0) + error (1, errno, "error loading %s", opt); } for (; argc; --argc) diff --git a/tests/test-fbufmode.c b/tests/test-fbufmode.c index 1bf820e67..3f83864a1 100644 --- a/tests/test-fbufmode.c +++ b/tests/test-fbufmode.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define TESTFILE "t-fbufmode.tmp" @@ -64,7 +64,7 @@ main () { /* mingw's setvbuf implements _IOLBF the same way as _IOFBF. */ ASSERT (fbufmode (fp) == _IOLBF - || fbufmode (fp) == _IOFBF); + || fbufmode (fp) == _IOFBF); } /* This setvbuf call can fail, e.g. on HP-UX 11. */ diff --git a/tests/test-fchdir.c b/tests/test-fchdir.c index 0419f43fd..19065591d 100644 --- a/tests/test-fchdir.c +++ b/tests/test-fchdir.c @@ -29,15 +29,15 @@ #include "cloexec.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -69,27 +69,27 @@ main (void) ASSERT (chdir (".." + 1 - i) == 0); ASSERT (fchdir (fd) == 0); { - size_t len = strlen (cwd) + 1; - char *new_dir = malloc (len); - ASSERT (new_dir); - ASSERT (getcwd (new_dir, len) == new_dir); - ASSERT (strcmp (cwd, new_dir) == 0); - free (new_dir); + size_t len = strlen (cwd) + 1; + char *new_dir = malloc (len); + ASSERT (new_dir); + ASSERT (getcwd (new_dir, len) == new_dir); + ASSERT (strcmp (cwd, new_dir) == 0); + free (new_dir); } /* For second iteration, use a cloned fd, to ensure that dup - remembers whether an fd was associated with a directory. */ + remembers whether an fd was associated with a directory. */ if (!i) - { - int new_fd = dup (fd); - ASSERT (0 <= new_fd); - ASSERT (close (fd) == 0); - ASSERT (dup2 (new_fd, fd) == fd); - ASSERT (close (new_fd) == 0); - ASSERT (dup_cloexec (fd) == new_fd); - ASSERT (dup2 (new_fd, fd) == fd); - ASSERT (close (new_fd) == 0); - } + { + int new_fd = dup (fd); + ASSERT (0 <= new_fd); + ASSERT (close (fd) == 0); + ASSERT (dup2 (new_fd, fd) == fd); + ASSERT (close (new_fd) == 0); + ASSERT (dup_cloexec (fd) == new_fd); + ASSERT (dup2 (new_fd, fd) == fd); + ASSERT (close (new_fd) == 0); + } } free (cwd); diff --git a/tests/test-fcntl-h.c b/tests/test-fcntl-h.c index a1f086676..c6546be02 100644 --- a/tests/test-fcntl-h.c +++ b/tests/test-fcntl-h.c @@ -22,8 +22,8 @@ /* Check that the various O_* macros are defined. */ int o = O_DIRECT | O_DIRECTORY | O_DSYNC | O_NDELAY | O_NOATIME | O_NONBLOCK - | O_NOCTTY | O_NOFOLLOW | O_NOLINKS | O_RSYNC | O_SYNC | O_TTY_INIT - | O_BINARY | O_TEXT; + | O_NOCTTY | O_NOFOLLOW | O_NOLINKS | O_RSYNC | O_SYNC | O_TTY_INIT + | O_BINARY | O_TEXT; /* Check that the various SEEK_* macros are defined. */ int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET }; diff --git a/tests/test-fdopendir.c b/tests/test-fdopendir.c index fad60cfa7..7e0b3ee9b 100644 --- a/tests/test-fdopendir.c +++ b/tests/test-fdopendir.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-fflush.c b/tests/test-fflush.c index 3afdf7bd6..8e33c9f0f 100644 --- a/tests/test-fflush.c +++ b/tests/test-fflush.c @@ -70,7 +70,7 @@ main (void) if (lseek (fd, 0, SEEK_CUR) != 5) { fprintf (stderr, "File offset is wrong after fseek: %ld.\n", - (long) lseek (fd, 0, SEEK_CUR)); + (long) lseek (fd, 0, SEEK_CUR)); fclose (f); unlink ("test-fflush.txt"); return 1; @@ -78,7 +78,7 @@ main (void) if (ftell (f) != 5) { fprintf (stderr, "ftell result is wrong after fseek: %ld.\n", - (long) ftell (f)); + (long) ftell (f)); fclose (f); unlink ("test-fflush.txt"); return 1; @@ -111,7 +111,7 @@ main (void) if (lseek (fd, 0, SEEK_CUR) != 6) { fprintf (stderr, "File offset is wrong after fseeko: %ld.\n", - (long) lseek (fd, 0, SEEK_CUR)); + (long) lseek (fd, 0, SEEK_CUR)); fclose (f); unlink ("test-fflush.txt"); return 1; @@ -119,7 +119,7 @@ main (void) if (ftell (f) != 6) { fprintf (stderr, "ftell result is wrong after fseeko: %ld.\n", - (long) ftell (f)); + (long) ftell (f)); fclose (f); unlink ("test-fflush.txt"); return 1; diff --git a/tests/test-fflush2.c b/tests/test-fflush2.c index a395c6dba..da0a760c2 100644 --- a/tests/test-fflush2.c +++ b/tests/test-fflush2.c @@ -23,15 +23,15 @@ #include "binary-io.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -47,74 +47,74 @@ main (int argc, char **argv) switch (argv[1][0]) { case '1': - /* Check fflush after a backup ungetc() call. This is case 1a in - terms of - , - according to the Austin Group's resolution on 2009-01-08. */ + /* Check fflush after a backup ungetc() call. This is case 1a in + terms of + , + according to the Austin Group's resolution on 2009-01-08. */ - c = fgetc (stdin); - ASSERT (c == '#'); + c = fgetc (stdin); + ASSERT (c == '#'); - c = fgetc (stdin); - ASSERT (c == '!'); + c = fgetc (stdin); + ASSERT (c == '!'); - /* Here the file-position indicator must be 2. */ + /* Here the file-position indicator must be 2. */ - c = ungetc ('!', stdin); - ASSERT (c == '!'); + c = ungetc ('!', stdin); + ASSERT (c == '!'); - fflush (stdin); + fflush (stdin); - /* Here the file-position indicator must be 1. */ + /* Here the file-position indicator must be 1. */ - c = fgetc (stdin); - ASSERT (c == '!'); + c = fgetc (stdin); + ASSERT (c == '!'); - c = fgetc (stdin); - ASSERT (c == '/'); + c = fgetc (stdin); + ASSERT (c == '/'); - return 0; + return 0; case '2': - /* Check fflush after a non-backup ungetc() call. This is case 2a in - terms of - , - according to the Austin Group's resolution on 2009-01-08. */ - /* Check that fflush after a non-backup ungetc() call discards the - ungetc buffer. This is mandated by POSIX - : - "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." - - "[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() or - ungetwc() that have not subsequently been read from the stream - shall be discarded." */ + /* Check fflush after a non-backup ungetc() call. This is case 2a in + terms of + , + according to the Austin Group's resolution on 2009-01-08. */ + /* Check that fflush after a non-backup ungetc() call discards the + ungetc buffer. This is mandated by POSIX + : + "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." + + "[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() or + ungetwc() that have not subsequently been read from the stream + shall be discarded." */ - c = fgetc (stdin); - ASSERT (c == '#'); + c = fgetc (stdin); + ASSERT (c == '#'); - c = fgetc (stdin); - ASSERT (c == '!'); + c = fgetc (stdin); + ASSERT (c == '!'); - /* Here the file-position indicator must be 2. */ + /* Here the file-position indicator must be 2. */ - c = ungetc ('@', stdin); - ASSERT (c == '@'); + c = ungetc ('@', stdin); + ASSERT (c == '@'); - fflush (stdin); + fflush (stdin); - /* Here the file-position indicator must be 1. */ + /* Here the file-position indicator must be 1. */ - c = fgetc (stdin); - ASSERT (c == '!'); + c = fgetc (stdin); + ASSERT (c == '!'); - c = fgetc (stdin); - ASSERT (c == '/'); + c = fgetc (stdin); + ASSERT (c == '/'); - return 0; + return 0; } return 1; diff --git a/tests/test-file-has-acl.c b/tests/test-file-has-acl.c index 5685f4115..3e069ee41 100644 --- a/tests/test-file-has-acl.c +++ b/tests/test-file-has-acl.c @@ -28,15 +28,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -68,8 +68,8 @@ main (int argc, char *argv[]) int ret = file_has_acl (file, &statbuf); if (ret < 0) { - fprintf (stderr, "could not access the ACL of file \"%s\"\n", file); - exit (EXIT_FAILURE); + fprintf (stderr, "could not access the ACL of file \"%s\"\n", file); + exit (EXIT_FAILURE); } printf ("%s\n", ret ? "yes" : "no"); } diff --git a/tests/test-filenamecat.c b/tests/test-filenamecat.c index 44a7bd587..d10bf5fdb 100644 --- a/tests/test-filenamecat.c +++ b/tests/test-filenamecat.c @@ -57,10 +57,10 @@ main (int argc _UNUSED_PARAMETER_, char *argv[]) char const *const *t = tests[i]; char *res = file_name_concat (t[0], t[1], &base_in_result); if (strcmp (res, t[2]) != 0) - { - fprintf (stderr, "test #%u: got %s, expected %s\n", i, res, t[2]); - fail = true; - } + { + fprintf (stderr, "test #%u: got %s, expected %s\n", i, res, t[2]); + fail = true; + } } exit (fail ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/tests/test-filevercmp.c b/tests/test-filevercmp.c index 14426a6a7..4c29d0c8d 100644 --- a/tests/test-filevercmp.c +++ b/tests/test-filevercmp.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* set of well sorted examples */ @@ -117,15 +117,15 @@ main (void) { const char *const *j; for (j = examples; *j; j++) - { - int result = filevercmp (*i, *j); - if (result < 0) - ASSERT (i < j); - else if (0 < result) - ASSERT (j < i); - else - ASSERT (i == j); - } + { + int result = filevercmp (*i, *j); + if (result < 0) + ASSERT (i < j); + else if (0 < result) + ASSERT (j < i); + else + ASSERT (i == j); + } } return 0; diff --git a/tests/test-flock.c b/tests/test-flock.c index f71532ee2..e0147e8de 100644 --- a/tests/test-flock.c +++ b/tests/test-flock.c @@ -25,16 +25,16 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed, errno = %d\n", \ - __FILE__, __LINE__, errno); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed, errno = %d\n", \ + __FILE__, __LINE__, errno); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -51,7 +51,7 @@ test_shared (const char *file, int fd) ASSERT (fd2 >= 0); r = flock (fd2, LOCK_SH | LOCK_NB); - ASSERT (r == 0); /* Was able to acquire a second shared lock. */ + ASSERT (r == 0); /* Was able to acquire a second shared lock. */ ASSERT (flock (fd, LOCK_UN) == 0); ASSERT (close (fd2) == 0); @@ -69,7 +69,7 @@ test_exclusive (const char *file, int fd) ASSERT (fd2 >= 0); r = flock (fd2, LOCK_SH | LOCK_NB); - ASSERT (r == -1); /* Was unable to acquire a second exclusive lock. */ + ASSERT (r == -1); /* Was unable to acquire a second exclusive lock. */ ASSERT (flock (fd, LOCK_UN) == 0); ASSERT (close (fd2) == 0); diff --git a/tests/test-floorf1.c b/tests/test-floorf1.c index e15b293b8..373724a46 100644 --- a/tests/test-floorf1.c +++ b/tests/test-floorf1.c @@ -27,15 +27,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f. diff --git a/tests/test-floorf2.c b/tests/test-floorf2.c index e7fcd98a1..d668487e5 100644 --- a/tests/test-floorf2.c +++ b/tests/test-floorf2.c @@ -29,15 +29,15 @@ #include "isnanf-nolibm.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) @@ -74,27 +74,27 @@ floorf_reference (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } return z; } @@ -131,9 +131,9 @@ check (float x) return 0; else { - fprintf (stderr, "floorf %g(%a) = %g(%a) or %g(%a)?\n", - x, x, reference, reference, result, result); - return 1; + fprintf (stderr, "floorf %g(%a) = %g(%a) or %g(%a)?\n", + x, x, reference, reference, result, result); + return 1; } } } @@ -150,14 +150,14 @@ main () for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++) for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++) { - /* Combine highbits and lowbits into a floating-point number, - sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ - union { float f; uint32_t i; } janus; - janus.i = ((uint32_t) highbits << (32 - NUM_HIGHBITS)) - | ((uint32_t) ((int32_t) ((uint32_t) lowbits << (32 - NUM_LOWBITS)) - >> (32 - NUM_LOWBITS - NUM_HIGHBITS)) - >> NUM_HIGHBITS); - error |= check (janus.f); + /* Combine highbits and lowbits into a floating-point number, + sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ + union { float f; uint32_t i; } janus; + janus.i = ((uint32_t) highbits << (32 - NUM_HIGHBITS)) + | ((uint32_t) ((int32_t) ((uint32_t) lowbits << (32 - NUM_LOWBITS)) + >> (32 - NUM_LOWBITS - NUM_HIGHBITS)) + >> NUM_HIGHBITS); + error |= check (janus.f); } return (error ? 1 : 0); } diff --git a/tests/test-floorl.c b/tests/test-floorl.c index 87fea7f86..7afea04f2 100644 --- a/tests/test-floorl.c +++ b/tests/test-floorl.c @@ -29,15 +29,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On HP-UX 10.20, negating 0.0L does not yield -0.0L. diff --git a/tests/test-fnmatch.c b/tests/test-fnmatch.c index 9d0aaaeaa..3e21d9d44 100644 --- a/tests/test-fnmatch.c +++ b/tests/test-fnmatch.c @@ -23,17 +23,17 @@ #include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", \ - __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", \ + __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-fopen.h b/tests/test-fopen.h index 1920b27ed..6ba923b3b 100644 --- a/tests/test-fopen.h +++ b/tests/test-fopen.h @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Test fopen. Assumes BASE is defined. */ diff --git a/tests/test-fpending.c b/tests/test-fpending.c index 6c053dc84..44b6f66dd 100644 --- a/tests/test-fpending.c +++ b/tests/test-fpending.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-fprintf-posix.c b/tests/test-fprintf-posix.c index be65079e8..4133e40bd 100644 --- a/tests/test-fprintf-posix.c +++ b/tests/test-fprintf-posix.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-fprintf-posix.h" diff --git a/tests/test-fprintf-posix2.c b/tests/test-fprintf-posix2.c index 6d6dc0820..55293f7ae 100644 --- a/tests/test-fprintf-posix2.c +++ b/tests/test-fprintf-posix2.c @@ -73,11 +73,11 @@ main (int argc, char *argv[]) { case 0: { - void *memory = malloc (5000000); - if (memory == NULL) - return 1; - memset (memory, 17, 5000000); - return 78; + void *memory = malloc (5000000); + if (memory == NULL) + return 1; + memset (memory, 17, 5000000); + return 78; } case 1: ret = fprintf (stdout, "%.5000000f", 1.0); diff --git a/tests/test-fpurge.c b/tests/test-fpurge.c index 2197b89df..9bf237886 100644 --- a/tests/test-fpurge.c +++ b/tests/test-fpurge.c @@ -30,15 +30,15 @@ #endif #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define TESTFILE "t-fpurge.tmp" @@ -55,54 +55,54 @@ main (void) /* Create a file with some contents. */ fp = fopen (TESTFILE, "w"); if (fp == NULL) - goto skip; + goto skip; if (fwrite ("foobarsh", 1, 8, fp) < 8) - goto skip; + goto skip; if (fclose (fp)) - goto skip; + goto skip; /* The file's contents is now "foobarsh". */ /* Open it in read-write mode. */ fp = fopen (TESTFILE, "r+"); if (fp == NULL) - goto skip; + goto skip; if (fseek (fp, 3, SEEK_CUR)) - goto skip; + goto skip; if (fwrite ("g", 1, 1, fp) < 1) - goto skip; + goto skip; if (fflush (fp)) - goto skip; + goto skip; if (fwrite ("bz", 1, 2, fp) < 2) - goto skip; + goto skip; /* Discard pending write. */ ASSERT (fpurge (fp) == 0); /* Verify that when discarding pending output, the file position is set - back to where it was before the write calls. */ + back to where it was before the write calls. */ if (check_filepos) - ASSERT (ftell (fp) == 4); + ASSERT (ftell (fp) == 4); ASSERT (fclose (fp) == 0); /* Open it in read-only mode. */ fp = fopen (TESTFILE, "r"); if (fp == NULL) - goto skip; + goto skip; /* Verify that the pending writes before the fpurge were really - discarded. */ + discarded. */ { - char buf[8]; - if (fread (buf, 1, 7, fp) < 7) - goto skip; - ASSERT (memcmp (buf, "foogars", 7) == 0); + char buf[8]; + if (fread (buf, 1, 7, fp) < 7) + goto skip; + ASSERT (memcmp (buf, "foogars", 7) == 0); } /* Discard the buffered 'h'. */ if (check_filepos) - ASSERT (ftell (fp) == 7); + ASSERT (ftell (fp) == 7); ASSERT (fpurge (fp) == 0); /* Verify that when discarding pending input, the file position is - advanced to match the end of the previously read input. */ + advanced to match the end of the previously read input. */ if (check_filepos) - ASSERT (ftell (fp) == 8); + ASSERT (ftell (fp) == 8); ASSERT (getc (fp) == EOF); ASSERT (fclose (fp) == 0); @@ -111,25 +111,25 @@ main (void) /* Ensure that purging a read does not corrupt subsequent writes. */ fp = fopen (TESTFILE, "r+"); if (fp == NULL) - goto skip; + goto skip; if (fseek (fp, -1, SEEK_END)) - goto skip; + goto skip; ASSERT (getc (fp) == 'h'); ASSERT (getc (fp) == EOF); if (check_filepos) - ASSERT (ftell (fp) == 8); + ASSERT (ftell (fp) == 8); ASSERT (fpurge (fp) == 0); if (check_filepos) - ASSERT (ftell (fp) == 8); + ASSERT (ftell (fp) == 8); ASSERT (putc ('!', fp) == '!'); ASSERT (fclose (fp) == 0); fp = fopen (TESTFILE, "r"); if (fp == NULL) - goto skip; + goto skip; { - char buf[10]; - ASSERT (fread (buf, 1, 10, fp) == 9); - ASSERT (memcmp (buf, "foogarsh!", 9) == 0); + char buf[10]; + ASSERT (fread (buf, 1, 10, fp) == 9); + ASSERT (memcmp (buf, "foogarsh!", 9) == 0); } ASSERT (fclose (fp) == 0); diff --git a/tests/test-freadable.c b/tests/test-freadable.c index 52a328730..becad342c 100644 --- a/tests/test-freadable.c +++ b/tests/test-freadable.c @@ -30,15 +30,15 @@ #endif #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define TESTFILE "t-freadable.tmp" diff --git a/tests/test-freadahead.c b/tests/test-freadahead.c index c369cbafd..c216231aa 100644 --- a/tests/test-freadahead.c +++ b/tests/test-freadahead.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -51,33 +51,33 @@ main (int argc, char **argv) else { if (lseek (0, 0, SEEK_CUR) == nbytes) - /* An unbuffered stdio, such as BeOS or on uClibc compiled without - __STDIO_BUFFERS. */ - ASSERT (freadahead (stdin) == 0); + /* An unbuffered stdio, such as BeOS or on uClibc compiled without + __STDIO_BUFFERS. */ + ASSERT (freadahead (stdin) == 0); else - { - /* Normal buffered stdio. */ - size_t buffered; - int c, c2; + { + /* Normal buffered stdio. */ + size_t buffered; + int c, c2; - ASSERT (freadahead (stdin) != 0); - buffered = freadahead (stdin); + ASSERT (freadahead (stdin) != 0); + buffered = freadahead (stdin); - c = fgetc (stdin); - ASSERT (freadahead (stdin) == buffered - 1); - ungetc (c, stdin); - ASSERT (freadahead (stdin) == buffered); - c2 = fgetc (stdin); - ASSERT (c2 == c); - ASSERT (freadahead (stdin) == buffered - 1); + c = fgetc (stdin); + ASSERT (freadahead (stdin) == buffered - 1); + ungetc (c, stdin); + ASSERT (freadahead (stdin) == buffered); + c2 = fgetc (stdin); + ASSERT (c2 == c); + ASSERT (freadahead (stdin) == buffered - 1); - c = '@'; - ungetc (c, stdin); - ASSERT (freadahead (stdin) == buffered); - c2 = fgetc (stdin); - ASSERT (c2 == c); - ASSERT (freadahead (stdin) == buffered - 1); - } + c = '@'; + ungetc (c, stdin); + ASSERT (freadahead (stdin) == buffered); + c2 = fgetc (stdin); + ASSERT (c2 == c); + ASSERT (freadahead (stdin) == buffered - 1); + } } return 0; diff --git a/tests/test-freadptr.c b/tests/test-freadptr.c index a46d65d3b..65334b8bc 100644 --- a/tests/test-freadptr.c +++ b/tests/test-freadptr.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -47,7 +47,7 @@ main (int argc, char **argv) if (lseek (0, 0, SEEK_CUR) == nbytes) { /* An unbuffered stdio, such as BeOS or on uClibc compiled without - __STDIO_BUFFERS. Or stdin is a pipe. */ + __STDIO_BUFFERS. Or stdin is a pipe. */ size_t size; ASSERT (freadptr (stdin, &size) == NULL); } @@ -55,7 +55,7 @@ main (int argc, char **argv) { /* Normal buffered stdio. */ const char stdin_contents[] = - "#!/bin/sh\n\n./test-freadptr${EXEEXT} 5 < \"$srcdir/test-freadptr.sh\" || exit 1\ncat \"$srcdir/test-freadptr.sh\" | ./test-freadptr${EXEEXT} 5 || exit 1\nexit 0\n"; + "#!/bin/sh\n\n./test-freadptr${EXEEXT} 5 < \"$srcdir/test-freadptr.sh\" || exit 1\ncat \"$srcdir/test-freadptr.sh\" | ./test-freadptr${EXEEXT} 5 || exit 1\nexit 0\n"; const char *expected = stdin_contents + nbytes; size_t available1; size_t available2; @@ -63,41 +63,41 @@ main (int argc, char **argv) /* Test normal behaviour. */ { - const char *ptr = freadptr (stdin, &available1); + const char *ptr = freadptr (stdin, &available1); - ASSERT (ptr != NULL); - ASSERT (available1 != 0); - ASSERT (available1 <= strlen (expected)); - ASSERT (memcmp (ptr, expected, available1) == 0); + ASSERT (ptr != NULL); + ASSERT (available1 != 0); + ASSERT (available1 <= strlen (expected)); + ASSERT (memcmp (ptr, expected, available1) == 0); } /* Test behaviour after normal ungetc. */ ungetc (fgetc (stdin), stdin); { - const char *ptr = freadptr (stdin, &available2); + const char *ptr = freadptr (stdin, &available2); - if (ptr != NULL) - { - ASSERT (available2 == available1); - ASSERT (memcmp (ptr, expected, available2) == 0); - } + if (ptr != NULL) + { + ASSERT (available2 == available1); + ASSERT (memcmp (ptr, expected, available2) == 0); + } } /* Test behaviour after arbitrary ungetc. */ fgetc (stdin); ungetc ('@', stdin); { - const char *ptr = freadptr (stdin, &available3); - - if (ptr != NULL) - { - ASSERT (available3 == 1 || available3 == available1); - ASSERT (ptr[0] == '@'); - if (available3 > 1) - { - ASSERT (memcmp (ptr + 1, expected + 1, available3 - 1) == 0); - } - } + const char *ptr = freadptr (stdin, &available3); + + if (ptr != NULL) + { + ASSERT (available3 == 1 || available3 == available1); + ASSERT (ptr[0] == '@'); + if (available3 > 1) + { + ASSERT (memcmp (ptr + 1, expected + 1, available3 - 1) == 0); + } + } } } diff --git a/tests/test-freadptr2.c b/tests/test-freadptr2.c index c2922783b..e6f534834 100644 --- a/tests/test-freadptr2.c +++ b/tests/test-freadptr2.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -60,12 +60,12 @@ main (int argc, char **argv) else { if (lseek (0, 0, SEEK_CUR) == nbytes) - /* An unbuffered stdio, such as BeOS or on uClibc compiled without - __STDIO_BUFFERS. */ - ASSERT (freadptrbufsize (stdin) == 0); + /* An unbuffered stdio, such as BeOS or on uClibc compiled without + __STDIO_BUFFERS. */ + ASSERT (freadptrbufsize (stdin) == 0); else - /* Normal buffered stdio. */ - ASSERT (freadptrbufsize (stdin) != 0); + /* Normal buffered stdio. */ + ASSERT (freadptrbufsize (stdin) != 0); } return 0; diff --git a/tests/test-freadseek.c b/tests/test-freadseek.c index 707190905..2bd9ab6ff 100644 --- a/tests/test-freadseek.c +++ b/tests/test-freadseek.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-freopen.c b/tests/test-freopen.c index 55a665e34..23f2af512 100644 --- a/tests/test-freopen.c +++ b/tests/test-freopen.c @@ -22,15 +22,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-frexp.c b/tests/test-frexp.c index 0cd08230b..47ddab297 100644 --- a/tests/test-frexp.c +++ b/tests/test-frexp.c @@ -33,15 +33,15 @@ #define exp exponent #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0. diff --git a/tests/test-frexpl.c b/tests/test-frexpl.c index d4babb88c..e4367f6ea 100644 --- a/tests/test-frexpl.c +++ b/tests/test-frexpl.c @@ -34,15 +34,15 @@ #define exp exponent #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On MIPS IRIX machines, LDBL_MIN_EXP is -1021, but the smallest reliable diff --git a/tests/test-fseek.c b/tests/test-fseek.c index 6ba378829..04fc96675 100644 --- a/tests/test-fseek.c +++ b/tests/test-fseek.c @@ -22,15 +22,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #ifndef FUNC_UNGETC_BROKEN diff --git a/tests/test-fstrcmp.c b/tests/test-fstrcmp.c index 69845508d..a2d250527 100644 --- a/tests/test-fstrcmp.c +++ b/tests/test-fstrcmp.c @@ -27,15 +27,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static bool @@ -67,9 +67,9 @@ check_fstrcmp (const char *string1, const char *string2, double expected) double bound = (1 + expected) * 0.5; if (expected < bound) { - volatile double result = fstrcmp_bounded (string1, string2, bound); - if (!(result < bound)) - return false; + volatile double result = fstrcmp_bounded (string1, string2, bound); + if (!(result < bound)) + return false; } } diff --git a/tests/test-ftell.c b/tests/test-ftell.c index 786a448c1..06628657a 100644 --- a/tests/test-ftell.c +++ b/tests/test-ftell.c @@ -30,15 +30,15 @@ #endif #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #ifndef FUNC_UNGETC_BROKEN diff --git a/tests/test-ftello.c b/tests/test-ftello.c index c5b1246ff..f3183c8ec 100644 --- a/tests/test-ftello.c +++ b/tests/test-ftello.c @@ -30,15 +30,15 @@ #endif #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #ifndef FUNC_UNGETC_BROKEN diff --git a/tests/test-func.c b/tests/test-func.c index 106a20edc..7679ef047 100644 --- a/tests/test-func.c +++ b/tests/test-func.c @@ -22,16 +22,16 @@ #include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -46,7 +46,7 @@ main () #endif ASSERT (strcmp (__func__, "main") == 0 - || strcmp (__func__, "") == 0); + || strcmp (__func__, "") == 0); return 0; } diff --git a/tests/test-fwritable.c b/tests/test-fwritable.c index a0659edc0..34f242708 100644 --- a/tests/test-fwritable.c +++ b/tests/test-fwritable.c @@ -30,15 +30,15 @@ #endif #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define TESTFILE "t-fwritable.tmp" diff --git a/tests/test-fwriting.c b/tests/test-fwriting.c index 9916b8229..ee23eecf8 100644 --- a/tests/test-fwriting.c +++ b/tests/test-fwriting.c @@ -30,15 +30,15 @@ #endif #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define TESTFILE "t-fwriting.tmp" diff --git a/tests/test-gc-arcfour.c b/tests/test-gc-arcfour.c index 7ddeb5849..31fa2377b 100644 --- a/tests/test-gc-arcfour.c +++ b/tests/test-gc-arcfour.c @@ -60,10 +60,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", ciphertext_1[i] & 0xFF); + printf ("%02x ", ciphertext_1[i] & 0xFF); printf ("\n"); return 1; } @@ -83,10 +83,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", plaintext_1[i] & 0xFF); + printf ("%02x ", plaintext_1[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-gc-arctwo.c b/tests/test-gc-arctwo.c index 5680a3cf6..8533612af 100644 --- a/tests/test-gc-arctwo.c +++ b/tests/test-gc-arctwo.c @@ -59,10 +59,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", ciphertext[i] & 0xFF); + printf ("%02x ", ciphertext[i] & 0xFF); printf ("\n"); return 1; } @@ -82,10 +82,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", plaintext[i] & 0xFF); + printf ("%02x ", plaintext[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) - printf ("%02x ", scratch[i] & 0xFF); + printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-gc-des.c b/tests/test-gc-des.c index 0945512dc..5d7e13b57 100644 --- a/tests/test-gc-des.c +++ b/tests/test-gc-des.c @@ -49,35 +49,35 @@ main (int argc, char *argv[]) for (i = 0; i < 64; ++i) { - rc = gc_cipher_open (GC_DES, GC_ECB, &ctx); - if (rc != GC_OK) - return 1; + rc = gc_cipher_open (GC_DES, GC_ECB, &ctx); + if (rc != GC_OK) + return 1; - rc = gc_cipher_setkey (ctx, 8, key); - if (rc != GC_OK) - return 1; + rc = gc_cipher_setkey (ctx, 8, key); + if (rc != GC_OK) + return 1; - memcpy (temp1, input, 8); - rc = gc_cipher_encrypt_inline (ctx, 8, temp1); - if (rc != GC_OK) - return 1; + memcpy (temp1, input, 8); + rc = gc_cipher_encrypt_inline (ctx, 8, temp1); + if (rc != GC_OK) + return 1; - memcpy (temp2, temp1, 8); - rc = gc_cipher_encrypt_inline (ctx, 8, temp2); - if (rc != GC_OK) - return 1; + memcpy (temp2, temp1, 8); + rc = gc_cipher_encrypt_inline (ctx, 8, temp2); + if (rc != GC_OK) + return 1; - rc = gc_cipher_setkey (ctx, 8, temp2); - if (rc != GC_OK) - return 1; + rc = gc_cipher_setkey (ctx, 8, temp2); + if (rc != GC_OK) + return 1; - memcpy (temp3, temp1, 8); - rc = gc_cipher_decrypt_inline (ctx, 8, temp3); - if (rc != GC_OK) - return 1; + memcpy (temp3, temp1, 8); + rc = gc_cipher_decrypt_inline (ctx, 8, temp3); + if (rc != GC_OK) + return 1; - memcpy (key, temp3, 8); - memcpy (input, temp1, 8); + memcpy (key, temp3, 8); + memcpy (input, temp1, 8); } if (memcmp (temp3, result, 8)) return 1; diff --git a/tests/test-gc-hmac-md5.c b/tests/test-gc-hmac-md5.c index b594d9172..e2fac4445 100644 --- a/tests/test-gc-hmac-md5.c +++ b/tests/test-gc-hmac-md5.c @@ -57,21 +57,21 @@ main (int argc, char *argv[]) if (gc_hmac_md5 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, 16) != 0) { - size_t i; - printf ("hash 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } diff --git a/tests/test-gc-hmac-sha1.c b/tests/test-gc-hmac-sha1.c index d39f3c541..09ebf2cff 100644 --- a/tests/test-gc-hmac-sha1.c +++ b/tests/test-gc-hmac-sha1.c @@ -48,21 +48,21 @@ main (int argc, char *argv[]) if (gc_hmac_sha1 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, GC_SHA1_DIGEST_SIZE) != 0) { - size_t i; - printf ("hash 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } diff --git a/tests/test-gc-md2.c b/tests/test-gc-md2.c index 17c3410a7..61e272051 100644 --- a/tests/test-gc-md2.c +++ b/tests/test-gc-md2.c @@ -48,52 +48,52 @@ main (int argc, char *argv[]) if (gc_md2 (in, inlen, out) != 0) { - printf ("gc_md2 call failed\n"); - return 1; + printf ("gc_md2 call failed\n"); + return 1; } if (memcmp (out, expect, 16) != 0) { - size_t i; - printf ("md2 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("md2 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } if (gc_hash_buffer (GC_MD2, in, inlen, out) != 0) { - printf ("gc_hash_buffer(MD2) call failed\n"); - return 1; + printf ("gc_hash_buffer(MD2) call failed\n"); + return 1; } if (memcmp (out, expect, 16) != 0) { - size_t i; - printf ("md2 2 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("md2 2 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } if (gc_hash_digest_length (GC_MD2) != 16) { - printf ("gc_hash_digest_length (GC_MD2) failed\n"); - return 1; + printf ("gc_hash_digest_length (GC_MD2) failed\n"); + return 1; } if ((rc = gc_hash_open (GC_MD2, 0, &h)) != GC_OK) { - printf ("gc_hash_open(GC_MD2) failed (%d)\n", rc); - return 1; + printf ("gc_hash_open(GC_MD2) failed (%d)\n", rc); + return 1; } gc_hash_write (h, inlen, in); @@ -102,21 +102,21 @@ main (int argc, char *argv[]) if (!p) { - printf ("gc_hash_read failed\n"); - return 1; + printf ("gc_hash_read failed\n"); + return 1; } if (memcmp (p, expect, 16) != 0) - { - size_t i; - printf ("md2 3 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", p[i] & 0xFF); - printf ("\n"); - return 1; + { + size_t i; + printf ("md2 3 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", p[i] & 0xFF); + printf ("\n"); + return 1; } gc_hash_close (h); diff --git a/tests/test-gc-md4.c b/tests/test-gc-md4.c index 206d3d218..db79e3907 100644 --- a/tests/test-gc-md4.c +++ b/tests/test-gc-md4.c @@ -50,52 +50,52 @@ main (int argc, char *argv[]) if (gc_md4 (in, inlen, out) != 0) { - printf ("gc_md4 call failed\n"); - return 1; + printf ("gc_md4 call failed\n"); + return 1; } if (memcmp (out, expect, 16) != 0) { - size_t i; - printf ("md4 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("md4 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } if (gc_hash_buffer (GC_MD4, in, inlen, out) != 0) { - printf ("gc_hash_buffer(MD4) call failed\n"); - return 1; + printf ("gc_hash_buffer(MD4) call failed\n"); + return 1; } if (memcmp (out, expect, 16) != 0) { - size_t i; - printf ("md4 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("md4 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } if (gc_hash_digest_length (GC_MD4) != 16) { - printf ("gc_hash_digest_length (GC_MD4) failed\n"); - return 1; + printf ("gc_hash_digest_length (GC_MD4) failed\n"); + return 1; } if ((rc = gc_hash_open (GC_MD4, 0, &h)) != GC_OK) { - printf ("gc_hash_open(GC_MD4) failed (%d)\n", rc); - return 1; + printf ("gc_hash_open(GC_MD4) failed (%d)\n", rc); + return 1; } gc_hash_write (h, inlen, in); @@ -104,21 +104,21 @@ main (int argc, char *argv[]) if (!p) { - printf ("gc_hash_read failed\n"); - return 1; + printf ("gc_hash_read failed\n"); + return 1; } if (memcmp (p, expect, 16) != 0) { - size_t i; - printf ("md4 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", p[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("md4 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", p[i] & 0xFF); + printf ("\n"); + return 1; } gc_hash_close (h); diff --git a/tests/test-gc-md5.c b/tests/test-gc-md5.c index b5985e6b5..cdfc7bceb 100644 --- a/tests/test-gc-md5.c +++ b/tests/test-gc-md5.c @@ -50,52 +50,52 @@ main (int argc, char *argv[]) if (gc_md5 (in, inlen, out) != 0) { - printf ("gc_md5 call failed\n"); - return 1; + printf ("gc_md5 call failed\n"); + return 1; } if (memcmp (out, expect, 16) != 0) { - size_t i; - printf ("md5 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("md5 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } if (gc_hash_buffer (GC_MD5, in, inlen, out) != 0) { - printf ("gc_hash_buffer(MD5) call failed\n"); - return 1; + printf ("gc_hash_buffer(MD5) call failed\n"); + return 1; } if (memcmp (out, expect, 16) != 0) { - size_t i; - printf ("md5 2 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("md5 2 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } if (gc_hash_digest_length (GC_MD5) != 16) { - printf ("gc_hash_digest_length (GC_MD5) failed\n"); - return 1; + printf ("gc_hash_digest_length (GC_MD5) failed\n"); + return 1; } if ((rc = gc_hash_open (GC_MD5, 0, &h)) != GC_OK) { - printf ("gc_hash_open(GC_MD5) failed (%d)\n", rc); - return 1; + printf ("gc_hash_open(GC_MD5) failed (%d)\n", rc); + return 1; } gc_hash_write (h, inlen, in); @@ -104,21 +104,21 @@ main (int argc, char *argv[]) if (!p) { - printf ("gc_hash_read failed\n"); - return 1; + printf ("gc_hash_read failed\n"); + return 1; } if (memcmp (p, expect, 16) != 0) - { - size_t i; - printf ("md5 3 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", p[i] & 0xFF); - printf ("\n"); - return 1; + { + size_t i; + printf ("md5 3 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", p[i] & 0xFF); + printf ("\n"); + return 1; } gc_hash_close (h); diff --git a/tests/test-gc-pbkdf2-sha1.c b/tests/test-gc-pbkdf2-sha1.c index 933af951e..4e8459676 100644 --- a/tests/test-gc-pbkdf2-sha1.c +++ b/tests/test-gc-pbkdf2-sha1.c @@ -89,20 +89,20 @@ main (int argc, char *argv[]) for (i = 0; i < sizeof (pkcs5) / sizeof (pkcs5[0]); i++) { rc = gc_pbkdf2_sha1 (pkcs5[i].password, strlen (pkcs5[i].password), - pkcs5[i].salt, strlen (pkcs5[i].salt), - pkcs5[i].iterations, out, pkcs5[i].dklen); + pkcs5[i].salt, strlen (pkcs5[i].salt), + pkcs5[i].iterations, out, pkcs5[i].dklen); if (rc != GC_OK) - { - printf ("PKCS5 entry %ld failed fatally: %d\n", - (unsigned long) i, rc); - return 1; - } + { + printf ("PKCS5 entry %ld failed fatally: %d\n", + (unsigned long) i, rc); + return 1; + } if (memcmp (pkcs5[i].expected, out, pkcs5[i].dklen) != 0) - { - printf ("PKCS5 entry %ld failed\n", (unsigned long) i); - return 1; - } + { + printf ("PKCS5 entry %ld failed\n", (unsigned long) i); + return 1; + } } return 0; diff --git a/tests/test-gc-rijndael.c b/tests/test-gc-rijndael.c index ab7aebdd3..9b9d3849d 100644 --- a/tests/test-gc-rijndael.c +++ b/tests/test-gc-rijndael.c @@ -58,48 +58,48 @@ main (int argc, char *argv[]) for (i = 0; i < 10000; i++) { - rc = gc_cipher_encrypt_inline (ctx, 16, buf); - if (rc != GC_OK) - { - printf ("encrypt failed %d\n", rc); - return 1; - } + rc = gc_cipher_encrypt_inline (ctx, 16, buf); + if (rc != GC_OK) + { + printf ("encrypt failed %d\n", rc); + return 1; + } } if (memcmp (buf, ct, 16) != 0) { - size_t i; - printf ("expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", ct[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", buf[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", ct[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", buf[i] & 0xFF); + printf ("\n"); + return 1; } for (i = 0; i < 10000; i++) { - rc = gc_cipher_decrypt_inline (ctx, 16, buf); - if (rc != GC_OK) - { - printf ("decrypt failed %d\n", rc); - return 1; - } + rc = gc_cipher_decrypt_inline (ctx, 16, buf); + if (rc != GC_OK) + { + printf ("decrypt failed %d\n", rc); + return 1; + } } if (memcmp (buf, pt, 16) != 0) { - size_t i; - printf ("expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", pt[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", buf[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", pt[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", buf[i] & 0xFF); + printf ("\n"); + return 1; } gc_cipher_close (ctx); @@ -135,25 +135,25 @@ main (int argc, char *argv[]) for (i = 0; i < 10000; i++) { - rc = gc_cipher_encrypt_inline (ctx, 16, buf); - if (rc != GC_OK) - { - printf ("encrypt failed %d\n", rc); - return 1; - } + rc = gc_cipher_encrypt_inline (ctx, 16, buf); + if (rc != GC_OK) + { + printf ("encrypt failed %d\n", rc); + return 1; + } } if (memcmp (buf, ct, 16) != 0) { - size_t i; - printf ("expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", ct[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", buf[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", ct[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", buf[i] & 0xFF); + printf ("\n"); + return 1; } gc_cipher_close (ctx); diff --git a/tests/test-gc-sha1.c b/tests/test-gc-sha1.c index 63c111c27..55565e77b 100644 --- a/tests/test-gc-sha1.c +++ b/tests/test-gc-sha1.c @@ -46,53 +46,53 @@ main (int argc, char *argv[]) if (gc_sha1 (in, inlen, out) != 0) { - printf ("gc_sha1 call failed\n"); - return 1; + printf ("gc_sha1 call failed\n"); + return 1; } if (memcmp (out, expect, 20) != 0) { - size_t i; - printf ("sha1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("sha1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } rc = gc_hash_buffer (GC_SHA1, "abcdefgh", 8, out); if (rc != GC_OK) { - printf ("gc_hash_buffer(sha1) call failed: %d\n", rc); - return 1; + printf ("gc_hash_buffer(sha1) call failed: %d\n", rc); + return 1; } if (memcmp (out, expect, 20) != 0) { - size_t i; - printf ("sha1' mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("sha1' mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } if (gc_hash_digest_length (GC_SHA1) != 20) { - printf ("gc_hash_digest_length (GC_SHA1) failed\n"); - return 1; + printf ("gc_hash_digest_length (GC_SHA1) failed\n"); + return 1; } if ((rc = gc_hash_open (GC_SHA1, 0, &h)) != GC_OK) { - printf ("gc_hash_open(GC_SHA1) failed (%d)\n", rc); - return 1; + printf ("gc_hash_open(GC_SHA1) failed (%d)\n", rc); + return 1; } gc_hash_write (h, inlen, in); @@ -101,21 +101,21 @@ main (int argc, char *argv[]) if (!p) { - printf ("gc_hash_read failed\n"); - return 1; + printf ("gc_hash_read failed\n"); + return 1; } if (memcmp (p, expect, 20) != 0) { - size_t i; - printf ("sha1 1 mismatch. expected:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", expect[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", p[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("sha1 1 mismatch. expected:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", expect[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", p[i] & 0xFF); + printf ("\n"); + return 1; } gc_hash_close (h); diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c index 57c1a4d71..7464ec217 100644 --- a/tests/test-getaddrinfo.c +++ b/tests/test-getaddrinfo.c @@ -75,31 +75,31 @@ simple (char const *host, char const *service) if (res != 0) { /* EAI_AGAIN is returned if no network is available. Don't fail - the test merely because someone is down the country on their - in-law's farm. */ + the test merely because someone is down the country on their + in-law's farm. */ if (res == EAI_AGAIN) - { - skip++; - fprintf (stderr, "skipping getaddrinfo test: no network?\n"); - return 77; - } + { + skip++; + fprintf (stderr, "skipping getaddrinfo test: no network?\n"); + return 77; + } /* IRIX reports EAI_NONAME for "https". Don't fail the test - merely because of this. */ + merely because of this. */ if (res == EAI_NONAME) - return 0; + return 0; /* Solaris reports EAI_SERVICE for "http" and "https". Don't - fail the test merely because of this. */ + fail the test merely because of this. */ if (res == EAI_SERVICE) - return 0; + return 0; #ifdef EAI_NODATA /* AIX reports EAI_NODATA for "https". Don't fail the test - merely because of this. */ + merely because of this. */ if (res == EAI_NODATA) - return 0; + return 0; #endif /* Provide details if errno was set. */ if (res == EAI_SYSTEM) - dbgprintf ("system error: %s\n", strerror (err)); + dbgprintf ("system error: %s\n", strerror (err)); return 1; } @@ -112,27 +112,27 @@ simple (char const *host, char const *service) dbgprintf ("\tprotocol %x\n", ai->ai_protocol); dbgprintf ("\taddrlen %ld: ", (unsigned long) ai->ai_addrlen); dbgprintf ("\tFound %s\n", - inet_ntop (ai->ai_family, - &((struct sockaddr_in *) - ai->ai_addr)->sin_addr, - buf, sizeof (buf) - 1)); + inet_ntop (ai->ai_family, + &((struct sockaddr_in *) + ai->ai_addr)->sin_addr, + buf, sizeof (buf) - 1)); if (ai->ai_canonname) - dbgprintf ("\tFound %s...\n", ai->ai_canonname); + dbgprintf ("\tFound %s...\n", ai->ai_canonname); { - char ipbuf[BUFSIZ]; - char portbuf[BUFSIZ]; - - res = getnameinfo (ai->ai_addr, ai->ai_addrlen, - ipbuf, sizeof (ipbuf) - 1, - portbuf, sizeof (portbuf) - 1, - NI_NUMERICHOST|NI_NUMERICSERV); - dbgprintf ("\t\tgetnameinfo %d: %s\n", res, gai_strerror (res)); - if (res == 0) - { - dbgprintf ("\t\tip %s\n", ipbuf); - dbgprintf ("\t\tport %s\n", portbuf); - } + char ipbuf[BUFSIZ]; + char portbuf[BUFSIZ]; + + res = getnameinfo (ai->ai_addr, ai->ai_addrlen, + ipbuf, sizeof (ipbuf) - 1, + portbuf, sizeof (portbuf) - 1, + NI_NUMERICHOST|NI_NUMERICSERV); + dbgprintf ("\t\tgetnameinfo %d: %s\n", res, gai_strerror (res)); + if (res == 0) + { + dbgprintf ("\t\tip %s\n", ipbuf); + dbgprintf ("\t\tport %s\n", portbuf); + } } } @@ -166,8 +166,8 @@ int main (void) if (data.wVersion < requested) { - WSACleanup (); - return 2; + WSACleanup (); + return 2; } } #endif diff --git a/tests/test-getcwd.c b/tests/test-getcwd.c index 9a4ba4b63..debace7df 100644 --- a/tests/test-getcwd.c +++ b/tests/test-getcwd.c @@ -43,7 +43,7 @@ main (int argc, char **argv) if (1 < argc) { if (chdir (argv[1]) == 0) - printf ("changed to directory %s\n", argv[1]); + printf ("changed to directory %s\n", argv[1]); } pwd1 = getcwd (NULL, 0); diff --git a/tests/test-getdate.c b/tests/test-getdate.c index 58668867e..40d80dfe0 100644 --- a/tests/test-getdate.c +++ b/tests/test-getdate.c @@ -27,23 +27,23 @@ #include "getdate.h" -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", \ - __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", \ + __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #ifdef DEBUG -#define LOG(str, now, res) \ - printf ("string `%s' diff %d %d\n", \ - str, res.tv_sec - now.tv_sec, res.tv_nsec - now.tv_nsec); +#define LOG(str, now, res) \ + printf ("string `%s' diff %d %d\n", \ + str, res.tv_sec - now.tv_sec, res.tv_nsec - now.tv_nsec); #else #define LOG(str, now, res) (void) 0 #endif @@ -84,7 +84,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result, p, &now)); LOG (p, now, result); ASSERT (now.tv_sec + 24 * 60 * 60 == result.tv_sec - && now.tv_nsec == result.tv_nsec); + && now.tv_nsec == result.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; @@ -92,7 +92,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result, p, &now)); LOG (p, now, result); ASSERT (now.tv_sec - 24 * 60 * 60 == result.tv_sec - && now.tv_nsec == result.tv_nsec); + && now.tv_nsec == result.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; @@ -100,7 +100,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result, p, &now)); LOG (p, now, result); ASSERT (now.tv_sec + 4 * 60 * 60 == result.tv_sec - && now.tv_nsec == result.tv_nsec); + && now.tv_nsec == result.tv_nsec); /* test if timezone is not being ignored for day offset */ now.tv_sec = 4711; @@ -112,7 +112,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); /* test if several time zones formats are handled same way */ now.tv_sec = 4711; @@ -124,12 +124,12 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); p = "UTC+1400"; ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; @@ -140,12 +140,12 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); p = "UTC-1400"; ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; @@ -156,7 +156,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; @@ -167,7 +167,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); /* TZ out of range should cause get_date failure */ @@ -176,7 +176,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) p = "UTC+25:00"; ASSERT (!get_date (&result, p, &now)); - /* Check for several invalid countable dayshifts */ + /* Check for several invalid countable dayshifts */ now.tv_sec = 4711; now.tv_nsec = 1267; p = "UTC+4:00 +40 yesterday"; @@ -202,7 +202,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; p = "UTC+400 yesterday"; @@ -212,7 +212,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); now.tv_sec = 4711; now.tv_nsec = 1267; p = "UTC+400 now"; @@ -222,7 +222,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result2, p, &now)); LOG (p, now, result2); ASSERT (result.tv_sec == result2.tv_sec - && result.tv_nsec == result2.tv_nsec); + && result.tv_nsec == result2.tv_nsec); /* Check that some "next Monday", "last Wednesday", etc. are correct. */ setenv ("TZ", "UTC0", 1); @@ -253,7 +253,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result, p, &now)); LOG (p, now, result); ASSERT (result.tv_sec == now.tv_sec - && result.tv_nsec == now.tv_nsec); + && result.tv_nsec == now.tv_nsec); p = "FRIDAY UTC+00"; now.tv_sec = 0; @@ -261,7 +261,7 @@ main (int argc _UNUSED_PARAMETER_, char **argv) ASSERT (get_date (&result, p, &now)); LOG (p, now, result); ASSERT (result.tv_sec == 24 * 3600 - && result.tv_nsec == now.tv_nsec); + && result.tv_nsec == now.tv_nsec); return 0; } diff --git a/tests/test-getdelim.c b/tests/test-getdelim.c index da4fe6b31..8de43dbf6 100644 --- a/tests/test-getdelim.c +++ b/tests/test-getdelim.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-getdtablesize.c b/tests/test-getdtablesize.c index db77534c5..577d329ef 100644 --- a/tests/test-getdtablesize.c +++ b/tests/test-getdtablesize.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-getline.c b/tests/test-getline.c index 50722cd48..cc40c5512 100644 --- a/tests/test-getline.c +++ b/tests/test-getline.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-getndelim2.c b/tests/test-getndelim2.c index 84135eaf3..3ced1df50 100644 --- a/tests/test-getndelim2.c +++ b/tests/test-getndelim2.c @@ -26,15 +26,15 @@ #include "getndelim2.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -144,13 +144,13 @@ main (void) ASSERT (strcmp (buffer, line + 501 * 13) == 0); result = getndelim2 (&line, &len, 501 * 14 - 1, GETNLINE_NO_LIMIT, - EOF, EOF, f); + EOF, EOF, f); ASSERT (result == 1); buffer[500] = '\n'; ASSERT (strcmp (buffer, line + 501 * 13) == 0); result = getndelim2 (&line, &len, 501 * 14 - 1, GETNLINE_NO_LIMIT, - EOF, EOF, f); + EOF, EOF, f); buffer[500] = '\0'; ASSERT (strcmp (buffer, line + 501 * 13) == 0); ASSERT (result == -1); diff --git a/tests/test-getopt.c b/tests/test-getopt.c index cc87f3272..bf85a0d42 100644 --- a/tests/test-getopt.c +++ b/tests/test-getopt.c @@ -28,15 +28,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* The glibc/gnulib implementation of getopt supports setting optind = 0, diff --git a/tests/test-getopt.h b/tests/test-getopt.h index be47b53e0..bcc7fe6d4 100644 --- a/tests/test-getopt.h +++ b/tests/test-getopt.h @@ -20,11 +20,11 @@ static void getopt_loop (int argc, const char **argv, - const char *options, - int *a_seen, int *b_seen, - const char **p_value, const char **q_value, - int *non_options_count, const char **non_options, - int *unrecognized) + const char *options, + int *a_seen, int *b_seen, + const char **p_value, const char **q_value, + int *non_options_count, const char **non_options, + int *unrecognized) { int c; @@ -32,31 +32,31 @@ getopt_loop (int argc, const char **argv, while ((c = getopt (argc, (char **) argv, options)) != -1) { switch (c) - { - case 'a': - (*a_seen)++; - break; - case 'b': - (*b_seen)++; - break; - case 'p': - *p_value = optarg; - break; - case 'q': - *q_value = optarg; - break; - case '\1': - /* Must only happen with option '-' at the beginning. */ - ASSERT (options[0] == '-'); - non_options[(*non_options_count)++] = optarg; - break; - case '?': - *unrecognized = optopt; - break; - default: - *unrecognized = c; - break; - } + { + case 'a': + (*a_seen)++; + break; + case 'b': + (*b_seen)++; + break; + case 'p': + *p_value = optarg; + break; + case 'q': + *q_value = optarg; + break; + case '\1': + /* Must only happen with option '-' at the beginning. */ + ASSERT (options[0] == '-'); + non_options[(*non_options_count)++] = optarg; + break; + case '?': + *unrecognized = optopt; + break; + default: + *unrecognized = c; + break; + } } } @@ -93,8 +93,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "ab", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -123,8 +123,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "ab", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 1); ASSERT (p_value == NULL); @@ -152,8 +152,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "ab", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 1); ASSERT (p_value == NULL); @@ -182,8 +182,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "ab", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 2); ASSERT (b_seen == 1); ASSERT (p_value == NULL); @@ -212,8 +212,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "p:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -241,8 +241,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "p:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -272,8 +272,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 1); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -303,8 +303,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "p::q::", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -332,8 +332,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "p::q::", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -361,8 +361,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "abp::q::", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -395,8 +395,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -429,8 +429,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); if (posixly) { ASSERT (strcmp (argv[0], "program") == 0); @@ -497,8 +497,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); if (posixly) { ASSERT (strcmp (argv[0], "program") == 0); @@ -571,8 +571,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "-abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -621,8 +621,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "-abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -642,26 +642,26 @@ test_getopt (void) ASSERT (q_value == NULL); if (non_options_count == 2) { - /* glibc behaviour. */ - ASSERT (non_options_count == 2); - ASSERT (strcmp (non_options[0], "donald") == 0); - ASSERT (strcmp (non_options[1], "duck") == 0); - ASSERT (unrecognized == 0); - ASSERT (optind == 7); + /* glibc behaviour. */ + ASSERT (non_options_count == 2); + ASSERT (strcmp (non_options[0], "donald") == 0); + ASSERT (strcmp (non_options[1], "duck") == 0); + ASSERT (unrecognized == 0); + ASSERT (optind == 7); } else { - /* Another valid behaviour. */ - ASSERT (non_options_count == 7); - ASSERT (strcmp (non_options[0], "donald") == 0); - ASSERT (strcmp (non_options[1], "duck") == 0); - ASSERT (strcmp (non_options[2], "-b") == 0); - ASSERT (strcmp (non_options[3], "foo") == 0); - ASSERT (strcmp (non_options[4], "-q") == 0); - ASSERT (strcmp (non_options[5], "johnny") == 0); - ASSERT (strcmp (non_options[6], "bar") == 0); - ASSERT (unrecognized == 0); - ASSERT (optind == 12); + /* Another valid behaviour. */ + ASSERT (non_options_count == 7); + ASSERT (strcmp (non_options[0], "donald") == 0); + ASSERT (strcmp (non_options[1], "duck") == 0); + ASSERT (strcmp (non_options[2], "-b") == 0); + ASSERT (strcmp (non_options[3], "foo") == 0); + ASSERT (strcmp (non_options[4], "-q") == 0); + ASSERT (strcmp (non_options[5], "johnny") == 0); + ASSERT (strcmp (non_options[6], "bar") == 0); + ASSERT (unrecognized == 0); + ASSERT (optind == 12); } } #endif @@ -689,8 +689,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "abp:q:-", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); if (posixly) { ASSERT (strcmp (argv[0], "program") == 0); @@ -753,8 +753,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "+abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -788,8 +788,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "+abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -827,8 +827,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "+abp:q:", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -874,8 +874,8 @@ test_getopt (void) argv[argc] = NULL; optind = start; getopt_loop (argc, argv, "abp:q:+", - &a_seen, &b_seen, &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &a_seen, &b_seen, &p_value, &q_value, + &non_options_count, non_options, &unrecognized); if (posixly) { ASSERT (strcmp (argv[0], "program") == 0); diff --git a/tests/test-getopt_long.h b/tests/test-getopt_long.h index 63cc5c708..5b6acc64a 100644 --- a/tests/test-getopt_long.h +++ b/tests/test-getopt_long.h @@ -42,48 +42,48 @@ static const struct option long_options_optional[] = static void getopt_long_loop (int argc, const char **argv, - const char *options, const struct option *long_options, - const char **p_value, const char **q_value, - int *non_options_count, const char **non_options, - int *unrecognized) + const char *options, const struct option *long_options, + const char **p_value, const char **q_value, + int *non_options_count, const char **non_options, + int *unrecognized) { int option_index; int c; opterr = 0; while ((c = getopt_long (argc, (char **) argv, options, long_options, - &option_index)) - != -1) + &option_index)) + != -1) { switch (c) - { - case 0: - /* An option with a non-NULL flag pointer was processed. */ - break; - case 'a': - a_seen++; - break; - case 'b': - b_seen = 1; - break; - case 'p': - *p_value = optarg; - break; - case 'q': - *q_value = optarg; - break; - case '\1': - /* Must only happen with option '-' at the beginning. */ - ASSERT (options[0] == '-'); - non_options[(*non_options_count)++] = optarg; - break; - case '?': - *unrecognized = optopt; - break; - default: - *unrecognized = c; - break; - } + { + case 0: + /* An option with a non-NULL flag pointer was processed. */ + break; + case 'a': + a_seen++; + break; + case 'b': + b_seen = 1; + break; + case 'p': + *p_value = optarg; + break; + case 'q': + *q_value = optarg; + break; + case '\1': + /* Must only happen with option '-' at the beginning. */ + ASSERT (options[0] == '-'); + non_options[(*non_options_count)++] = optarg; + break; + case '?': + *unrecognized = optopt; + break; + default: + *unrecognized = c; + break; + } } } @@ -255,8 +255,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "ab", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -285,8 +285,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "ab", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 1); ASSERT (p_value == NULL); @@ -314,8 +314,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "ab", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 1); ASSERT (p_value == NULL); @@ -344,8 +344,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "ab", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 2); ASSERT (b_seen == 1); ASSERT (p_value == NULL); @@ -374,8 +374,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "p:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -403,8 +403,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "p:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -434,8 +434,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 1); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -464,8 +464,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "p::q::", long_options_optional, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -493,8 +493,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "p::q::", long_options_optional, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -522,8 +522,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "abp::q::", long_options_optional, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -555,8 +555,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); @@ -589,8 +589,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "-p") == 0); ASSERT (strcmp (argv[2], "billy") == 0); @@ -636,8 +636,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "-p") == 0); ASSERT (strcmp (argv[2], "billy") == 0); @@ -683,8 +683,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "-abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -733,8 +733,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "-abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -754,26 +754,26 @@ test_getopt_long (void) ASSERT (q_value == NULL); if (non_options_count == 2) { - /* glibc behaviour. */ - ASSERT (non_options_count == 2); - ASSERT (strcmp (non_options[0], "donald") == 0); - ASSERT (strcmp (non_options[1], "duck") == 0); - ASSERT (unrecognized == 0); - ASSERT (optind == 7); + /* glibc behaviour. */ + ASSERT (non_options_count == 2); + ASSERT (strcmp (non_options[0], "donald") == 0); + ASSERT (strcmp (non_options[1], "duck") == 0); + ASSERT (unrecognized == 0); + ASSERT (optind == 7); } else { - /* Another valid behaviour. */ - ASSERT (non_options_count == 7); - ASSERT (strcmp (non_options[0], "donald") == 0); - ASSERT (strcmp (non_options[1], "duck") == 0); - ASSERT (strcmp (non_options[2], "-b") == 0); - ASSERT (strcmp (non_options[3], "foo") == 0); - ASSERT (strcmp (non_options[4], "-q") == 0); - ASSERT (strcmp (non_options[5], "johnny") == 0); - ASSERT (strcmp (non_options[6], "bar") == 0); - ASSERT (unrecognized == 0); - ASSERT (optind == 12); + /* Another valid behaviour. */ + ASSERT (non_options_count == 7); + ASSERT (strcmp (non_options[0], "donald") == 0); + ASSERT (strcmp (non_options[1], "duck") == 0); + ASSERT (strcmp (non_options[2], "-b") == 0); + ASSERT (strcmp (non_options[3], "foo") == 0); + ASSERT (strcmp (non_options[4], "-q") == 0); + ASSERT (strcmp (non_options[5], "johnny") == 0); + ASSERT (strcmp (non_options[6], "bar") == 0); + ASSERT (unrecognized == 0); + ASSERT (optind == 12); } } @@ -800,8 +800,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "abp:q:-", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "-p") == 0); ASSERT (strcmp (argv[2], "billy") == 0); @@ -843,8 +843,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "+abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -878,8 +878,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "+abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -917,8 +917,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "+abp:q:", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "donald") == 0); ASSERT (strcmp (argv[2], "-p") == 0); @@ -964,8 +964,8 @@ test_getopt_long (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "abp:q:+", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (strcmp (argv[0], "program") == 0); ASSERT (strcmp (argv[1], "-p") == 0); ASSERT (strcmp (argv[2], "billy") == 0); @@ -1012,8 +1012,8 @@ test_getopt_long_posix (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "p::", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 0); ASSERT (b_seen == 0); ASSERT (p_value == NULL); @@ -1043,8 +1043,8 @@ test_getopt_long_posix (void) argv[argc] = NULL; optind = start; getopt_long_loop (argc, argv, "-ab", long_options_required, - &p_value, &q_value, - &non_options_count, non_options, &unrecognized); + &p_value, &q_value, + &non_options_count, non_options, &unrecognized); ASSERT (a_seen == 1); ASSERT (b_seen == 1); ASSERT (p_value == NULL); diff --git a/tests/test-glob.c b/tests/test-glob.c index fc5ec3012..750d9d887 100644 --- a/tests/test-glob.c +++ b/tests/test-glob.c @@ -24,17 +24,17 @@ #include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", \ - __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", \ + __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define GL_NO_SUCH_FILE "/gnulib-magic-does-not-exist" diff --git a/tests/test-hash.c b/tests/test-hash.c index baaab9a0c..2e7c550af 100644 --- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -32,15 +32,15 @@ #define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array)) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static bool @@ -109,10 +109,10 @@ main (int argc, char **argv) { unsigned int seed; if (get_seed (argv[1], &seed) != 0) - { - fprintf (stderr, "invalid seed: %s\n", argv[1]); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "invalid seed: %s\n", argv[1]); + exit (EXIT_FAILURE); + } srand (seed); } @@ -124,11 +124,11 @@ main (int argc, char **argv) ASSERT (ht); insert_new (ht, "a"); { - char *str1 = xstrdup ("a"); - char *str2 = hash_insert (ht, str1); - ASSERT (str1 != str2); - ASSERT (STREQ (str1, str2)); - free (str1); + char *str1 = xstrdup ("a"); + char *str2 = hash_insert (ht, str1); + ASSERT (str1 != str2); + ASSERT (STREQ (str1, str2)); + free (str1); } insert_new (ht, "b"); insert_new (ht, "c"); @@ -136,10 +136,10 @@ main (int argc, char **argv) ASSERT (hash_do_for_each (ht, walk, &i) == 3); ASSERT (i == 7); { - void *buf[5] = { NULL }; - ASSERT (hash_get_entries (ht, NULL, 0) == 0); - ASSERT (hash_get_entries (ht, buf, 5) == 3); - ASSERT (STREQ (buf[0], "a") || STREQ (buf[0], "b") || STREQ (buf[0], "c")); + void *buf[5] = { NULL }; + ASSERT (hash_get_entries (ht, NULL, 0) == 0); + ASSERT (hash_get_entries (ht, buf, 5) == 3); + ASSERT (STREQ (buf[0], "a") || STREQ (buf[0], "b") || STREQ (buf[0], "c")); } ASSERT (hash_delete (ht, "a")); ASSERT (hash_delete (ht, "a") == NULL); @@ -171,11 +171,11 @@ main (int argc, char **argv) ht = hash_initialize (sz, NULL, NULL, NULL, NULL); ASSERT (ht); { - char *str = xstrdup ("a"); - insert_new (ht, "a"); - insert_new (ht, str); - ASSERT (hash_lookup (ht, str) == str); - free (str); + char *str = xstrdup ("a"); + insert_new (ht, "a"); + insert_new (ht, str); + ASSERT (hash_lookup (ht, str) == str); + free (str); } hash_free (ht); } @@ -188,7 +188,7 @@ main (int argc, char **argv) tuning.is_n_buckets = true; /* Invalid tuning. */ ht = hash_initialize (4651, &tuning, hash_pjw, hash_compare_strings, - hash_freer); + hash_freer); ASSERT (!ht); /* Alternate tuning. */ @@ -200,67 +200,67 @@ main (int argc, char **argv) Hash_tuning const *tune = (k == 0 ? NULL : &tuning); /* Now, each entry is malloc'd. */ ht = hash_initialize (4651, tune, hash_pjw, - hash_compare_strings, hash_freer); + hash_compare_strings, hash_freer); ASSERT (ht); for (i = 0; i < 10000; i++) - { - unsigned int op = rand () % 10; - switch (op) - { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - { - char buf[50]; - char const *p = uinttostr (i, buf); - insert_new (ht, xstrdup (p)); - } - break; + { + unsigned int op = rand () % 10; + switch (op) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + { + char buf[50]; + char const *p = uinttostr (i, buf); + insert_new (ht, xstrdup (p)); + } + break; - case 6: - { - size_t n = hash_get_n_entries (ht); - ASSERT (hash_rehash (ht, n + rand () % 20)); - } - break; + case 6: + { + size_t n = hash_get_n_entries (ht); + ASSERT (hash_rehash (ht, n + rand () % 20)); + } + break; - case 7: - { - size_t n = hash_get_n_entries (ht); - size_t delta = rand () % 20; - if (delta < n) - ASSERT (hash_rehash (ht, n - delta)); - } - break; + case 7: + { + size_t n = hash_get_n_entries (ht); + size_t delta = rand () % 20; + if (delta < n) + ASSERT (hash_rehash (ht, n - delta)); + } + break; - case 8: - case 9: - { - /* Delete a random entry. */ - size_t n = hash_get_n_entries (ht); - if (n) - { - size_t kk = rand () % n; - void const *p; - void *v; - for (p = hash_get_first (ht); kk; - --kk, p = hash_get_next (ht, p)) - { - /* empty */ - } - ASSERT (p); - v = hash_delete (ht, p); - ASSERT (v); - free (v); - } - break; - } - } - ASSERT (hash_table_ok (ht)); - } + case 8: + case 9: + { + /* Delete a random entry. */ + size_t n = hash_get_n_entries (ht); + if (n) + { + size_t kk = rand () % n; + void const *p; + void *v; + for (p = hash_get_first (ht); kk; + --kk, p = hash_get_next (ht, p)) + { + /* empty */ + } + ASSERT (p); + v = hash_delete (ht, p); + ASSERT (v); + free (v); + } + break; + } + } + ASSERT (hash_table_ok (ht)); + } hash_free (ht); } diff --git a/tests/test-hmac-md5.c b/tests/test-hmac-md5.c index e3cf76b51..d4b2de130 100644 --- a/tests/test-hmac-md5.c +++ b/tests/test-hmac-md5.c @@ -46,21 +46,21 @@ main (int argc, char *argv[]) if (hmac_md5 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, 16) != 0) { - size_t i; - printf ("hash 1 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 1 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } @@ -81,21 +81,21 @@ main (int argc, char *argv[]) if (hmac_md5 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, 16) != 0) { - size_t i; - printf ("hash 2 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 2 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } @@ -125,21 +125,21 @@ main (int argc, char *argv[]) if (hmac_md5 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, 16) != 0) { - size_t i; - printf ("hash 3 mismatch. expected:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 16; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 3 mismatch. expected:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 16; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } diff --git a/tests/test-hmac-sha1.c b/tests/test-hmac-sha1.c index 22f27492e..8482214fd 100644 --- a/tests/test-hmac-sha1.c +++ b/tests/test-hmac-sha1.c @@ -37,21 +37,21 @@ main (int argc, char *argv[]) if (hmac_sha1 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, 20) != 0) { - size_t i; - printf ("hash 1 mismatch. expected:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 1 mismatch. expected:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } @@ -66,21 +66,21 @@ main (int argc, char *argv[]) if (hmac_sha1 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, 20) != 0) { - size_t i; - printf ("hash 2 mismatch. expected:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 2 mismatch. expected:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } @@ -99,21 +99,21 @@ main (int argc, char *argv[]) if (hmac_sha1 (key, key_len, data, data_len, out) != 0) { - printf ("call failure\n"); - return 1; + printf ("call failure\n"); + return 1; } if (memcmp (digest, out, 20) != 0) { - size_t i; - printf ("hash 3 mismatch. expected:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", digest[i] & 0xFF); - printf ("\ncomputed:\n"); - for (i = 0; i < 20; i++) - printf ("%02x ", out[i] & 0xFF); - printf ("\n"); - return 1; + size_t i; + printf ("hash 3 mismatch. expected:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", digest[i] & 0xFF); + printf ("\ncomputed:\n"); + for (i = 0; i < 20; i++) + printf ("%02x ", out[i] & 0xFF); + printf ("\n"); + return 1; } } diff --git a/tests/test-i-ring.c b/tests/test-i-ring.c index c08a3ee94..d53123efd 100644 --- a/tests/test-i-ring.c +++ b/tests/test-i-ring.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-iconv-utf.c b/tests/test-iconv-utf.c index ec8d03767..116477435 100644 --- a/tests/test-iconv-utf.c +++ b/tests/test-iconv-utf.c @@ -28,15 +28,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -69,8 +69,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -100,8 +100,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -131,8 +131,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -162,8 +162,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -193,8 +193,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -224,8 +224,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -255,8 +255,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); @@ -286,8 +286,8 @@ main () outptr = buf; outbytesleft = sizeof (buf); res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + (sizeof (expected) - 1)); ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); diff --git a/tests/test-iconv.c b/tests/test-iconv.c index 8bac1764b..e7e574245 100644 --- a/tests/test-iconv.c +++ b/tests/test-iconv.c @@ -28,15 +28,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -61,8 +61,8 @@ main () char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_88591_to_utf8, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + strlen (expected)); ASSERT (memcmp (buf, expected, strlen (expected)) == 0); @@ -77,8 +77,8 @@ main () char *outptr = buf; size_t outbytesleft = 1; size_t res = iconv (cd_88591_to_utf8, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == (size_t)(-1) && errno == E2BIG); ASSERT (inbytesleft == 1); ASSERT (outbytesleft == 1); @@ -96,8 +96,8 @@ main () char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_utf8_to_88591, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == 0 && inbytesleft == 0); ASSERT (outptr == buf + strlen (expected)); ASSERT (memcmp (buf, expected, strlen (expected)) == 0); @@ -112,17 +112,17 @@ main () char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_utf8_to_88591, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); if (res == (size_t)(-1)) { ASSERT (errno == EILSEQ); - ASSERT (inbytesleft == strlen (input) && outptr == buf); + ASSERT (inbytesleft == strlen (input) && outptr == buf); } else { - ASSERT (res == 1); - ASSERT (inbytesleft == 0); + ASSERT (res == 1); + ASSERT (inbytesleft == 0); } } @@ -135,8 +135,8 @@ main () char *outptr = buf; size_t outbytesleft = sizeof (buf); size_t res = iconv (cd_utf8_to_88591, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); ASSERT (res == (size_t)(-1) && errno == EINVAL); ASSERT (inbytesleft == 1 && outptr == buf); } diff --git a/tests/test-iconvme.c b/tests/test-iconvme.c index 3cf26c831..4834a606d 100644 --- a/tests/test-iconvme.c +++ b/tests/test-iconvme.c @@ -41,9 +41,9 @@ int main (int ac, char *av[]) size_t len = 0; printf ("Enter string to convert:\n\t> "); if (getline (&in, &len, stdin) < 0) - perror ("getline"); + perror ("getline"); if (in[strlen (in) - 1] == '\n') - in[strlen (in) - 1] = '\0'; + in[strlen (in) - 1] = '\0'; } if (!to) @@ -51,9 +51,9 @@ int main (int ac, char *av[]) size_t len = 0; printf ("Enter destination code set:\n\t> "); if (getline (&to, &len, stdin) < 0) - perror ("getline"); + perror ("getline"); if (to[strlen (to) - 1] == '\n') - to[strlen (to) - 1] = '\0'; + to[strlen (to) - 1] = '\0'; } if (!from) @@ -61,15 +61,15 @@ int main (int ac, char *av[]) size_t len = 0; printf ("Enter source code set:\n\t> "); if (getline (&from, &len, stdin) < 0) - perror ("getline"); + perror ("getline"); if (from[strlen (from) - 1] == '\n') - from[strlen (from) - 1] = '\0'; + from[strlen (from) - 1] = '\0'; } printf (" Input string: `%s'\n" - "From code set: `%s'\n" - " To code set: `%s'\n", - in, from, to); + "From code set: `%s'\n" + " To code set: `%s'\n", + in, from, to); out = iconv_string (in, from, to); diff --git a/tests/test-idpriv-drop.c b/tests/test-idpriv-drop.c index 0da443fc3..5dbc8e288 100644 --- a/tests/test-idpriv-drop.c +++ b/tests/test-idpriv-drop.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -45,13 +45,13 @@ show_uids () uid_t saved; ASSERT (getresuid (&real, &effective, &saved) >= 0); printf ("uids: real=%d effective=%d saved=%d", - (int) real, (int) effective, (int) saved); + (int) real, (int) effective, (int) saved); #elif HAVE_GETEUID printf ("uids: real=%d effective=%d", - (int) getuid (), (int) geteuid()); + (int) getuid (), (int) geteuid()); #elif HAVE_GETUID printf ("uids: real=%d", - (int) getuid ()); + (int) getuid ()); #endif } @@ -64,13 +64,13 @@ show_gids () gid_t saved; ASSERT (getresgid (&real, &effective, &saved) >= 0); printf ("gids: real=%d effective=%d saved=%d", - (int) real, (int) effective, (int) saved); + (int) real, (int) effective, (int) saved); #elif HAVE_GETEGID printf ("gids: real=%d effective=%d", - (int) getgid (), (int) getegid()); + (int) getgid (), (int) getegid()); #elif HAVE_GETGID printf ("gids: real=%d", - (int) getgid ()); + (int) getgid ()); #endif } @@ -104,7 +104,7 @@ main (int argc, char *argv[]) { const char *arg = argv[i]; if (strcmp (arg, "-v") == 0) - verbose = true; + verbose = true; } if (verbose) @@ -122,9 +122,9 @@ main (int argc, char *argv[]) uid_t effective; uid_t saved; if (getresuid (&real, &effective, &saved) < 0 - || real != uid - || effective != uid - || saved != uid) + || real != uid + || effective != uid + || saved != uid) abort (); } #else @@ -143,9 +143,9 @@ main (int argc, char *argv[]) gid_t effective; gid_t saved; if (getresgid (&real, &effective, &saved) < 0 - || real != gid - || effective != gid - || saved != gid) + || real != gid + || effective != gid + || saved != gid) abort (); } #else diff --git a/tests/test-idpriv-droptemp.c b/tests/test-idpriv-droptemp.c index b2e4ecc90..3dc36c9a6 100644 --- a/tests/test-idpriv-droptemp.c +++ b/tests/test-idpriv-droptemp.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -45,13 +45,13 @@ show_uids () uid_t saved; ASSERT (getresuid (&real, &effective, &saved) >= 0); printf ("uids: real=%d effective=%d saved=%d", - (int) real, (int) effective, (int) saved); + (int) real, (int) effective, (int) saved); #elif HAVE_GETEUID printf ("uids: real=%d effective=%d", - (int) getuid (), (int) geteuid()); + (int) getuid (), (int) geteuid()); #elif HAVE_GETUID printf ("uids: real=%d", - (int) getuid ()); + (int) getuid ()); #endif } @@ -64,13 +64,13 @@ show_gids () gid_t saved; ASSERT (getresgid (&real, &effective, &saved) >= 0); printf ("gids: real=%d effective=%d saved=%d", - (int) real, (int) effective, (int) saved); + (int) real, (int) effective, (int) saved); #elif HAVE_GETEGID printf ("gids: real=%d effective=%d", - (int) getgid (), (int) getegid()); + (int) getgid (), (int) getegid()); #elif HAVE_GETGID printf ("gids: real=%d", - (int) getgid ()); + (int) getgid ()); #endif } @@ -110,58 +110,58 @@ main (int argc, char *argv[]) { const char *arg = argv[i]; if (strcmp (arg, "-v") == 0) - verbose = true; + verbose = true; } for (i = 0; i < 3; i++) { if (verbose) - show ("before droptemp:"); + show ("before droptemp:"); ASSERT (idpriv_temp_drop () == 0); if (verbose) - show ("privileged: "); + show ("privileged: "); /* Verify that the privileges have really been dropped. */ #if HAVE_GETEUID if (geteuid () != uid) - abort (); + abort (); #endif #if HAVE_GETUID if (getuid () != uid) - abort (); + abort (); #endif #if HAVE_GETEGID if (getegid () != gid) - abort (); + abort (); #endif #if HAVE_GETGID if (getgid () != gid) - abort (); + abort (); #endif ASSERT (idpriv_temp_restore () == 0); if (verbose) - show ("unprivileged: "); + show ("unprivileged: "); /* Verify that the privileges have really been acquired again. */ #if HAVE_GETEUID if (geteuid () != privileged_uid) - abort (); + abort (); #endif #if HAVE_GETUID if (getuid () != uid) - abort (); + abort (); #endif #if HAVE_GETEGID if (getegid () != privileged_gid) - abort (); + abort (); #endif #if HAVE_GETGID if (getgid () != gid) - abort (); + abort (); #endif } diff --git a/tests/test-inet_ntop.c b/tests/test-inet_ntop.c index 71ba5c31e..312163aab 100644 --- a/tests/test-inet_ntop.c +++ b/tests/test-inet_ntop.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-inet_pton.c b/tests/test-inet_pton.c index b6c3ab298..dc6401e1f 100644 --- a/tests/test-inet_pton.c +++ b/tests/test-inet_pton.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-isblank.c b/tests/test-isblank.c index babb99889..f25d26d05 100644 --- a/tests/test-isblank.c +++ b/tests/test-isblank.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-isfinite.c b/tests/test-isfinite.c index abfeb07ac..03f5cac0c 100644 --- a/tests/test-isfinite.c +++ b/tests/test-isfinite.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) float zerof = 0.0f; diff --git a/tests/test-isinf.c b/tests/test-isinf.c index 43c77ada1..dffd99088 100644 --- a/tests/test-isinf.c +++ b/tests/test-isinf.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) float zerof = 0.0f; diff --git a/tests/test-isnan.c b/tests/test-isnan.c index 9a0856a0e..e9dd5e321 100644 --- a/tests/test-isnan.c +++ b/tests/test-isnan.c @@ -29,15 +29,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f. diff --git a/tests/test-isnand.h b/tests/test-isnand.h index 09c5e9776..215e18a6d 100644 --- a/tests/test-isnand.h +++ b/tests/test-isnand.h @@ -23,15 +23,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0. diff --git a/tests/test-isnanf.h b/tests/test-isnanf.h index f3f387c4b..2444c6d23 100644 --- a/tests/test-isnanf.h +++ b/tests/test-isnanf.h @@ -23,15 +23,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f. diff --git a/tests/test-isnanl.h b/tests/test-isnanl.h index baf04db0d..8638f064b 100644 --- a/tests/test-isnanl.h +++ b/tests/test-isnanl.h @@ -24,15 +24,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On HP-UX 10.20, negating 0.0L does not yield -0.0L. diff --git a/tests/test-ldexpl.c b/tests/test-ldexpl.c index 5f1fbd99f..42faf6071 100644 --- a/tests/test-ldexpl.c +++ b/tests/test-ldexpl.c @@ -29,15 +29,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On HP-UX 10.20, negating 0.0L does not yield -0.0L. @@ -126,9 +126,9 @@ main () y = ldexpl (x, 0); ASSERT (y == x); y = ldexpl (x, 5); ASSERT (y == x * 32.0L); if (i - 5 >= LDBL_MIN_EXP) - { - y = ldexpl (x, -5); ASSERT (y == x * 0.03125L); - } + { + y = ldexpl (x, -5); ASSERT (y == x * 0.03125L); + } } for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L) { diff --git a/tests/test-linked_list.c b/tests/test-linked_list.c index cf0aac75d..3051a7e6e 100644 --- a/tests/test-linked_list.c +++ b/tests/test-linked_list.c @@ -32,15 +32,15 @@ static const char *objects[15] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-linkedhash_list.c b/tests/test-linkedhash_list.c index c4be6231c..58edac8e7 100644 --- a/tests/test-linkedhash_list.c +++ b/tests/test-linkedhash_list.c @@ -59,15 +59,15 @@ string_hash (const void *x) #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-localename.c b/tests/test-localename.c index 82f786bb6..e278e191f 100644 --- a/tests/test-localename.c +++ b/tests/test-localename.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -52,9 +52,9 @@ main () unsetenv ("LANG"); setlocale (LC_ALL, ""); ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), - gl_locale_name_default ()) == 0); + gl_locale_name_default ()) == 0); ASSERT (strcmp (gl_locale_name (LC_NUMERIC, "LC_NUMERIC"), - gl_locale_name_default ()) == 0); + gl_locale_name_default ()) == 0); /* Check that an empty environment variable is treated like an unset environment variable. */ @@ -65,7 +65,7 @@ main () unsetenv ("LANG"); setlocale (LC_ALL, ""); ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), - gl_locale_name_default ()) == 0); + gl_locale_name_default ()) == 0); unsetenv ("LC_ALL"); setenv ("LC_CTYPE", "", 1); @@ -73,7 +73,7 @@ main () unsetenv ("LANG"); setlocale (LC_ALL, ""); ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), - gl_locale_name_default ()) == 0); + gl_locale_name_default ()) == 0); unsetenv ("LC_ALL"); unsetenv ("LC_CTYPE"); @@ -81,7 +81,7 @@ main () unsetenv ("LANG"); setlocale (LC_ALL, ""); ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), - gl_locale_name_default ()) == 0); + gl_locale_name_default ()) == 0); unsetenv ("LC_ALL"); unsetenv ("LC_CTYPE"); @@ -89,7 +89,7 @@ main () setenv ("LANG", "", 1); setlocale (LC_ALL, ""); ASSERT (strcmp (gl_locale_name (LC_MESSAGES, "LC_MESSAGES"), - gl_locale_name_default ()) == 0); + gl_locale_name_default ()) == 0); /* Check that LC_ALL overrides the others, and LANG is overridden by the others. */ diff --git a/tests/test-lock.c b/tests/test-lock.c index 58db0859c..92306e10d 100644 --- a/tests/test-lock.c +++ b/tests/test-lock.c @@ -441,10 +441,10 @@ once_contender_thread (void *arg) gl_lock_unlock (ready_lock[id]); if (repeat == REPEAT_COUNT) - break; + break; dbgprintf ("Contender %p waiting for signal for round %d\n", - gl_thread_self (), repeat); + gl_thread_self (), repeat); #if ENABLE_LOCKING /* Wait for the signal to go. */ gl_rwlock_rdlock (fire_signal[repeat]); @@ -453,10 +453,10 @@ once_contender_thread (void *arg) #else /* Wait for the signal to go. */ while (fire_signal_state <= repeat) - yield (); + yield (); #endif dbgprintf ("Contender %p got the signal for round %d\n", - gl_thread_self (), repeat); + gl_thread_self (), repeat); /* Contend for execution. */ gl_once (once_control, once_execute); @@ -497,30 +497,30 @@ test_once (void) /* Wait until every thread is ready. */ dbgprintf ("Main thread before synchonizing for round %d\n", repeat); for (;;) - { - int ready_count = 0; - for (i = 0; i < THREAD_COUNT; i++) - { - gl_lock_lock (ready_lock[i]); - ready_count += ready[i]; - gl_lock_unlock (ready_lock[i]); - } - if (ready_count == THREAD_COUNT) - break; - yield (); - } + { + int ready_count = 0; + for (i = 0; i < THREAD_COUNT; i++) + { + gl_lock_lock (ready_lock[i]); + ready_count += ready[i]; + gl_lock_unlock (ready_lock[i]); + } + if (ready_count == THREAD_COUNT) + break; + yield (); + } dbgprintf ("Main thread after synchonizing for round %d\n", repeat); if (repeat > 0) - { - /* Check that exactly one thread executed the once_execute() - function. */ - if (performed != 1) - abort (); - } + { + /* Check that exactly one thread executed the once_execute() + function. */ + if (performed != 1) + abort (); + } if (repeat == REPEAT_COUNT) - break; + break; /* Preparation for the next round: Initialize once_control. */ memcpy (&once_control, &fresh_once, sizeof (gl_once_t)); @@ -530,11 +530,11 @@ test_once (void) /* Preparation for the next round: Reset the ready flags. */ for (i = 0; i < THREAD_COUNT; i++) - { - gl_lock_lock (ready_lock[i]); - ready[i] = 0; - gl_lock_unlock (ready_lock[i]); - } + { + gl_lock_lock (ready_lock[i]); + ready[i] = 0; + gl_lock_unlock (ready_lock[i]); + } /* Signal all threads simultaneously. */ dbgprintf ("Main thread giving signal for round %d\n", repeat); diff --git a/tests/test-lseek.c b/tests/test-lseek.c index ebba02ec6..e474a0b01 100644 --- a/tests/test-lseek.c +++ b/tests/test-lseek.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* ARGC must be 2; *ARGV[1] is '0' if stdin and stdout are files, '1' @@ -51,7 +51,7 @@ main (int argc, char **argv) errno = 0; #if ! defined __BEOS__ /* POSIX says that the last lseek call, when failing, does not change - the current offset. But BeOS sets it to 0. */ + the current offset. But BeOS sets it to 0. */ ASSERT (lseek (0, (off_t)0, SEEK_CUR) == 2); #endif #if 0 /* leads to SIGSYS on IRIX 6.5 */ @@ -65,7 +65,7 @@ main (int argc, char **argv) errno = 0; #if ! defined __BEOS__ /* POSIX says that the last lseek call, when failing, does not change - the current offset. But BeOS sets it to 0. */ + the current offset. But BeOS sets it to 0. */ ASSERT (lseek (1, (off_t)0, SEEK_CUR) == 2); #endif #if 0 /* leads to SIGSYS on IRIX 6.5 */ diff --git a/tests/test-lstat.c b/tests/test-lstat.c index b8c3d94e8..8c62bc135 100644 --- a/tests/test-lstat.c +++ b/tests/test-lstat.c @@ -33,11 +33,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-lstat.h b/tests/test-lstat.h index a47eb096e..3828316f6 100644 --- a/tests/test-lstat.h +++ b/tests/test-lstat.h @@ -74,8 +74,8 @@ test_lstat_func (int (*func) (char const *, struct stat *), bool print) { ASSERT (unlink (BASE "file") == 0); if (print) - fputs ("skipping test: symlinks not supported on this file system\n", - stderr); + fputs ("skipping test: symlinks not supported on this file system\n", + stderr); return 77; } ASSERT (symlink (BASE "file", BASE "link2") == 0); diff --git a/tests/test-mbmemcasecmp.c b/tests/test-mbmemcasecmp.c index 6044d4e63..3fb7e0a8f 100644 --- a/tests/test-mbmemcasecmp.c +++ b/tests/test-mbmemcasecmp.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-mbmemcasecmp.h" @@ -54,19 +54,19 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - test_iso_8859_1 (mbmemcasecmp, true); - return 0; + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + test_iso_8859_1 (mbmemcasecmp, true); + return 0; case '2': - /* Locale encoding is UTF-8, locale is not Turkish. */ - test_utf_8 (mbmemcasecmp, false); - return 0; + /* Locale encoding is UTF-8, locale is not Turkish. */ + test_utf_8 (mbmemcasecmp, false); + return 0; case '3': - /* Locale encoding is UTF-8, locale is Turkish. */ - test_utf_8 (mbmemcasecmp, true); - return 0; + /* Locale encoding is UTF-8, locale is Turkish. */ + test_utf_8 (mbmemcasecmp, true); + return 0; } return 1; diff --git a/tests/test-mbmemcasecmp.h b/tests/test-mbmemcasecmp.h index 2b695f7ba..bd8533198 100644 --- a/tests/test-mbmemcasecmp.h +++ b/tests/test-mbmemcasecmp.h @@ -89,13 +89,13 @@ test_iso_8859_1 (int (*my_casecmp) (const char *, size_t, const char *, size_t), if (assume_byte_values) { - /* These results are the opposite of those in test-ulc-casecmp.c, - because my_casecmp compares precomposed characters, whereas - ulc_casecmp compares decomposed character sequences. */ + /* These results are the opposite of those in test-ulc-casecmp.c, + because my_casecmp compares precomposed characters, whereas + ulc_casecmp compares decomposed character sequences. */ - ASSERT (my_casecmp (input1, SIZEOF (input1), input5, SIZEOF (input5)) > 0); + ASSERT (my_casecmp (input1, SIZEOF (input1), input5, SIZEOF (input5)) > 0); - ASSERT (my_casecmp (input2, SIZEOF (input2), input5, SIZEOF (input5)) > 0); + ASSERT (my_casecmp (input2, SIZEOF (input2), input5, SIZEOF (input5)) > 0); } } #endif @@ -191,33 +191,33 @@ test_utf_8 (int (*my_casecmp) (const char *, size_t, const char *, size_t), bool { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const char input1[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', ' ', - 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const char input2[] = { 'g', 'r', 0xC3, 0xBC, 0x73, 0x73, ' ', 'g', 'o', 't', 't', '.', ' ', - 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const char input3[] = { 'G', 'R', 0xC3, 0x9C, 0x53, 0x53, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, - 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, - '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', - 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, + 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, + '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', + 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; (void) input1; @@ -280,9 +280,9 @@ test_utf_8 (int (*my_casecmp) (const char *, size_t, const char *, size_t), bool if (!turkish) { - #if 0 /* This functionality requires ulc_casecmp. */ - ASSERT (my_casecmp (input, SIZEOF (input), casefolded, SIZEOF (casefolded)) == 0); - #endif + #if 0 /* This functionality requires ulc_casecmp. */ + ASSERT (my_casecmp (input, SIZEOF (input), casefolded, SIZEOF (casefolded)) == 0); + #endif } else ASSERT (my_casecmp (input, SIZEOF (input), casefolded_tr, SIZEOF (casefolded_tr)) == 0); @@ -322,24 +322,24 @@ test_utf_8 (int (*my_casecmp) (const char *, size_t, const char *, size_t), bool { /* "περισσότερες πληροφορίες" */ static const char input1[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; static const char input2[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 }; static const char input3[] = { - 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, - 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, - ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, - 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 + 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, + 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, + ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, + 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 }; (void) input1; diff --git a/tests/test-mbmemcasecoll.c b/tests/test-mbmemcasecoll.c index 94c0a4896..b12729604 100644 --- a/tests/test-mbmemcasecoll.c +++ b/tests/test-mbmemcasecoll.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-mbmemcasecmp.h" @@ -60,19 +60,19 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - test_iso_8859_1 (mbmemcasecoll_hard, false); - return 0; + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + test_iso_8859_1 (mbmemcasecoll_hard, false); + return 0; case '2': - /* Locale encoding is UTF-8, locale is not Turkish. */ - test_utf_8 (mbmemcasecoll_hard, false); - return 0; + /* Locale encoding is UTF-8, locale is not Turkish. */ + test_utf_8 (mbmemcasecoll_hard, false); + return 0; case '3': - /* Locale encoding is UTF-8, locale is Turkish. */ - test_utf_8 (mbmemcasecoll_hard, true); - return 0; + /* Locale encoding is UTF-8, locale is Turkish. */ + test_utf_8 (mbmemcasecoll_hard, true); + return 0; } return 1; diff --git a/tests/test-mbrtowc.c b/tests/test-mbrtowc.c index 8f1f1bec8..178e2106c 100644 --- a/tests/test-mbrtowc.c +++ b/tests/test-mbrtowc.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -81,40 +81,40 @@ main (int argc, char *argv[]) memset (&state, '\0', sizeof (mbstate_t)); for (c = 0; c < 0x100; c++) switch (c) - { - case '\t': case '\v': case '\f': - 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 '~': - /* c is in the ISO C "basic character set". */ - buf[0] = c; - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, buf, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == c); - ASSERT (mbsinit (&state)); - ret = mbrtowc (NULL, buf, 1, &state); - ASSERT (ret == 1); - ASSERT (mbsinit (&state)); - break; - } + { + case '\t': case '\v': case '\f': + 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 '~': + /* c is in the ISO C "basic character set". */ + buf[0] = c; + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, buf, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == c); + ASSERT (mbsinit (&state)); + ret = mbrtowc (NULL, buf, 1, &state); + ASSERT (ret == 1); + ASSERT (mbsinit (&state)); + break; + } } /* Test special calling convention, passing a NULL pointer. */ @@ -131,199 +131,199 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - { - char input[] = "B\374\337er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == (unsigned char) '\374'); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 2, 3, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == (unsigned char) '\337'); - ASSERT (mbsinit (&state)); - input[2] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 3, 2, &state); - ASSERT (ret == 1); - ASSERT (wc == 'e'); - ASSERT (mbsinit (&state)); - input[3] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 4, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'r'); - ASSERT (mbsinit (&state)); - } - return 0; + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + char input[] = "B\374\337er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == (unsigned char) '\374'); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 2, 3, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == (unsigned char) '\337'); + ASSERT (mbsinit (&state)); + input[2] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 3, 2, &state); + ASSERT (ret == 1); + ASSERT (wc == 'e'); + ASSERT (mbsinit (&state)); + input[3] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 4, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'r'); + ASSERT (mbsinit (&state)); + } + return 0; case '2': - /* Locale encoding is UTF-8. */ - { - char input[] = "B\303\274\303\237er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 2, 5, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[2] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 3, 4, &state); - ASSERT (ret == 2); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[3] = '\0'; - input[4] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 5, 2, &state); - ASSERT (ret == 1); - ASSERT (wc == 'e'); - ASSERT (mbsinit (&state)); - input[5] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 6, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'r'); - ASSERT (mbsinit (&state)); - } - return 0; + /* Locale encoding is UTF-8. */ + { + char input[] = "B\303\274\303\237er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 2, 5, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[2] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 3, 4, &state); + ASSERT (ret == 2); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[3] = '\0'; + input[4] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 5, 2, &state); + ASSERT (ret == 1); + ASSERT (wc == 'e'); + ASSERT (mbsinit (&state)); + input[5] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 6, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'r'); + ASSERT (mbsinit (&state)); + } + return 0; case '3': - /* Locale encoding is EUC-JP. */ - { - char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == '<'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 2, &state); - ASSERT (ret == 2); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - input[2] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 3, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[3] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 4, 4, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[4] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 5, 3, &state); - ASSERT (ret == 2); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[5] = '\0'; - input[6] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 7, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == '>'); - ASSERT (mbsinit (&state)); - } - return 0; + /* Locale encoding is EUC-JP. */ + { + char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == '<'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 2, &state); + ASSERT (ret == 2); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + input[2] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 3, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[3] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 4, 4, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[4] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 5, 3, &state); + ASSERT (ret == 2); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[5] = '\0'; + input[6] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 7, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == '>'); + ASSERT (mbsinit (&state)); + } + return 0; case '4': - /* Locale encoding is GB18030. */ - { - char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 2, 7, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[2] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 3, 6, &state); - ASSERT (ret == 4); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[3] = '\0'; - input[4] = '\0'; - input[5] = '\0'; - input[6] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 7, 2, &state); - ASSERT (ret == 1); - ASSERT (wc == 'e'); - ASSERT (mbsinit (&state)); - input[5] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 8, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'r'); - ASSERT (mbsinit (&state)); - } - return 0; + /* Locale encoding is GB18030. */ + { + char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 2, 7, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[2] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 3, 6, &state); + ASSERT (ret == 4); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[3] = '\0'; + input[4] = '\0'; + input[5] = '\0'; + input[6] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 7, 2, &state); + ASSERT (ret == 1); + ASSERT (wc == 'e'); + ASSERT (mbsinit (&state)); + input[5] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 8, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'r'); + ASSERT (mbsinit (&state)); + } + return 0; } return 1; diff --git a/tests/test-mbscasecmp.c b/tests/test-mbscasecmp.c index d6aa37a89..6e4757c7f 100644 --- a/tests/test-mbscasecmp.c +++ b/tests/test-mbscasecmp.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbscasestr1.c b/tests/test-mbscasestr1.c index 688070c2b..b174f1513 100644 --- a/tests/test-mbscasestr1.c +++ b/tests/test-mbscasestr1.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -76,16 +76,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = 'B'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbscasestr (haystack, needle) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbscasestr (haystack, needle) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -100,15 +100,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbscasestr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbscasestr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -119,18 +119,18 @@ main () char *needle = (char *) malloc (m + 2); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = '\0'; - memset (needle, 'a', m); - needle[m] = 'B'; - needle[m + 1] = '\0'; + memset (needle, 'a', m); + needle[m] = 'B'; + needle[m + 1] = '\0'; - result = mbscasestr (haystack, needle); - ASSERT (result == haystack + m); + result = mbscasestr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-mbscasestr2.c b/tests/test-mbscasestr2.c index 712bf3f32..c9b4f9858 100644 --- a/tests/test-mbscasestr2.c +++ b/tests/test-mbscasestr2.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -84,16 +84,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'a', m); - haystack[0] = '\303'; haystack[1] = '\204'; - haystack[m] = '\0'; + memset (haystack, 'a', m); + haystack[0] = '\303'; haystack[1] = '\204'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbscasestr (haystack, needle) == haystack + 2); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbscasestr (haystack, needle) == haystack + 2); + } - free (haystack); + free (haystack); } } @@ -112,15 +112,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbscasestr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbscasestr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -131,18 +131,18 @@ main () char *needle = (char *) malloc (m + 3); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = '\303'; haystack[2 * m + 1] = '\247'; - haystack[2 * m + 2] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = '\303'; haystack[2 * m + 1] = '\247'; + haystack[2 * m + 2] = '\0'; - memset (needle, 'a', m); - needle[m] = '\303'; needle[m + 1] = '\207'; - needle[m + 2] = '\0'; + memset (needle, 'a', m); + needle[m] = '\303'; needle[m + 1] = '\207'; + needle[m + 2] = '\0'; - result = mbscasestr (haystack, needle); - ASSERT (result == haystack + m); + result = mbscasestr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-mbscasestr3.c b/tests/test-mbscasestr3.c index 817704243..a636eba98 100644 --- a/tests/test-mbscasestr3.c +++ b/tests/test-mbscasestr3.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbscasestr4.c b/tests/test-mbscasestr4.c index 256e96cbd..9763f151b 100644 --- a/tests/test-mbscasestr4.c +++ b/tests/test-mbscasestr4.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbschr.c b/tests/test-mbschr.c index 23bab6d40..2028decf7 100644 --- a/tests/test-mbschr.c +++ b/tests/test-mbschr.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbscspn.c b/tests/test-mbscspn.c index c22867f42..f2dae51c8 100644 --- a/tests/test-mbscspn.c +++ b/tests/test-mbscspn.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbsinit.c b/tests/test-mbsinit.c index 5d4c9c3ae..392b8535f 100644 --- a/tests/test-mbsinit.c +++ b/tests/test-mbsinit.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -51,7 +51,7 @@ main (int argc, char *argv[]) /* configure should already have checked that the locale is supported. */ if (setlocale (LC_ALL, "") == NULL) - return 1; + return 1; ret = mbrtowc (&wc, input, 1, &state); ASSERT (ret == (size_t)(-2)); diff --git a/tests/test-mbsncasecmp.c b/tests/test-mbsncasecmp.c index 6da989f3e..2db03bab5 100644 --- a/tests/test-mbsncasecmp.c +++ b/tests/test-mbsncasecmp.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbsnrtowcs.c b/tests/test-mbsnrtowcs.c index e246118b3..60a8e1882 100644 --- a/tests/test-mbsnrtowcs.c +++ b/tests/test-mbsnrtowcs.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -84,214 +84,214 @@ main (int argc, char *argv[]) int unlimited; for (unlimited = 0; unlimited < 2; unlimited++) - { - #define BUFSIZE 10 - wchar_t buf[BUFSIZE]; - const char *src; - mbstate_t temp_state; - - { - size_t i; - for (i = 0; i < BUFSIZE; i++) - buf[i] = (wchar_t) 0xBADFACE; - } - - switch (argv[1][0]) - { - case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - { - char input[] = "B\374\337er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == (unsigned char) '\374'); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsnrtowcs (NULL, &src, 4, unlimited ? BUFSIZE : 1, &temp_state); - ASSERT (ret == 3); - ASSERT (src == input + 2); - ASSERT (mbsinit (&state)); - - src = input + 2; - ret = mbsnrtowcs (buf, &src, 4, unlimited ? BUFSIZE : 1, &state); - ASSERT (ret == (unlimited ? 3 : 1)); - ASSERT (src == (unlimited ? NULL : input + 3)); - ASSERT (wctob (buf[0]) == (unsigned char) '\337'); - if (unlimited) - { - ASSERT (buf[1] == 'e'); - ASSERT (buf[2] == 'r'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[1] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '2': - /* Locale encoding is UTF-8. */ - { - char input[] = "B\303\274\303\237er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsnrtowcs (NULL, &src, 6, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 4); - ASSERT (src == input + 2); - ASSERT (!mbsinit (&state)); - - src = input + 2; - ret = mbsnrtowcs (buf, &src, 6, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 4 : 2)); - ASSERT (src == (unlimited ? NULL : input + 5)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == 'e'); - ASSERT (buf[3] == 'r'); - ASSERT (buf[4] == 0); - ASSERT (buf[5] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '3': - /* Locale encoding is EUC-JP. */ - { - char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == '<'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 2, &state); - ASSERT (ret == 2); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - input[2] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 3, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[3] = '\0'; - - src = input + 4; - temp_state = state; - ret = mbsnrtowcs (NULL, &src, 5, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 3); - ASSERT (src == input + 4); - ASSERT (!mbsinit (&state)); - - src = input + 4; - ret = mbsnrtowcs (buf, &src, 5, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 3 : 2)); - ASSERT (src == (unlimited ? NULL : input + 7)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == '>'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '4': - /* Locale encoding is GB18030. */ - { - char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsnrtowcs (NULL, &src, 8, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 4); - ASSERT (src == input + 2); - ASSERT (!mbsinit (&state)); - - src = input + 2; - ret = mbsnrtowcs (buf, &src, 8, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 4 : 2)); - ASSERT (src == (unlimited ? NULL : input + 7)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == 'e'); - ASSERT (buf[3] == 'r'); - ASSERT (buf[4] == 0); - ASSERT (buf[5] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - default: - return 1; - } - } + { + #define BUFSIZE 10 + wchar_t buf[BUFSIZE]; + const char *src; + mbstate_t temp_state; + + { + size_t i; + for (i = 0; i < BUFSIZE; i++) + buf[i] = (wchar_t) 0xBADFACE; + } + + switch (argv[1][0]) + { + case '1': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + char input[] = "B\374\337er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == (unsigned char) '\374'); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsnrtowcs (NULL, &src, 4, unlimited ? BUFSIZE : 1, &temp_state); + ASSERT (ret == 3); + ASSERT (src == input + 2); + ASSERT (mbsinit (&state)); + + src = input + 2; + ret = mbsnrtowcs (buf, &src, 4, unlimited ? BUFSIZE : 1, &state); + ASSERT (ret == (unlimited ? 3 : 1)); + ASSERT (src == (unlimited ? NULL : input + 3)); + ASSERT (wctob (buf[0]) == (unsigned char) '\337'); + if (unlimited) + { + ASSERT (buf[1] == 'e'); + ASSERT (buf[2] == 'r'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[1] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '2': + /* Locale encoding is UTF-8. */ + { + char input[] = "B\303\274\303\237er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsnrtowcs (NULL, &src, 6, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 4); + ASSERT (src == input + 2); + ASSERT (!mbsinit (&state)); + + src = input + 2; + ret = mbsnrtowcs (buf, &src, 6, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 4 : 2)); + ASSERT (src == (unlimited ? NULL : input + 5)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == 'e'); + ASSERT (buf[3] == 'r'); + ASSERT (buf[4] == 0); + ASSERT (buf[5] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '3': + /* Locale encoding is EUC-JP. */ + { + char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == '<'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 2, &state); + ASSERT (ret == 2); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + input[2] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 3, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[3] = '\0'; + + src = input + 4; + temp_state = state; + ret = mbsnrtowcs (NULL, &src, 5, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 3); + ASSERT (src == input + 4); + ASSERT (!mbsinit (&state)); + + src = input + 4; + ret = mbsnrtowcs (buf, &src, 5, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 3 : 2)); + ASSERT (src == (unlimited ? NULL : input + 7)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == '>'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '4': + /* Locale encoding is GB18030. */ + { + char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsnrtowcs (NULL, &src, 8, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 4); + ASSERT (src == input + 2); + ASSERT (!mbsinit (&state)); + + src = input + 2; + ret = mbsnrtowcs (buf, &src, 8, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 4 : 2)); + ASSERT (src == (unlimited ? NULL : input + 7)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == 'e'); + ASSERT (buf[3] == 'r'); + ASSERT (buf[4] == 0); + ASSERT (buf[5] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + default: + return 1; + } + } return 0; } diff --git a/tests/test-mbspbrk.c b/tests/test-mbspbrk.c index 07ff02450..c5b386f81 100644 --- a/tests/test-mbspbrk.c +++ b/tests/test-mbspbrk.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbspcasecmp.c b/tests/test-mbspcasecmp.c index 489d701c0..912eb8577 100644 --- a/tests/test-mbspcasecmp.c +++ b/tests/test-mbspcasecmp.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbsrchr.c b/tests/test-mbsrchr.c index 483de8c37..160148ac3 100644 --- a/tests/test-mbsrchr.c +++ b/tests/test-mbsrchr.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbsrtowcs.c b/tests/test-mbsrtowcs.c index 81e67c1c8..49cb78ae4 100644 --- a/tests/test-mbsrtowcs.c +++ b/tests/test-mbsrtowcs.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -84,214 +84,214 @@ main (int argc, char *argv[]) int unlimited; for (unlimited = 0; unlimited < 2; unlimited++) - { - #define BUFSIZE 10 - wchar_t buf[BUFSIZE]; - const char *src; - mbstate_t temp_state; - - { - size_t i; - for (i = 0; i < BUFSIZE; i++) - buf[i] = (wchar_t) 0xBADFACE; - } - - switch (argv[1][0]) - { - case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - { - char input[] = "B\374\337er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == 1); - ASSERT (wctob (wc) == (unsigned char) '\374'); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 1, &temp_state); - ASSERT (ret == 3); - ASSERT (src == input + 2); - ASSERT (mbsinit (&state)); - - src = input + 2; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 1, &state); - ASSERT (ret == (unlimited ? 3 : 1)); - ASSERT (src == (unlimited ? NULL : input + 3)); - ASSERT (wctob (buf[0]) == (unsigned char) '\337'); - if (unlimited) - { - ASSERT (buf[1] == 'e'); - ASSERT (buf[2] == 'r'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[1] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '2': - /* Locale encoding is UTF-8. */ - { - char input[] = "B\303\274\303\237er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 4); - ASSERT (src == input + 2); - ASSERT (!mbsinit (&state)); - - src = input + 2; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 4 : 2)); - ASSERT (src == (unlimited ? NULL : input + 5)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == 'e'); - ASSERT (buf[3] == 'r'); - ASSERT (buf[4] == 0); - ASSERT (buf[5] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '3': - /* Locale encoding is EUC-JP. */ - { - char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == '<'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 2, &state); - ASSERT (ret == 2); - ASSERT (wctob (wc) == EOF); - ASSERT (mbsinit (&state)); - input[1] = '\0'; - input[2] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 3, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[3] = '\0'; - - src = input + 4; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 3); - ASSERT (src == input + 4); - ASSERT (!mbsinit (&state)); - - src = input + 4; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 3 : 2)); - ASSERT (src == (unlimited ? NULL : input + 7)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == '>'); - ASSERT (buf[3] == 0); - ASSERT (buf[4] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - case '4': - /* Locale encoding is GB18030. */ - { - char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ - memset (&state, '\0', sizeof (mbstate_t)); - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input, 1, &state); - ASSERT (ret == 1); - ASSERT (wc == 'B'); - ASSERT (mbsinit (&state)); - input[0] = '\0'; - - wc = (wchar_t) 0xBADFACE; - ret = mbrtowc (&wc, input + 1, 1, &state); - ASSERT (ret == (size_t)(-2)); - ASSERT (wc == (wchar_t) 0xBADFACE); - ASSERT (!mbsinit (&state)); - input[1] = '\0'; - - src = input + 2; - temp_state = state; - ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); - ASSERT (ret == 4); - ASSERT (src == input + 2); - ASSERT (!mbsinit (&state)); - - src = input + 2; - ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); - ASSERT (ret == (unlimited ? 4 : 2)); - ASSERT (src == (unlimited ? NULL : input + 7)); - ASSERT (wctob (buf[0]) == EOF); - ASSERT (wctob (buf[1]) == EOF); - if (unlimited) - { - ASSERT (buf[2] == 'e'); - ASSERT (buf[3] == 'r'); - ASSERT (buf[4] == 0); - ASSERT (buf[5] == (wchar_t) 0xBADFACE); - } - else - ASSERT (buf[2] == (wchar_t) 0xBADFACE); - ASSERT (mbsinit (&state)); - } - break; - - default: - return 1; - } - } + { + #define BUFSIZE 10 + wchar_t buf[BUFSIZE]; + const char *src; + mbstate_t temp_state; + + { + size_t i; + for (i = 0; i < BUFSIZE; i++) + buf[i] = (wchar_t) 0xBADFACE; + } + + switch (argv[1][0]) + { + case '1': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + char input[] = "B\374\337er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == 1); + ASSERT (wctob (wc) == (unsigned char) '\374'); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 1, &temp_state); + ASSERT (ret == 3); + ASSERT (src == input + 2); + ASSERT (mbsinit (&state)); + + src = input + 2; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 1, &state); + ASSERT (ret == (unlimited ? 3 : 1)); + ASSERT (src == (unlimited ? NULL : input + 3)); + ASSERT (wctob (buf[0]) == (unsigned char) '\337'); + if (unlimited) + { + ASSERT (buf[1] == 'e'); + ASSERT (buf[2] == 'r'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[1] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '2': + /* Locale encoding is UTF-8. */ + { + char input[] = "B\303\274\303\237er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 4); + ASSERT (src == input + 2); + ASSERT (!mbsinit (&state)); + + src = input + 2; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 4 : 2)); + ASSERT (src == (unlimited ? NULL : input + 5)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == 'e'); + ASSERT (buf[3] == 'r'); + ASSERT (buf[4] == 0); + ASSERT (buf[5] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '3': + /* Locale encoding is EUC-JP. */ + { + char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == '<'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 2, &state); + ASSERT (ret == 2); + ASSERT (wctob (wc) == EOF); + ASSERT (mbsinit (&state)); + input[1] = '\0'; + input[2] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 3, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[3] = '\0'; + + src = input + 4; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 3); + ASSERT (src == input + 4); + ASSERT (!mbsinit (&state)); + + src = input + 4; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 3 : 2)); + ASSERT (src == (unlimited ? NULL : input + 7)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == '>'); + ASSERT (buf[3] == 0); + ASSERT (buf[4] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + case '4': + /* Locale encoding is GB18030. */ + { + char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + memset (&state, '\0', sizeof (mbstate_t)); + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input, 1, &state); + ASSERT (ret == 1); + ASSERT (wc == 'B'); + ASSERT (mbsinit (&state)); + input[0] = '\0'; + + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, input + 1, 1, &state); + ASSERT (ret == (size_t)(-2)); + ASSERT (wc == (wchar_t) 0xBADFACE); + ASSERT (!mbsinit (&state)); + input[1] = '\0'; + + src = input + 2; + temp_state = state; + ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state); + ASSERT (ret == 4); + ASSERT (src == input + 2); + ASSERT (!mbsinit (&state)); + + src = input + 2; + ret = mbsrtowcs (buf, &src, unlimited ? BUFSIZE : 2, &state); + ASSERT (ret == (unlimited ? 4 : 2)); + ASSERT (src == (unlimited ? NULL : input + 7)); + ASSERT (wctob (buf[0]) == EOF); + ASSERT (wctob (buf[1]) == EOF); + if (unlimited) + { + ASSERT (buf[2] == 'e'); + ASSERT (buf[3] == 'r'); + ASSERT (buf[4] == 0); + ASSERT (buf[5] == (wchar_t) 0xBADFACE); + } + else + ASSERT (buf[2] == (wchar_t) 0xBADFACE); + ASSERT (mbsinit (&state)); + } + break; + + default: + return 1; + } + } return 0; } diff --git a/tests/test-mbsspn.c b/tests/test-mbsspn.c index 5e1b1193e..f8798dbfb 100644 --- a/tests/test-mbsspn.c +++ b/tests/test-mbsspn.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-mbsstr1.c b/tests/test-mbsstr1.c index 33aae1061..23e1dbec0 100644 --- a/tests/test-mbsstr1.c +++ b/tests/test-mbsstr1.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -75,16 +75,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = 'B'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbsstr (haystack, needle) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbsstr (haystack, needle) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -99,15 +99,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbsstr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbsstr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -118,18 +118,18 @@ main () char *needle = (char *) malloc (m + 2); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = '\0'; - memset (needle, 'A', m); - needle[m] = 'B'; - needle[m + 1] = '\0'; + memset (needle, 'A', m); + needle[m] = 'B'; + needle[m + 1] = '\0'; - result = mbsstr (haystack, needle); - ASSERT (result == haystack + m); + result = mbsstr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-mbsstr2.c b/tests/test-mbsstr2.c index c92974221..667390f4c 100644 --- a/tests/test-mbsstr2.c +++ b/tests/test-mbsstr2.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -84,16 +84,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = '\303'; haystack[1] = '\204'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = '\303'; haystack[1] = '\204'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbsstr (haystack, needle) == haystack + 2); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbsstr (haystack, needle) == haystack + 2); + } - free (haystack); + free (haystack); } } @@ -112,15 +112,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (mbsstr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (mbsstr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -131,18 +131,18 @@ main () char *needle = (char *) malloc (m + 3); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = '\303'; haystack[2 * m + 1] = '\207'; - haystack[2 * m + 2] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = '\303'; haystack[2 * m + 1] = '\207'; + haystack[2 * m + 2] = '\0'; - memset (needle, 'A', m); - needle[m] = '\303'; needle[m + 1] = '\207'; - needle[m + 2] = '\0'; + memset (needle, 'A', m); + needle[m] = '\303'; needle[m + 1] = '\207'; + needle[m + 2] = '\0'; - result = mbsstr (haystack, needle); - ASSERT (result == haystack + m); + result = mbsstr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-mbsstr3.c b/tests/test-mbsstr3.c index b4a62afe4..a948a0378 100644 --- a/tests/test-mbsstr3.c +++ b/tests/test-mbsstr3.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-md2.c b/tests/test-md2.c index 314764b35..5aaa168ba 100644 --- a/tests/test-md2.c +++ b/tests/test-md2.c @@ -42,10 +42,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < MD2_DIGEST_SIZE; i++) - printf ("%02x ", out1[i] & 0xFF); + printf ("%02x ", out1[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < MD2_DIGEST_SIZE; i++) - printf ("%02x ", buf[i] & 0xFF); + printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } @@ -56,10 +56,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < MD2_DIGEST_SIZE; i++) - printf ("%02x ", out2[i] & 0xFF); + printf ("%02x ", out2[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < MD2_DIGEST_SIZE; i++) - printf ("%02x ", buf[i] & 0xFF); + printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-md4.c b/tests/test-md4.c index 2bf6d730c..4647c56e5 100644 --- a/tests/test-md4.c +++ b/tests/test-md4.c @@ -43,10 +43,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < MD4_DIGEST_SIZE; i++) - printf ("%02x ", out1[i] & 0xFF); + printf ("%02x ", out1[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < MD4_DIGEST_SIZE; i++) - printf ("%02x ", buf[i] & 0xFF); + printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } @@ -57,10 +57,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < MD4_DIGEST_SIZE; i++) - printf ("%02x ", out2[i] & 0xFF); + printf ("%02x ", out2[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < MD4_DIGEST_SIZE; i++) - printf ("%02x ", buf[i] & 0xFF); + printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-md5.c b/tests/test-md5.c index c3f4521ce..4ede2c40f 100644 --- a/tests/test-md5.c +++ b/tests/test-md5.c @@ -42,10 +42,10 @@ main (void) size_t i; printf ("expected:\n"); for (i = 0; i < MD5_DIGEST_SIZE; i++) - printf ("%02x ", out1[i] & 0xFF); + printf ("%02x ", out1[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < MD5_DIGEST_SIZE; i++) - printf ("%02x ", buf[i] & 0xFF); + printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } @@ -55,10 +55,10 @@ main (void) size_t i; printf ("expected:\n"); for (i = 0; i < MD5_DIGEST_SIZE; i++) - printf ("%02x ", out2[i] & 0xFF); + printf ("%02x ", out2[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < MD5_DIGEST_SIZE; i++) - printf ("%02x ", buf[i] & 0xFF); + printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-memchr.c b/tests/test-memchr.c index d5e53e008..582df89fa 100644 --- a/tests/test-memchr.c +++ b/tests/test-memchr.c @@ -25,15 +25,15 @@ #include "zerosize-ptr.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Calculating void * + int is not portable, so this wrapper converts @@ -76,7 +76,7 @@ main (void) size_t repeat = 10000; for (; repeat > 0; repeat--) { - ASSERT (MEMCHR (input, 'c', n) == input + 2); + ASSERT (MEMCHR (input, 'c', n) == input + 2); } } @@ -85,12 +85,12 @@ main (void) int i, j; for (i = 0; i < 32; i++) { - for (j = 0; j < 256; j++) - input[i + j] = j; - for (j = 0; j < 256; j++) - { - ASSERT (MEMCHR (input + i, j, 256) == input + i + j); - } + for (j = 0; j < 256; j++) + input[i + j] = j; + for (j = 0; j < 256; j++) + { + ASSERT (MEMCHR (input + i, j, 256) == input + i + j); + } } } @@ -102,23 +102,23 @@ main (void) if (page_boundary != NULL) { - for (n = 1; n <= 500; n++) - { - char *mem = page_boundary - n; - memset (mem, 'X', n); - ASSERT (MEMCHR (mem, 'U', n) == NULL); - - { - size_t i; - - for (i = 0; i < n; i++) - { - mem[i] = 'U'; - ASSERT (MEMCHR (mem, 'U', 4000) == mem + i); - mem[i] = 'X'; - } - } - } + for (n = 1; n <= 500; n++) + { + char *mem = page_boundary - n; + memset (mem, 'X', n); + ASSERT (MEMCHR (mem, 'U', n) == NULL); + + { + size_t i; + + for (i = 0; i < n; i++) + { + mem[i] = 'U'; + ASSERT (MEMCHR (mem, 'U', 4000) == mem + i); + mem[i] = 'X'; + } + } + } } } diff --git a/tests/test-memchr2.c b/tests/test-memchr2.c index 6769aba21..ef0a71330 100644 --- a/tests/test-memchr2.c +++ b/tests/test-memchr2.c @@ -26,15 +26,15 @@ #include "zerosize-ptr.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Calculating void * + int is not portable, so this wrapper converts @@ -84,10 +84,10 @@ main (void) size_t repeat = 10000; for (; repeat > 0; repeat--) { - ASSERT (MEMCHR2 (input, 'c', 'e', n) == input + 2); - ASSERT (MEMCHR2 (input, 'e', 'c', n) == input + 2); - ASSERT (MEMCHR2 (input, 'c', '\0', n) == input + 2); - ASSERT (MEMCHR2 (input, '\0', 'c', n) == input + 2); + ASSERT (MEMCHR2 (input, 'c', 'e', n) == input + 2); + ASSERT (MEMCHR2 (input, 'e', 'c', n) == input + 2); + ASSERT (MEMCHR2 (input, 'c', '\0', n) == input + 2); + ASSERT (MEMCHR2 (input, '\0', 'c', n) == input + 2); } } @@ -96,13 +96,13 @@ main (void) int i, j; for (i = 0; i < 32; i++) { - for (j = 0; j < 256; j++) - input[i + j] = j; - for (j = 0; j < 256; j++) - { - ASSERT (MEMCHR2 (input + i, j, 0xff, 256) == input + i + j); - ASSERT (MEMCHR2 (input + i, 0xff, j, 256) == input + i + j); - } + for (j = 0; j < 256; j++) + input[i + j] = j; + for (j = 0; j < 256; j++) + { + ASSERT (MEMCHR2 (input + i, j, 0xff, 256) == input + i + j); + ASSERT (MEMCHR2 (input + i, 0xff, j, 256) == input + i + j); + } } } diff --git a/tests/test-memcmp.c b/tests/test-memcmp.c index d108198f9..87403161e 100644 --- a/tests/test-memcmp.c +++ b/tests/test-memcmp.c @@ -25,15 +25,15 @@ #include "zerosize-ptr.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -70,11 +70,11 @@ main (void) int i; for (i = 0; i < 4; i++) { - char *a = foo + i; - char *b = bar + i; - strcpy (a, "--------01111111"); - strcpy (b, "--------10000000"); - ASSERT (memcmp (a, b, 16) < 0); + char *a = foo + i; + char *b = bar + i; + strcpy (a, "--------01111111"); + strcpy (b, "--------10000000"); + ASSERT (memcmp (a, b, 16) < 0); } } diff --git a/tests/test-memmem.c b/tests/test-memmem.c index 7f0f9257a..8f4c28c90 100644 --- a/tests/test-memmem.c +++ b/tests/test-memmem.c @@ -27,15 +27,15 @@ #include "zerosize-ptr.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -104,15 +104,15 @@ main (int argc, char *argv[]) char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; + memset (haystack, 'A', m); + haystack[0] = 'B'; - for (; repeat > 0; repeat--) - { - ASSERT (memmem (haystack, m, needle, n) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (memmem (haystack, m, needle, n) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -128,14 +128,14 @@ main (int argc, char *argv[]) char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); + memset (needle, 'A', m); - for (; repeat > 0; repeat--) - { - ASSERT (memmem (haystack, n, needle, m) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (memmem (haystack, n, needle, m) == NULL); + } - free (needle); + free (needle); } } @@ -146,16 +146,16 @@ main (int argc, char *argv[]) char *needle = (char *) malloc (m + 1); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; - memset (needle, 'A', m); - needle[m] = 'B'; + memset (needle, 'A', m); + needle[m] = 'B'; - result = memmem (haystack, 2 * m + 1, needle, m + 1); - ASSERT (result == haystack + m); + result = memmem (haystack, 2 * m + 1, needle, m + 1); + ASSERT (result == haystack + m); } free (needle); free (haystack); @@ -171,16 +171,16 @@ main (int argc, char *argv[]) char *needle = (char *) malloc (n); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', m); - memset (needle, 'B', n); + memset (haystack, 'A', m); + memset (needle, 'B', n); - for (; repeat > 0; repeat--) - { - result = memmem (haystack, m, needle, n); - ASSERT (result == NULL); - } + for (; repeat > 0; repeat--) + { + result = memmem (haystack, m, needle, n); + ASSERT (result == NULL); + } } free (haystack); free (needle); diff --git a/tests/test-memrchr.c b/tests/test-memrchr.c index 962fc90cf..17bc1f6f2 100644 --- a/tests/test-memrchr.c +++ b/tests/test-memrchr.c @@ -25,15 +25,15 @@ #include "zerosize-ptr.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Calculating void * + int is not portable, so this wrapper converts @@ -76,7 +76,7 @@ main (void) size_t repeat = 10000; for (; repeat > 0; repeat--) { - ASSERT (MEMRCHR (input, 'c', n) == input + n - 3); + ASSERT (MEMRCHR (input, 'c', n) == input + n - 3); } } @@ -85,12 +85,12 @@ main (void) int i, j; for (i = 0; i < 32; i++) { - for (j = 0; j < 256; j++) - input[i + j] = j; - for (j = 0; j < 256; j++) - { - ASSERT (MEMRCHR (input + i, j, 256) == input + i + j); - } + for (j = 0; j < 256; j++) + input[i + j] = j; + for (j = 0; j < 256; j++) + { + ASSERT (MEMRCHR (input + i, j, 256) == input + i + j); + } } } diff --git a/tests/test-mkdir.c b/tests/test-mkdir.c index 14c332334..6a19c3003 100644 --- a/tests/test-mkdir.c +++ b/tests/test-mkdir.c @@ -31,11 +31,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-obstack-printf.c b/tests/test-obstack-printf.c index 0c918d012..fdbdcfad3 100644 --- a/tests/test-obstack-printf.c +++ b/tests/test-obstack-printf.c @@ -30,15 +30,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define obstack_chunk_alloc xmalloc diff --git a/tests/test-openat-safer.c b/tests/test-openat-safer.c index fe9d456cc..f7091807d 100644 --- a/tests/test-openat-safer.c +++ b/tests/test-openat-safer.c @@ -37,11 +37,11 @@ static FILE *myerr; do \ { \ if (!(expr)) \ - { \ - fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (myerr); \ - abort (); \ - } \ + { \ + fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (myerr); \ + abort (); \ + } \ } \ while (0) @@ -78,50 +78,50 @@ main (void) { ASSERT (fchdir (dfd) == 0); if (0 <= i) - ASSERT (close (i) == 0); + ASSERT (close (i) == 0); /* Execute once in ".", once in "..". */ for (j = 0; j <= 1; j++) - { - if (j) - ASSERT (chdir ("..") == 0); - - /* Check for error detection. */ - errno = 0; - ASSERT (openat (AT_FDCWD, "", O_RDONLY) == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (openat (dfd, "", O_RDONLY) == -1); - ASSERT (errno == ENOENT); - errno = 0; - ASSERT (openat (-1, ".", O_RDONLY) == -1); - ASSERT (errno == EBADF); - - /* Check for trailing slash and /dev/null handling. */ - errno = 0; - ASSERT (openat (dfd, "nonexist.ent/", O_CREAT | O_RDONLY, - S_IRUSR | S_IWUSR) == -1); - ASSERT (errno == ENOTDIR || errno == EISDIR || errno == ENOENT - || errno == EINVAL); - errno = 0; - ASSERT (openat (dfd, witness "/", O_RDONLY) == -1); - ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL); - /* Using a bad directory is okay for absolute paths. */ - fd = openat (-1, "/dev/null", O_WRONLY); - ASSERT (STDERR_FILENO < fd); - /* Using a non-directory is wrong for relative paths. */ - errno = 0; - ASSERT (openat (fd, ".", O_RDONLY) == -1); - ASSERT (errno == EBADF || errno == ENOTDIR); - ASSERT (close (fd) == 0); - - /* Check for our witness file. */ - fd = openat (dfd, witness, O_RDONLY | O_NOFOLLOW); - ASSERT (STDERR_FILENO < fd); - ASSERT (read (fd, buf, 2) == 2); - ASSERT (buf[0] == 'h' && buf[1] == 'i'); - ASSERT (close (fd) == 0); - } + { + if (j) + ASSERT (chdir ("..") == 0); + + /* Check for error detection. */ + errno = 0; + ASSERT (openat (AT_FDCWD, "", O_RDONLY) == -1); + ASSERT (errno == ENOENT); + errno = 0; + ASSERT (openat (dfd, "", O_RDONLY) == -1); + ASSERT (errno == ENOENT); + errno = 0; + ASSERT (openat (-1, ".", O_RDONLY) == -1); + ASSERT (errno == EBADF); + + /* Check for trailing slash and /dev/null handling. */ + errno = 0; + ASSERT (openat (dfd, "nonexist.ent/", O_CREAT | O_RDONLY, + S_IRUSR | S_IWUSR) == -1); + ASSERT (errno == ENOTDIR || errno == EISDIR || errno == ENOENT + || errno == EINVAL); + errno = 0; + ASSERT (openat (dfd, witness "/", O_RDONLY) == -1); + ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL); + /* Using a bad directory is okay for absolute paths. */ + fd = openat (-1, "/dev/null", O_WRONLY); + ASSERT (STDERR_FILENO < fd); + /* Using a non-directory is wrong for relative paths. */ + errno = 0; + ASSERT (openat (fd, ".", O_RDONLY) == -1); + ASSERT (errno == EBADF || errno == ENOTDIR); + ASSERT (close (fd) == 0); + + /* Check for our witness file. */ + fd = openat (dfd, witness, O_RDONLY | O_NOFOLLOW); + ASSERT (STDERR_FILENO < fd); + ASSERT (read (fd, buf, 2) == 2); + ASSERT (buf[0] == 'h' && buf[1] == 'i'); + ASSERT (close (fd) == 0); + } } ASSERT (fchdir (dfd) == 0); ASSERT (unlink (witness) == 0); diff --git a/tests/test-pipe-filter-gi1.c b/tests/test-pipe-filter-gi1.c index 00cbb06f2..228419874 100644 --- a/tests/test-pipe-filter-gi1.c +++ b/tests/test-pipe-filter-gi1.c @@ -28,15 +28,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) @@ -70,12 +70,12 @@ done_read (void *data_read, size_t num_bytes_read, void *private_data) { /* Handle conversion NL -> CRLF possibly done by the child process. */ if (!(O_BINARY && *q == '\r')) - { - char orig = *p; - char expected = c_toupper (orig); - ASSERT (*q == expected); - p++; - } + { + char orig = *p; + char expected = c_toupper (orig); + ASSERT (*q == expected); + p++; + } } l->nread = p - l->input; } @@ -115,7 +115,7 @@ main (int argc, char *argv[]) argv[3] = NULL; f = pipe_filter_gi_create ("tr", tr_program, argv, false, true, - prepare_read, done_read, &l); + prepare_read, done_read, &l); ASSERT (f != NULL); result = pipe_filter_gi_write (f, input, input_size); ASSERT (result == 0); diff --git a/tests/test-pipe-filter-gi2-child.c b/tests/test-pipe-filter-gi2-child.c index 858ac2607..21fcdc0d8 100644 --- a/tests/test-pipe-filter-gi2-child.c +++ b/tests/test-pipe-filter-gi2-child.c @@ -31,13 +31,13 @@ main () int i, j; if (scanf (" %d", &i) != 1) - break; + break; if (scanf (" %d", &j) != 1) - break; + break; if (j == -1) - exit (i); + exit (i); while (i <= j) - printf ("abcdefghijklmnopqrstuvwxyz%d\n", i++); + printf ("abcdefghijklmnopqrstuvwxyz%d\n", i++); } exit (0); } diff --git a/tests/test-pipe-filter-gi2-main.c b/tests/test-pipe-filter-gi2-main.c index b9a0b11a9..5cf8984aa 100644 --- a/tests/test-pipe-filter-gi2-main.c +++ b/tests/test-pipe-filter-gi2-main.c @@ -30,15 +30,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* 0.1 sec pause */ @@ -94,7 +94,7 @@ main (int argc, char **argv) path[0] = "/nonexistent/blah"; f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, true, false, - prepare_read, ignore_done_read, NULL); + prepare_read, ignore_done_read, NULL); small_nap (); rc = pipe_filter_gi_write (f, "", 1); ASSERT (rc == 127 || rc == -1); @@ -108,7 +108,7 @@ main (int argc, char **argv) { path[0] = argv[1]; f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, false, false, - prepare_read, ignore_done_read, NULL); + prepare_read, ignore_done_read, NULL); pipe_filter_gi_write_string (f, "1 -1"); ASSERT (pipe_filter_gi_close (f) == 1); printf ("Test 2 passed.\n"); @@ -121,7 +121,7 @@ main (int argc, char **argv) path[0] = argv[1]; f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, false, false, - prepare_read, ignore_done_read, NULL); + prepare_read, ignore_done_read, NULL); pipe_filter_gi_write_string (f, "1 -1\n"); /* tell the child to terminate */ small_nap (); /* let the child terminate */ rc = pipe_filter_gi_write (f, " ", 1); /* write to a closed pipe */ @@ -138,7 +138,7 @@ main (int argc, char **argv) { path[0] = argv[1]; f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, false, true, - prepare_read, output_done_read, NULL); + prepare_read, output_done_read, NULL); pipe_filter_gi_write_string (f, "1 50\n"); pipe_filter_gi_write_string (f, "51\n"); pipe_filter_gi_write_string (f, "100"); diff --git a/tests/test-pipe-filter-ii1.c b/tests/test-pipe-filter-ii1.c index 016c042fa..310a7bba7 100644 --- a/tests/test-pipe-filter-ii1.c +++ b/tests/test-pipe-filter-ii1.c @@ -28,15 +28,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) @@ -92,12 +92,12 @@ done_read (void *data_read, size_t num_bytes_read, void *private_data) { /* Handle conversion NL -> CRLF possibly done by the child process. */ if (!(O_BINARY && *q == '\r')) - { - char orig = *p; - char expected = c_toupper (orig); - ASSERT (*q == expected); - p++; - } + { + char orig = *p; + char expected = c_toupper (orig); + ASSERT (*q == expected); + p++; + } } l->nread = p - l->input; } @@ -138,9 +138,9 @@ main (int argc, char *argv[]) argv[3] = NULL; result = pipe_filter_ii_execute ("tr", tr_program, argv, false, true, - prepare_write, done_write, - prepare_read, done_read, - &l); + prepare_write, done_write, + prepare_read, done_read, + &l); ASSERT (result == 0); ASSERT (l.nwritten == input_size); ASSERT (l.nread == input_size); diff --git a/tests/test-pipe-filter-ii2-child.c b/tests/test-pipe-filter-ii2-child.c index 2cc9d43c0..3a0054141 100644 --- a/tests/test-pipe-filter-ii2-child.c +++ b/tests/test-pipe-filter-ii2-child.c @@ -31,13 +31,13 @@ main () int i, j; if (scanf (" %d", &i) != 1) - break; + break; if (scanf (" %d", &j) != 1) - break; + break; if (j == -1) - exit (i); + exit (i); while (i <= j) - printf ("abcdefghijklmnopqrstuvwxyz%d\n", i++); + printf ("abcdefghijklmnopqrstuvwxyz%d\n", i++); } exit (0); } diff --git a/tests/test-pipe-filter-ii2-main.c b/tests/test-pipe-filter-ii2-main.c index bada07e94..909634f39 100644 --- a/tests/test-pipe-filter-ii2-main.c +++ b/tests/test-pipe-filter-ii2-main.c @@ -30,15 +30,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) struct locals @@ -113,9 +113,9 @@ main (int argc, char **argv) l.nread = 0; path[0] = "/nonexistent/blah"; rc = pipe_filter_ii_execute ("pipe-filter-test", path[0], path, true, false, - prepare_write, done_write, - prepare_read, ignore_done_read, - &l); + prepare_write, done_write, + prepare_read, ignore_done_read, + &l); ASSERT (rc == 127 || rc == -1); printf ("Test 1 passed.\n"); fflush (stdout); @@ -132,9 +132,9 @@ main (int argc, char **argv) l.nread = 0; path[0] = argv[1]; rc = pipe_filter_ii_execute ("pipe-filter-test", path[0], path, false, false, - prepare_write, done_write, - prepare_read, ignore_done_read, - &l); + prepare_write, done_write, + prepare_read, ignore_done_read, + &l); ASSERT (rc == 1); printf ("Test 2 passed.\n"); fflush (stdout); @@ -151,9 +151,9 @@ main (int argc, char **argv) l.nread = 0; path[0] = argv[1]; rc = pipe_filter_ii_execute ("pipe-filter-test", path[0], path, false, true, - prepare_write, done_write, - prepare_read, output_done_read, - &l); + prepare_write, done_write, + prepare_read, output_done_read, + &l); ASSERT (rc == 0); printf ("Test 3 passed.\n"); fflush (stdout); diff --git a/tests/test-pipe.c b/tests/test-pipe.c index 404534da2..4c298a7aa 100644 --- a/tests/test-pipe.c +++ b/tests/test-pipe.c @@ -199,10 +199,10 @@ main (int argc, char *argv[]) if (strcmp (argv[1], "child") == 0) { /* fd 2 might be closed, but fd BACKUP_STDERR_FILENO is the original - stderr. */ + stderr. */ myerr = fdopen (BACKUP_STDERR_FILENO, "w"); if (!myerr) - return 2; + return 2; return child_main (argc, argv); } /* We might close fd 2 later, so save it in fd 10. */ diff --git a/tests/test-pipe2.c b/tests/test-pipe2.c index e450469bd..049af5d5a 100644 --- a/tests/test-pipe2.c +++ b/tests/test-pipe2.c @@ -31,15 +31,15 @@ #include "binary-io.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Return true if FD is open. */ @@ -106,47 +106,47 @@ main () use_cloexec = 0; #endif { - int o_flags; - int fd[2]; + int o_flags; + int fd[2]; - o_flags = 0; + o_flags = 0; #if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) - if (use_nonblocking) - o_flags |= O_NONBLOCK; + if (use_nonblocking) + o_flags |= O_NONBLOCK; #endif #if defined O_CLOEXEC - if (use_cloexec) - o_flags |= O_CLOEXEC; + if (use_cloexec) + o_flags |= O_CLOEXEC; #endif - fd[0] = -1; - fd[1] = -1; - ASSERT (pipe2 (fd, o_flags) >= 0); - ASSERT (fd[0] >= 0); - ASSERT (fd[1] >= 0); - ASSERT (fd[0] != fd[1]); - ASSERT (is_open (fd[0]) >= 0); - ASSERT (is_open (fd[1]) >= 0); - if (use_cloexec) - { - ASSERT (is_cloexec (fd[0])); - ASSERT (is_cloexec (fd[1])); - } - else - { - ASSERT (!is_cloexec (fd[0])); - ASSERT (!is_cloexec (fd[1])); - } - if (use_nonblocking) - { - ASSERT (is_nonblocking (fd[0])); - ASSERT (is_nonblocking (fd[1])); - } - else - { - ASSERT (!is_nonblocking (fd[0])); - ASSERT (!is_nonblocking (fd[1])); - } + fd[0] = -1; + fd[1] = -1; + ASSERT (pipe2 (fd, o_flags) >= 0); + ASSERT (fd[0] >= 0); + ASSERT (fd[1] >= 0); + ASSERT (fd[0] != fd[1]); + ASSERT (is_open (fd[0]) >= 0); + ASSERT (is_open (fd[1]) >= 0); + if (use_cloexec) + { + ASSERT (is_cloexec (fd[0])); + ASSERT (is_cloexec (fd[1])); + } + else + { + ASSERT (!is_cloexec (fd[0])); + ASSERT (!is_cloexec (fd[1])); + } + if (use_nonblocking) + { + ASSERT (is_nonblocking (fd[0])); + ASSERT (is_nonblocking (fd[1])); + } + else + { + ASSERT (!is_nonblocking (fd[0])); + ASSERT (!is_nonblocking (fd[1])); + } } return 0; diff --git a/tests/test-poll.c b/tests/test-poll.c index d78698e4a..ed9bd9e91 100644 --- a/tests/test-poll.c +++ b/tests/test-poll.c @@ -50,7 +50,7 @@ #define SO_REUSEPORT SO_REUSEADDR #endif -#define TEST_PORT 12345 +#define TEST_PORT 12345 /* Minimal testing infrastructure. */ @@ -268,7 +268,7 @@ test_accept_first (void) close (s); c = connect_to_socket (true); if (poll1_nowait (c, POLLOUT | POLLWRNORM | POLLRDBAND) - != (POLLOUT | POLLWRNORM)) + != (POLLOUT | POLLWRNORM)) failed ("cannot write after blocking connect"); write (c, "foo", 3); wait (&pid); diff --git a/tests/test-popen.h b/tests/test-popen.h index 9364c5afa..b0d2e6fef 100644 --- a/tests/test-popen.h +++ b/tests/test-popen.h @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -47,9 +47,9 @@ main (int argc, char **argv) if (argc > 1) { if (*argv[1] == 'r') /* Parent is reading, so we write. */ - ASSERT (putchar ('c') == 'c'); + ASSERT (putchar ('c') == 'c'); else /* Parent is writing, so we read. */ - ASSERT (getchar () == 'p'); + ASSERT (getchar () == 'p'); /* Test that parent can read non-zero status. */ return 42; } @@ -69,10 +69,10 @@ main (int argc, char **argv) int status; if (i) - { - ASSERT (fclose (stdin) == 0); - ASSERT (fclose (stdout) == 0); - } + { + ASSERT (fclose (stdin) == 0); + ASSERT (fclose (stdout) == 0); + } cmd[len + 1] = 'r'; ASSERT (child = popen (cmd, "r")); @@ -81,10 +81,10 @@ main (int argc, char **argv) ASSERT (WIFEXITED (status)); ASSERT (WEXITSTATUS (status) == 42); if (i) - { - ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1); - ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1); - } + { + ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1); + ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1); + } cmd[len + 1] = 'w'; ASSERT (child = popen (cmd, "w")); @@ -93,10 +93,10 @@ main (int argc, char **argv) ASSERT (WIFEXITED (status)); ASSERT (WEXITSTATUS (status) == 42); if (i) - { - ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1); - ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1); - } + { + ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1); + ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1); + } } free (cmd); return 0; diff --git a/tests/test-posix_spawn1.c b/tests/test-posix_spawn1.c index d3951ebae..896c7c9d4 100644 --- a/tests/test-posix_spawn1.c +++ b/tests/test-posix_spawn1.c @@ -96,9 +96,9 @@ main () || (err = posix_spawnp (&child, "/bin/sh", &actions, &attrs, argv, environ)) != 0)) { if (actions_allocated) - posix_spawn_file_actions_destroy (&actions); + posix_spawn_file_actions_destroy (&actions); if (attrs_allocated) - posix_spawnattr_destroy (&attrs); + posix_spawnattr_destroy (&attrs); sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); errno = err; perror ("subprocess failed"); diff --git a/tests/test-posix_spawn2.c b/tests/test-posix_spawn2.c index ca57713e4..f5aa2baf0 100644 --- a/tests/test-posix_spawn2.c +++ b/tests/test-posix_spawn2.c @@ -95,9 +95,9 @@ main () || (err = posix_spawnp (&child, "/bin/sh", &actions, &attrs, argv, environ)) != 0)) { if (actions_allocated) - posix_spawn_file_actions_destroy (&actions); + posix_spawn_file_actions_destroy (&actions); if (attrs_allocated) - posix_spawnattr_destroy (&attrs); + posix_spawnattr_destroy (&attrs); sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); errno = err; perror ("subprocess failed"); diff --git a/tests/test-posixtm.c b/tests/test-posixtm.c index 66ca1f7c0..e1a87a0a8 100644 --- a/tests/test-posixtm.c +++ b/tests/test-posixtm.c @@ -29,15 +29,15 @@ #include "intprops.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) struct posixtm_test diff --git a/tests/test-pread.c b/tests/test-pread.c index fd5db8e8a..0ef387d9f 100644 --- a/tests/test-pread.c +++ b/tests/test-pread.c @@ -65,12 +65,12 @@ main (void) ASSERT (init_pos == pos); for (i = 0; i < N; i++) - { - char byte_buf; - ASSERT (pread (fd, &byte_buf, 1, i) == 1); - ASSERT (byte_buf == buf[i]); - ASSERT (lseek (fd, 0, SEEK_CUR) == init_pos); - } + { + char byte_buf; + ASSERT (pread (fd, &byte_buf, 1, i) == 1); + ASSERT (byte_buf == buf[i]); + ASSERT (lseek (fd, 0, SEEK_CUR) == init_pos); + } } { diff --git a/tests/test-printf-frexp.c b/tests/test-printf-frexp.c index 8ba934888..a194132bd 100644 --- a/tests/test-printf-frexp.c +++ b/tests/test-printf-frexp.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static double diff --git a/tests/test-printf-frexpl.c b/tests/test-printf-frexpl.c index c4c156a93..50f8aaf6b 100644 --- a/tests/test-printf-frexpl.c +++ b/tests/test-printf-frexpl.c @@ -27,15 +27,15 @@ #include "fpucw.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On MIPS IRIX machines, LDBL_MIN_EXP is -1021, but the smallest reliable diff --git a/tests/test-printf-posix.c b/tests/test-printf-posix.c index 04705e879..51f1bf787 100644 --- a/tests/test-printf-posix.c +++ b/tests/test-printf-posix.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-printf-posix.h" diff --git a/tests/test-printf-posix2.c b/tests/test-printf-posix2.c index b6e4fcc55..fbd9f287d 100644 --- a/tests/test-printf-posix2.c +++ b/tests/test-printf-posix2.c @@ -73,11 +73,11 @@ main (int argc, char *argv[]) { case 0: { - void *memory = malloc (5000000); - if (memory == NULL) - return 1; - memset (memory, 17, 5000000); - return 78; + void *memory = malloc (5000000); + if (memory == NULL) + return 1; + memset (memory, 17, 5000000); + return 78; } case 1: ret = printf ("%.5000000f", 1.0); diff --git a/tests/test-priv-set.c b/tests/test-priv-set.c index 7f0587377..6d3b87ba0 100644 --- a/tests/test-priv-set.c +++ b/tests/test-priv-set.c @@ -29,15 +29,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-quotearg.c b/tests/test-quotearg.c index 7346cba60..c9636a1cc 100644 --- a/tests/test-quotearg.c +++ b/tests/test-quotearg.c @@ -33,15 +33,15 @@ #include "gettext.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) struct result_strings { @@ -302,7 +302,7 @@ compare (char const *a, size_t la, char const *b, size_t lb) static void compare_strings (char *(func) (char const *, size_t *), - struct result_strings *results, bool ascii_only) + struct result_strings *results, bool ascii_only) { size_t len; char *p; @@ -372,7 +372,7 @@ static char * use_quotearg_colon (const char *str, size_t *len) { char *p = (*len == SIZE_MAX ? quotearg_colon (str) - : quotearg_colon_mem (str, *len)); + : quotearg_colon_mem (str, *len)); *len = strlen (p); return p; } @@ -416,7 +416,7 @@ main (int argc _UNUSED_PARAMETER_, char *argv[]) set_quoting_style (NULL, c_quoting_style); ASSERT (set_quoting_flags (NULL, QA_ELIDE_OUTER_QUOTES) - == QA_ELIDE_NULL_BYTES); + == QA_ELIDE_NULL_BYTES); compare_strings (use_quotearg_buffer, &flag_results[1].group1, ascii_only); compare_strings (use_quotearg, &flag_results[1].group2, ascii_only); compare_strings (use_quote_double_quotes, &flag_results[1].group2, @@ -424,7 +424,7 @@ main (int argc _UNUSED_PARAMETER_, char *argv[]) compare_strings (use_quotearg_colon, &flag_results[1].group3, ascii_only); ASSERT (set_quoting_flags (NULL, QA_SPLIT_TRIGRAPHS) - == QA_ELIDE_OUTER_QUOTES); + == QA_ELIDE_OUTER_QUOTES); compare_strings (use_quotearg_buffer, &flag_results[2].group1, ascii_only); compare_strings (use_quotearg, &flag_results[2].group2, ascii_only); compare_strings (use_quote_double_quotes, &flag_results[2].group2, @@ -459,21 +459,21 @@ main (int argc _UNUSED_PARAMETER_, char *argv[]) const char *locale_name = getenv ("LOCALE"); if (locale_name != NULL && strcmp (locale_name, "none") != 0 - && setenv ("LC_ALL", locale_name, 1) == 0 - && setlocale (LC_ALL, "") != NULL) + && setenv ("LC_ALL", locale_name, 1) == 0 + && setlocale (LC_ALL, "") != NULL) { - textdomain ("test-quotearg"); - bindtextdomain ("test-quotearg", getenv ("LOCALEDIR")); - - set_quoting_style (NULL, locale_quoting_style); - compare_strings (use_quotearg_buffer, &locale_results[0].group1, false); - compare_strings (use_quotearg, &locale_results[0].group2, false); - compare_strings (use_quotearg_colon, &locale_results[0].group3, false); - - set_quoting_style (NULL, clocale_quoting_style); - compare_strings (use_quotearg_buffer, &locale_results[1].group1, false); - compare_strings (use_quotearg, &locale_results[1].group2, false); - compare_strings (use_quotearg_colon, &locale_results[1].group3, false); + textdomain ("test-quotearg"); + bindtextdomain ("test-quotearg", getenv ("LOCALEDIR")); + + set_quoting_style (NULL, locale_quoting_style); + compare_strings (use_quotearg_buffer, &locale_results[0].group1, false); + compare_strings (use_quotearg, &locale_results[0].group2, false); + compare_strings (use_quotearg_colon, &locale_results[0].group3, false); + + set_quoting_style (NULL, clocale_quoting_style); + compare_strings (use_quotearg_buffer, &locale_results[1].group1, false); + compare_strings (use_quotearg, &locale_results[1].group2, false); + compare_strings (use_quotearg_colon, &locale_results[1].group3, false); } } #endif /* ENABLE_NLS */ diff --git a/tests/test-random_r.c b/tests/test-random_r.c index 5308f7337..748854332 100644 --- a/tests/test-random_r.c +++ b/tests/test-random_r.c @@ -20,15 +20,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -48,7 +48,7 @@ main () ASSERT (random_r (&rand_state, &r) == 0); ASSERT (0 <= r); if (RAND_MAX / 2 < r) - ++n_big; + ++n_big; } /* Fail if none of the numbers were larger than RAND_MAX / 2. */ diff --git a/tests/test-rawmemchr.c b/tests/test-rawmemchr.c index 963af3964..eece65fbf 100644 --- a/tests/test-rawmemchr.c +++ b/tests/test-rawmemchr.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Calculating void * + int is not portable, so this wrapper converts diff --git a/tests/test-rbtree_list.c b/tests/test-rbtree_list.c index 72b047310..8351dd3b4 100644 --- a/tests/test-rbtree_list.c +++ b/tests/test-rbtree_list.c @@ -34,15 +34,15 @@ static const char *objects[15] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-rbtree_oset.c b/tests/test-rbtree_oset.c index 8cb1ae6cf..77a783876 100644 --- a/tests/test-rbtree_oset.c +++ b/tests/test-rbtree_oset.c @@ -36,15 +36,15 @@ static const char *objects[30] = #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-rbtreehash_list.c b/tests/test-rbtreehash_list.c index a238f2914..0031f26ae 100644 --- a/tests/test-rbtreehash_list.c +++ b/tests/test-rbtreehash_list.c @@ -61,15 +61,15 @@ string_hash (const void *x) #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define RANDOM(n) (rand () % (n)) #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))] diff --git a/tests/test-read-file.c b/tests/test-read-file.c index 392c4f7ea..2509680ba 100644 --- a/tests/test-read-file.c +++ b/tests/test-read-file.c @@ -41,25 +41,25 @@ main (void) if (!out) { - perror ("Could not read file"); - err = 1; - } + perror ("Could not read file"); + err = 1; + } else - { - if (out[len] != '\0') - { - perror ("BAD: out[len] not zero"); - err = 1; - } + { + if (out[len] != '\0') + { + perror ("BAD: out[len] not zero"); + err = 1; + } - /* Assume FILE1 is a regular file or a symlink to a regular file. */ - if (len != statbuf.st_size) - { - fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE1); - err = 1; - } - free (out); - } + /* Assume FILE1 is a regular file or a symlink to a regular file. */ + if (len != statbuf.st_size) + { + fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE1); + err = 1; + } + free (out); + } } /* We can perform the test only if the file exists and is readable. @@ -71,26 +71,26 @@ main (void) if (!out) { - perror ("Could not read file"); - err = 1; - } + perror ("Could not read file"); + err = 1; + } else - { - if (out[len] != '\0') - { - perror ("BAD: out[len] not zero"); - err = 1; - } + { + if (out[len] != '\0') + { + perror ("BAD: out[len] not zero"); + err = 1; + } - /* /dev/null should always be empty. Ignore statbuf.st_size, since it - is not a regular file. */ - if (len != 0) - { - fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE2); - err = 1; - } - free (out); - } + /* /dev/null should always be empty. Ignore statbuf.st_size, since it + is not a regular file. */ + if (len != 0) + { + fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE2); + err = 1; + } + free (out); + } } return err; diff --git a/tests/test-readlink.c b/tests/test-readlink.c index 78bf342cb..5e51cb6d7 100644 --- a/tests/test-readlink.c +++ b/tests/test-readlink.c @@ -32,11 +32,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-readlink.h b/tests/test-readlink.h index 5f5e9108d..543b3b338 100644 --- a/tests/test-readlink.h +++ b/tests/test-readlink.h @@ -94,13 +94,13 @@ test_readlink (ssize_t (*func) (char const *, char *, size_t), bool print) result = readlink (BASE "link", buf, 1); if (result == -1) { - ASSERT (errno == ERANGE); - ASSERT (buf[0] == (char) 0xff); + ASSERT (errno == ERANGE); + ASSERT (buf[0] == (char) 0xff); } else { - ASSERT (result == 1); - ASSERT (buf[0] == BASE[0]); + ASSERT (result == 1); + ASSERT (buf[0] == BASE[0]); } ASSERT (buf[1] == (char) 0xff); ASSERT (func (BASE "link", buf, len) == len); diff --git a/tests/test-remove.c b/tests/test-remove.c index 16bfe2f9b..7781dfc33 100644 --- a/tests/test-remove.c +++ b/tests/test-remove.c @@ -31,11 +31,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-renameat.c b/tests/test-renameat.c index d43af37d6..7cde7be10 100644 --- a/tests/test-renameat.c +++ b/tests/test-renameat.c @@ -34,11 +34,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-rijndael.c b/tests/test-rijndael.c index d9b21a29e..7cf437f19 100644 --- a/tests/test-rijndael.c +++ b/tests/test-rijndael.c @@ -36,7 +36,7 @@ main (int argc, char *argv[]) size_t i; rc = rijndaelMakeKey (&key, RIJNDAEL_DIR_ENCRYPT, - 128, "00000000000000000000000000000000"); + 128, "00000000000000000000000000000000"); if (rc != 0) printf ("makeKey failed %d\n", rc); @@ -50,7 +50,7 @@ main (int argc, char *argv[]) { rc = rijndaelBlockEncrypt (&cipher, &key, in, 128, out); if (rc < 0) - printf ("blockEncrypt failed %d\n", rc); + printf ("blockEncrypt failed %d\n", rc); memcpy (in, out, RIJNDAEL_BITSPERBLOCK / 8); } @@ -60,16 +60,16 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++) - printf ("%02x ", ct[i] & 0xFF); + printf ("%02x ", ct[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++) - printf ("%02x ", out[i] & 0xFF); + printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } rc = rijndaelMakeKey (&key, RIJNDAEL_DIR_DECRYPT, - 128, "00000000000000000000000000000000"); + 128, "00000000000000000000000000000000"); if (rc != 0) printf ("makeKey failed %d\n", rc); @@ -83,7 +83,7 @@ main (int argc, char *argv[]) rc = rijndaelBlockDecrypt (&cipher, &key, in, 128, out); if (rc < 0) - printf ("blockEncrypt failed %d\n", rc); + printf ("blockEncrypt failed %d\n", rc); } if (memcmp (out, pt, RIJNDAEL_BITSPERBLOCK / 8) != 0) @@ -91,10 +91,10 @@ main (int argc, char *argv[]) size_t i; printf ("expected:\n"); for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++) - printf ("%02x ", pt[i] & 0xFF); + printf ("%02x ", pt[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < RIJNDAEL_BITSPERBLOCK / 8; i++) - printf ("%02x ", out[i] & 0xFF); + printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-rmdir.c b/tests/test-rmdir.c index 642d92c7a..908b0e666 100644 --- a/tests/test-rmdir.c +++ b/tests/test-rmdir.c @@ -31,11 +31,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-rmdir.h b/tests/test-rmdir.h index a85973955..5f1e955be 100644 --- a/tests/test-rmdir.h +++ b/tests/test-rmdir.h @@ -80,8 +80,8 @@ test_rmdir_func (int (*func) (char const *name), bool print) if (symlink (BASE "dir", BASE "link") != 0) { if (print) - fputs ("skipping test: symlinks not supported on this file system\n", - stderr); + fputs ("skipping test: symlinks not supported on this file system\n", + stderr); return 77; } ASSERT (mkdir (BASE "dir", 0700) == 0); diff --git a/tests/test-round1.c b/tests/test-round1.c index 0f2ed94af..8e9e0ef9c 100644 --- a/tests/test-round1.c +++ b/tests/test-round1.c @@ -29,15 +29,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0. diff --git a/tests/test-round2.c b/tests/test-round2.c index b5944a94b..252ce8501 100644 --- a/tests/test-round2.c +++ b/tests/test-round2.c @@ -63,7 +63,7 @@ equal (const char *message, DOUBLE x, DOUBLE y0, DOUBLE y1) else { fprintf (stderr, "%s: "FUNCTION"(%g(%a)) = %g(%a) or %g(%a)?\n", - message, x, x, y0, y0, y1, y1); + message, x, x, y0, y0, y1, y1); return false; } } @@ -92,17 +92,17 @@ main (void) for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++) for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++) { - /* Combine highbits and lowbits into a floating-point number, - sign-extending the lowbits to DOUBLE_BITS-NUM_HIGHBITS bits. */ - union { DOUBLE f; DOUBLE_UINT i; } janus; - verify (sizeof janus.f == sizeof janus.i); - janus.i = lowbits | (highbits << (DOUBLE_BITS - NUM_HIGHBITS)); - if (lowbits >> (NUM_LOWBITS - 1)) - janus.i |= ((DOUBLE_UINT) -1 - >> (NUM_LOWBITS + NUM_HIGHBITS) - << NUM_LOWBITS); - if (!check (janus.f)) - error = true; + /* Combine highbits and lowbits into a floating-point number, + sign-extending the lowbits to DOUBLE_BITS-NUM_HIGHBITS bits. */ + union { DOUBLE f; DOUBLE_UINT i; } janus; + verify (sizeof janus.f == sizeof janus.i); + janus.i = lowbits | (highbits << (DOUBLE_BITS - NUM_HIGHBITS)); + if (lowbits >> (NUM_LOWBITS - 1)) + janus.i |= ((DOUBLE_UINT) -1 + >> (NUM_LOWBITS + NUM_HIGHBITS) + << NUM_LOWBITS); + if (!check (janus.f)) + error = true; } return (error ? 1 : 0); } diff --git a/tests/test-roundf1.c b/tests/test-roundf1.c index 159762ee0..cbf3f9edb 100644 --- a/tests/test-roundf1.c +++ b/tests/test-roundf1.c @@ -29,15 +29,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f. diff --git a/tests/test-roundl.c b/tests/test-roundl.c index ddbf47444..c4fcf0cbb 100644 --- a/tests/test-roundl.c +++ b/tests/test-roundl.c @@ -31,15 +31,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On HP-UX 10.20, negating 0.0L does not yield -0.0L. diff --git a/tests/test-safe-alloc.c b/tests/test-safe-alloc.c index 97d200ab7..fc68ae770 100644 --- a/tests/test-safe-alloc.c +++ b/tests/test-safe-alloc.c @@ -28,15 +28,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-sameacls.c b/tests/test-sameacls.c index 9453f69ed..939b9c17c 100644 --- a/tests/test-sameacls.c +++ b/tests/test-sameacls.c @@ -34,15 +34,15 @@ #include "xalloc.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -68,31 +68,31 @@ main (int argc, char *argv[]) contents1 = read_file (file1, &size1); if (contents1 == NULL) { - fprintf (stderr, "error reading file %s: errno = %d\n", file1, errno); - fflush (stderr); - abort (); + fprintf (stderr, "error reading file %s: errno = %d\n", file1, errno); + fflush (stderr); + abort (); } contents2 = read_file (file2, &size2); if (contents2 == NULL) { - fprintf (stderr, "error reading file %s: errno = %d\n", file2, errno); - fflush (stderr); - abort (); + fprintf (stderr, "error reading file %s: errno = %d\n", file2, errno); + fflush (stderr); + abort (); } if (size2 != size1) { - fprintf (stderr, "files %s and %s have different sizes\n", - file1, file2); - fflush (stderr); - abort (); + fprintf (stderr, "files %s and %s have different sizes\n", + file1, file2); + fflush (stderr); + abort (); } if (memcmp (contents1, contents2, size1) != 0) { - fprintf (stderr, "files %s and %s have different contents\n", - file1, file2); - fflush (stderr); - abort (); + fprintf (stderr, "files %s and %s have different contents\n", + file1, file2); + fflush (stderr); + abort (); } } @@ -103,131 +103,131 @@ main (int argc, char *argv[]) if (stat (file1, &statbuf1) < 0) { - fprintf (stderr, "error accessing file %s: errno = %d\n", file1, errno); - fflush (stderr); - abort (); + fprintf (stderr, "error accessing file %s: errno = %d\n", file1, errno); + fflush (stderr); + abort (); } if (stat (file2, &statbuf2) < 0) { - fprintf (stderr, "error accessing file %s: errno = %d\n", file2, errno); - fflush (stderr); - abort (); + fprintf (stderr, "error accessing file %s: errno = %d\n", file2, errno); + fflush (stderr); + abort (); } if (statbuf1.st_mode != statbuf2.st_mode) { - fprintf (stderr, "files %s and %s have different access modes: %03o and %03o\n", - file1, file2, - (unsigned int) statbuf1.st_mode, (unsigned int) statbuf2.st_mode); - return 1; + fprintf (stderr, "files %s and %s have different access modes: %03o and %03o\n", + file1, file2, + (unsigned int) statbuf1.st_mode, (unsigned int) statbuf2.st_mode); + return 1; } } { #if HAVE_ACL_GET_FILE /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */ static const int types[] = { - ACL_TYPE_ACCESS + ACL_TYPE_ACCESS # if HAVE_ACL_TYPE_EXTENDED /* MacOS X */ - , ACL_TYPE_EXTENDED + , ACL_TYPE_EXTENDED # endif }; int t; for (t = 0; t < sizeof (types) / sizeof (types[0]); t++) { - int type = types[t]; - acl_t acl1; - char *text1; - int errno1; - acl_t acl2; - char *text2; - int errno2; - - acl1 = acl_get_file (file1, type); - if (acl1 == (acl_t)NULL) - { - text1 = NULL; - errno1 = errno; - } - else - { - text1 = acl_to_text (acl1, NULL); - if (text1 == NULL) - errno1 = errno; - else - errno1 = 0; - } - acl2 = acl_get_file (file2, type); - if (acl2 == (acl_t)NULL) - { - text2 = NULL; - errno2 = errno; - } - else - { - text2 = acl_to_text (acl2, NULL); - if (text2 == NULL) - errno2 = errno; - else - errno2 = 0; - } - - if (acl1 != (acl_t)NULL) - { - if (acl2 != (acl_t)NULL) - { - if (text1 != NULL) - { - if (text2 != NULL) - { - if (strcmp (text1, text2) != 0) - { - fprintf (stderr, "files %s and %s have different ACLs:\n%s\n%s\n", - file1, file2, text1, text2); - return 1; - } - } - else - { - fprintf (stderr, "file %s has a valid ACL, but file %s has an invalid ACL\n", - file1, file2); - return 1; - } - } - else - { - if (text2 != NULL) - { - fprintf (stderr, "file %s has an invalid ACL, but file %s has a valid ACL\n", - file1, file2); - return 1; - } - else - { - if (errno1 != errno2) - { - fprintf (stderr, "files %s and %s have differently invalid ACLs, errno = %d vs. %d\n", - file1, file2, errno1, errno2); - return 1; - } - } - } - } - else - { - fprintf (stderr, "file %s has an ACL, but file %s has no ACL\n", - file1, file2); - return 1; - } - } - else - { - if (acl2 != (acl_t)NULL) - { - fprintf (stderr, "file %s has no ACL, but file %s has an ACL\n", - file1, file2); - return 1; - } - } + int type = types[t]; + acl_t acl1; + char *text1; + int errno1; + acl_t acl2; + char *text2; + int errno2; + + acl1 = acl_get_file (file1, type); + if (acl1 == (acl_t)NULL) + { + text1 = NULL; + errno1 = errno; + } + else + { + text1 = acl_to_text (acl1, NULL); + if (text1 == NULL) + errno1 = errno; + else + errno1 = 0; + } + acl2 = acl_get_file (file2, type); + if (acl2 == (acl_t)NULL) + { + text2 = NULL; + errno2 = errno; + } + else + { + text2 = acl_to_text (acl2, NULL); + if (text2 == NULL) + errno2 = errno; + else + errno2 = 0; + } + + if (acl1 != (acl_t)NULL) + { + if (acl2 != (acl_t)NULL) + { + if (text1 != NULL) + { + if (text2 != NULL) + { + if (strcmp (text1, text2) != 0) + { + fprintf (stderr, "files %s and %s have different ACLs:\n%s\n%s\n", + file1, file2, text1, text2); + return 1; + } + } + else + { + fprintf (stderr, "file %s has a valid ACL, but file %s has an invalid ACL\n", + file1, file2); + return 1; + } + } + else + { + if (text2 != NULL) + { + fprintf (stderr, "file %s has an invalid ACL, but file %s has a valid ACL\n", + file1, file2); + return 1; + } + else + { + if (errno1 != errno2) + { + fprintf (stderr, "files %s and %s have differently invalid ACLs, errno = %d vs. %d\n", + file1, file2, errno1, errno2); + return 1; + } + } + } + } + else + { + fprintf (stderr, "file %s has an ACL, but file %s has no ACL\n", + file1, file2); + return 1; + } + } + else + { + if (acl2 != (acl_t)NULL) + { + fprintf (stderr, "file %s has no ACL, but file %s has an ACL\n", + file1, file2); + return 1; + } + } } #elif HAVE_ACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ int count1; @@ -251,7 +251,7 @@ main (int argc, char *argv[]) if (count1 != count2) { fprintf (stderr, "files %s and %s have different number of ACLs: %d and %d\n", - file1, file2, count1, count2); + file1, file2, count1, count2); return 1; } else @@ -261,38 +261,38 @@ main (int argc, char *argv[]) int i; if (acl (file1, GETACL, count1, entries1) < count1) - { - fprintf (stderr, "error retrieving the ACLs of file %s\n", file1); - fflush (stderr); - abort (); - } + { + fprintf (stderr, "error retrieving the ACLs of file %s\n", file1); + fflush (stderr); + abort (); + } if (acl (file2, GETACL, count2, entries2) < count1) - { - fprintf (stderr, "error retrieving the ACLs of file %s\n", file2); - fflush (stderr); - abort (); - } + { + fprintf (stderr, "error retrieving the ACLs of file %s\n", file2); + fflush (stderr); + abort (); + } for (i = 0; i < count1; i++) - { - if (entries1[i].a_type != entries2[i].a_type) - { - fprintf (stderr, "files %s and %s: different ACL entry #%d: different types %d and %d\n", - file1, file2, i, entries1[i].a_type, entries2[i].a_type); - return 1; - } - if (entries1[i].a_id != entries2[i].a_id) - { - fprintf (stderr, "files %s and %s: different ACL entry #%d: different ids %d and %d\n", - file1, file2, i, (int)entries1[i].a_id, (int)entries2[i].a_id); - return 1; - } - if (entries1[i].a_perm != entries2[i].a_perm) - { - fprintf (stderr, "files %s and %s: different ACL entry #%d: different permissions %03o and %03o\n", - file1, file2, i, (unsigned int) entries1[i].a_perm, (unsigned int) entries2[i].a_perm); - return 1; - } - } + { + if (entries1[i].a_type != entries2[i].a_type) + { + fprintf (stderr, "files %s and %s: different ACL entry #%d: different types %d and %d\n", + file1, file2, i, entries1[i].a_type, entries2[i].a_type); + return 1; + } + if (entries1[i].a_id != entries2[i].a_id) + { + fprintf (stderr, "files %s and %s: different ACL entry #%d: different ids %d and %d\n", + file1, file2, i, (int)entries1[i].a_id, (int)entries2[i].a_id); + return 1; + } + if (entries1[i].a_perm != entries2[i].a_perm) + { + fprintf (stderr, "files %s and %s: different ACL entry #%d: different permissions %03o and %03o\n", + file1, file2, i, (unsigned int) entries1[i].a_perm, (unsigned int) entries2[i].a_perm); + return 1; + } + } } # ifdef ACE_GETACL count1 = acl (file1, ACE_GETACLCNT, 0, NULL); @@ -316,7 +316,7 @@ main (int argc, char *argv[]) if (count1 != count2) { fprintf (stderr, "files %s and %s have different number of ACE-ACLs: %d and %d\n", - file1, file2, count1, count2); + file1, file2, count1, count2); return 1; } else if (count1 > 0) @@ -326,44 +326,44 @@ main (int argc, char *argv[]) int i; if (acl (file1, ACE_GETACL, count1, entries1) < count1) - { - fprintf (stderr, "error retrieving the ACE-ACLs of file %s\n", file1); - fflush (stderr); - abort (); - } + { + fprintf (stderr, "error retrieving the ACE-ACLs of file %s\n", file1); + fflush (stderr); + abort (); + } if (acl (file2, ACE_GETACL, count2, entries2) < count1) - { - fprintf (stderr, "error retrieving the ACE-ACLs of file %s\n", file2); - fflush (stderr); - abort (); - } + { + fprintf (stderr, "error retrieving the ACE-ACLs of file %s\n", file2); + fflush (stderr); + abort (); + } for (i = 0; i < count1; i++) - { - if (entries1[i].a_type != entries2[i].a_type) - { - fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different types %d and %d\n", - file1, file2, i, entries1[i].a_type, entries2[i].a_type); - return 1; - } - if (entries1[i].a_who != entries2[i].a_who) - { - fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different ids %d and %d\n", - file1, file2, i, (int)entries1[i].a_who, (int)entries2[i].a_who); - return 1; - } - if (entries1[i].a_access_mask != entries2[i].a_access_mask) - { - fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different access masks %03o and %03o\n", - file1, file2, i, (unsigned int) entries1[i].a_access_mask, (unsigned int) entries2[i].a_access_mask); - return 1; - } - if (entries1[i].a_flags != entries2[i].a_flags) - { - fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different flags 0x%x and 0x%x\n", - file1, file2, i, (unsigned int) entries1[i].a_flags, (unsigned int) entries2[i].a_flags); - return 1; - } - } + { + if (entries1[i].a_type != entries2[i].a_type) + { + fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different types %d and %d\n", + file1, file2, i, entries1[i].a_type, entries2[i].a_type); + return 1; + } + if (entries1[i].a_who != entries2[i].a_who) + { + fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different ids %d and %d\n", + file1, file2, i, (int)entries1[i].a_who, (int)entries2[i].a_who); + return 1; + } + if (entries1[i].a_access_mask != entries2[i].a_access_mask) + { + fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different access masks %03o and %03o\n", + file1, file2, i, (unsigned int) entries1[i].a_access_mask, (unsigned int) entries2[i].a_access_mask); + return 1; + } + if (entries1[i].a_flags != entries2[i].a_flags) + { + fprintf (stderr, "files %s and %s: different ACE-ACL entry #%d: different flags 0x%x and 0x%x\n", + file1, file2, i, (unsigned int) entries1[i].a_flags, (unsigned int) entries2[i].a_flags); + return 1; + } + } } # endif #elif HAVE_GETACL /* HP-UX */ @@ -392,7 +392,7 @@ main (int argc, char *argv[]) if (count1 != count2) { fprintf (stderr, "files %s and %s have different number of ACLs: %d and %d\n", - file1, file2, count1, count2); + file1, file2, count1, count2); return 1; } else if (count1 > 0) @@ -402,38 +402,38 @@ main (int argc, char *argv[]) int i; if (getacl (file1, count1, entries1) < count1) - { - fprintf (stderr, "error retrieving the ACLs of file %s\n", file1); - fflush (stderr); - abort (); - } + { + fprintf (stderr, "error retrieving the ACLs of file %s\n", file1); + fflush (stderr); + abort (); + } if (getacl (file2, count2, entries2) < count1) - { - fprintf (stderr, "error retrieving the ACLs of file %s\n", file2); - fflush (stderr); - abort (); - } + { + fprintf (stderr, "error retrieving the ACLs of file %s\n", file2); + fflush (stderr); + abort (); + } for (i = 0; i < count1; i++) - { - if (entries1[i].uid != entries2[i].uid) - { - fprintf (stderr, "files %s and %s: different ACL entry #%d: different uids %d and %d\n", - file1, file2, i, (int)entries1[i].uid, (int)entries2[i].uid); - return 1; - } - if (entries1[i].gid != entries2[i].gid) - { - fprintf (stderr, "files %s and %s: different ACL entry #%d: different gids %d and %d\n", - file1, file2, i, (int)entries1[i].gid, (int)entries2[i].gid); - return 1; - } - if (entries1[i].mode != entries2[i].mode) - { - fprintf (stderr, "files %s and %s: different ACL entry #%d: different permissions %03o and %03o\n", - file1, file2, i, (unsigned int) entries1[i].mode, (unsigned int) entries2[i].mode); - return 1; - } - } + { + if (entries1[i].uid != entries2[i].uid) + { + fprintf (stderr, "files %s and %s: different ACL entry #%d: different uids %d and %d\n", + file1, file2, i, (int)entries1[i].uid, (int)entries2[i].uid); + return 1; + } + if (entries1[i].gid != entries2[i].gid) + { + fprintf (stderr, "files %s and %s: different ACL entry #%d: different gids %d and %d\n", + file1, file2, i, (int)entries1[i].gid, (int)entries2[i].gid); + return 1; + } + if (entries1[i].mode != entries2[i].mode) + { + fprintf (stderr, "files %s and %s: different ACL entry #%d: different permissions %03o and %03o\n", + file1, file2, i, (unsigned int) entries1[i].mode, (unsigned int) entries2[i].mode); + return 1; + } + } } #elif HAVE_ACLX_GET /* AIX */ acl_type_t type1; @@ -482,7 +482,7 @@ main (int argc, char *argv[]) if (strcmp (text1, text2) != 0) { fprintf (stderr, "files %s and %s have different ACLs:\n%s\n%s\n", - file1, file2, text1, text2); + file1, file2, text1, text2); return 1; } #elif HAVE_STATACL /* older AIX */ @@ -506,13 +506,13 @@ main (int argc, char *argv[]) if (acl1.a.acl_len != acl2.a.acl_len) { fprintf (stderr, "files %s and %s have different ACL lengths: %u and %u\n", - file1, file2, acl1.a.acl_len, acl2.a.acl_len); + file1, file2, acl1.a.acl_len, acl2.a.acl_len); return 1; } if (acl1.a.acl_mode != acl2.a.acl_mode) { fprintf (stderr, "files %s and %s have different ACL modes: %03o and %03o\n", - file1, file2, acl1.a.acl_mode, acl2.a.acl_mode); + file1, file2, acl1.a.acl_mode, acl2.a.acl_mode); return 1; } if (acl1.a.u_access != acl2.a.u_access @@ -520,15 +520,15 @@ main (int argc, char *argv[]) || acl1.a.o_access != acl2.a.o_access) { fprintf (stderr, "files %s and %s have different ACL access masks: %03o %03o %03o and %03o %03o %03o\n", - file1, file2, - acl1.a.u_access, acl1.a.g_access, acl1.a.o_access, - acl2.a.u_access, acl2.a.g_access, acl2.a.o_access); + file1, file2, + acl1.a.u_access, acl1.a.g_access, acl1.a.o_access, + acl2.a.u_access, acl2.a.g_access, acl2.a.o_access); return 1; } if (memcmp (acl1.a.acl_ext, acl2.a.acl_ext, acl1.a.acl_len) != 0) { fprintf (stderr, "files %s and %s have different ACL entries\n", - file1, file2); + file1, file2); return 1; } #endif diff --git a/tests/test-select-fd.c b/tests/test-select-fd.c index ddd2013de..73cd20a9d 100644 --- a/tests/test-select-fd.c +++ b/tests/test-select-fd.c @@ -30,42 +30,42 @@ main (int argc, char *argv[]) char mode = argv[1][0]; if (mode == 'r' || mode == 'w') - { - int fd = atoi (argv[2]); + { + int fd = atoi (argv[2]); - if (fd >= 0) - { - const char *result_file_name = argv[3]; - FILE *result_file = fopen (result_file_name, "wb"); + if (fd >= 0) + { + const char *result_file_name = argv[3]; + FILE *result_file = fopen (result_file_name, "wb"); - if (result_file != NULL) - { - fd_set fds; - struct timeval timeout; - int ret; + if (result_file != NULL) + { + fd_set fds; + struct timeval timeout; + int ret; - FD_ZERO (&fds); - FD_SET (fd, &fds); - timeout.tv_sec = 0; - timeout.tv_usec = 10000; - ret = (mode == 'r' - ? select (fd + 1, &fds, NULL, NULL, &timeout) - : select (fd + 1, NULL, &fds, NULL, &timeout)); - if (ret < 0) - { - perror ("select failed"); - exit (1); - } - if ((ret == 0) != ! FD_ISSET (fd, &fds)) - { - fprintf (stderr, "incorrect return value\n"); - exit (1); - } - fprintf (result_file, "%d\n", ret); - exit (0); - } - } - } + FD_ZERO (&fds); + FD_SET (fd, &fds); + timeout.tv_sec = 0; + timeout.tv_usec = 10000; + ret = (mode == 'r' + ? select (fd + 1, &fds, NULL, NULL, &timeout) + : select (fd + 1, NULL, &fds, NULL, &timeout)); + if (ret < 0) + { + perror ("select failed"); + exit (1); + } + if ((ret == 0) != ! FD_ISSET (fd, &fds)) + { + fprintf (stderr, "incorrect return value\n"); + exit (1); + } + fprintf (result_file, "%d\n", ret); + exit (0); + } + } + } } fprintf (stderr, "Usage: test-select-fd mode fd result-file-name\n"); exit (1); diff --git a/tests/test-select-stdin.c b/tests/test-select-stdin.c index 079dec50e..4e6441808 100644 --- a/tests/test-select-stdin.c +++ b/tests/test-select-stdin.c @@ -47,34 +47,34 @@ main (void) gettimeofday (&after, NULL); spent_usec = (after.tv_sec - before.tv_sec) * 1000000 - + after.tv_usec - before.tv_usec; + + after.tv_usec - before.tv_usec; if (ret < 0) - { - perror ("select failed"); - exit (1); - } + { + perror ("select failed"); + exit (1); + } if ((ret == 0) != ! FD_ISSET (0, &readfds)) - { - fprintf (stderr, "incorrect return value\n"); - exit (1); - } + { + fprintf (stderr, "incorrect return value\n"); + exit (1); + } if (ret == 0) - { - if (spent_usec < 250000) - { - fprintf (stderr, "returned too early\n"); - exit (1); - } - /* Timeout */ - printf ("."); fflush (stdout); - } + { + if (spent_usec < 250000) + { + fprintf (stderr, "returned too early\n"); + exit (1); + } + /* Timeout */ + printf ("."); fflush (stdout); + } else - { - char c; + { + char c; - printf ("Input available! Trying to read 1 byte...\n"); - read (0, &c, 1); - } + printf ("Input available! Trying to read 1 byte...\n"); + read (0, &c, 1); + } } } diff --git a/tests/test-select.c b/tests/test-select.c index d6d6b063a..5ce7c7fae 100644 --- a/tests/test-select.c +++ b/tests/test-select.c @@ -51,7 +51,7 @@ enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 }; #define SO_REUSEPORT SO_REUSEADDR #endif -#define TEST_PORT 12345 +#define TEST_PORT 12345 /* Minimal testing infrastructure. */ diff --git a/tests/test-set-mode-acl.c b/tests/test-set-mode-acl.c index f28789e9e..1cc1503e7 100644 --- a/tests/test-set-mode-acl.c +++ b/tests/test-set-mode-acl.c @@ -26,15 +26,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-sha1.c b/tests/test-sha1.c index 892f2c8fa..30e98b9be 100644 --- a/tests/test-sha1.c +++ b/tests/test-sha1.c @@ -31,15 +31,15 @@ main (void) char buf[SHA1_DIGEST_SIZE]; if (memcmp (sha1_buffer (in1, strlen (in1), buf), - out1, SHA1_DIGEST_SIZE) != 0) + out1, SHA1_DIGEST_SIZE) != 0) { size_t i; printf ("expected:\n"); for (i = 0; i < SHA1_DIGEST_SIZE; i++) - printf ("%02x ", out1[i] & 0xFF); + printf ("%02x ", out1[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < SHA1_DIGEST_SIZE; i++) - printf ("%02x ", buf[i] & 0xFF); + printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } diff --git a/tests/test-sigaction.c b/tests/test-sigaction.c index 2269b6965..55da288b4 100644 --- a/tests/test-sigaction.c +++ b/tests/test-sigaction.c @@ -24,16 +24,16 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - signal (SIGABRT, SIG_DFL); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + signal (SIGABRT, SIG_DFL); \ + abort (); \ + } \ + } \ while (0) #ifndef SA_NOCLDSTOP @@ -53,7 +53,7 @@ provide other flags as extensions, such as SA_RESTORER, that we must ignore in this test. */ #define MASK_SA_FLAGS (SA_NOCLDSTOP | SA_ONSTACK | SA_RESETHAND | SA_RESTART \ - | SA_SIGINFO | SA_NOCLDWAIT | SA_NODEFER) + | SA_SIGINFO | SA_NOCLDWAIT | SA_NODEFER) /* This test is unsafe in the presence of an asynchronous SIGABRT, because we install a signal-handler that is intentionally not @@ -77,8 +77,8 @@ handler (int sig) break; case 1: /* This assertion fails on glibc-2.3.6 systems with LinuxThreads, - when this program is linked with -lpthread, due to the sigaction() - override in libpthread.so. */ + when this program is linked with -lpthread, due to the sigaction() + override in libpthread.so. */ #if !defined __GLIBC__ ASSERT (sa.sa_handler == SIG_DFL); #endif diff --git a/tests/test-signbit.c b/tests/test-signbit.c index 97f68e6a7..acca7fd98 100644 --- a/tests/test-signbit.c +++ b/tests/test-signbit.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) float zerof = 0.0f; diff --git a/tests/test-sigpipe.c b/tests/test-sigpipe.c index e1c19a530..8c412ccc3 100644 --- a/tests/test-sigpipe.c +++ b/tests/test-sigpipe.c @@ -52,18 +52,18 @@ main (int argc, char **argv) char c[2] = { 'y', '\n' }; int ret = write (1, c, sizeof (c)); if (ret <= 0) - { - switch (mode) - { - case 'B': /* The write() call should have failed with EPIPE. */ - if (ret < 0 && errno == EPIPE) - exit (0); - /*FALLTHROUGH*/ - case 'A': /* The process should silently die. */ - case 'C': /* The handler should have been called. */ - fprintf (stderr, "write() returned %d with error %d.\n", ret, errno); - exit (1); - } - } + { + switch (mode) + { + case 'B': /* The write() call should have failed with EPIPE. */ + if (ret < 0 && errno == EPIPE) + exit (0); + /*FALLTHROUGH*/ + case 'A': /* The process should silently die. */ + case 'C': /* The handler should have been called. */ + fprintf (stderr, "write() returned %d with error %d.\n", ret, errno); + exit (1); + } + } } } diff --git a/tests/test-snprintf-posix.c b/tests/test-snprintf-posix.c index eee434f23..dbbef8cb1 100644 --- a/tests/test-snprintf-posix.c +++ b/tests/test-snprintf-posix.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-snprintf-posix.h" diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index 262cdda55..24999d343 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -79,15 +79,15 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas if (start_index < end_index) { if (string[start_index] == '-') - start_index++; + start_index++; if (start_index + 3 <= end_index - && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) - { - start_index += 3; - if (start_index == end_index - || (string[start_index] == '(' && string[end_index - 1] == ')')) - return 1; - } + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } } return 0; } @@ -108,18 +108,18 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) retval = my_snprintf (buf, size, "%d", 12345); ASSERT (retval == 5); if (size < 6) - { - if (size > 0) - { - ASSERT (memcmp (buf, "12345", size - 1) == 0); - ASSERT (buf[size - 1] == '\0'); - } - ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); - } + { + if (size > 0) + { + ASSERT (memcmp (buf, "12345", size - 1) == 0); + ASSERT (buf[size - 1] == '\0'); + } + ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); + } else - { - ASSERT (memcmp (buf, "12345\0EF", 8) == 0); - } + { + ASSERT (memcmp (buf, "12345\0EF", 8) == 0); + } } /* Test support of size specifiers as in C99. */ @@ -164,9 +164,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%a %d", 3.1416015625, 33, 44, 55); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -175,9 +175,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%A %d", -3.1416015625, 33, 44, 55); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -219,8 +219,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%a %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -229,9 +229,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.0a %d", 1.5, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -240,9 +240,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.0a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -251,9 +251,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.1a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -262,9 +262,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.2a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -273,9 +273,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.3a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -284,9 +284,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.3a %d", 1.49999, 33, 44, 55); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -296,9 +296,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.1a %d", 1.999, 33, 44, 55); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -307,9 +307,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%10a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -318,9 +318,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.10a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -329,9 +329,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.50a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -340,9 +340,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%-10a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -351,9 +351,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%+a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -362,9 +362,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "% a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -373,9 +373,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -384,9 +384,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#a %d", 1.0, 33, 44, 55); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -395,9 +395,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%010a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -418,8 +418,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -428,9 +428,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", 3.1416015625L, 33, 44, 55); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -439,9 +439,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%LA %d", -3.1416015625L, 33, 44, 55); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -483,8 +483,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -495,8 +495,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -507,8 +507,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -525,8 +525,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -536,8 +536,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -547,8 +547,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -558,8 +558,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -569,8 +569,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -580,9 +580,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.0La %d", 1.5L, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -591,9 +591,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.0La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -602,9 +602,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.1La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -613,9 +613,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.2La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -624,9 +624,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.3La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -635,9 +635,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.3La %d", 1.49999L, 33, 44, 55); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -648,9 +648,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.1La %d", 1.999L, 33, 44, 55); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -659,9 +659,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%10La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -670,9 +670,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.10La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -681,9 +681,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.50La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -692,9 +692,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%-10La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -703,9 +703,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%+La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -714,9 +714,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "% La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -725,9 +725,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -736,9 +736,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#La %d", 1.0L, 33, 44, 55); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -747,9 +747,9 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%010La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -770,8 +770,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -796,89 +796,89 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "0.000000" }, - { 1.234321234321234e-36, "0.000000" }, - { 1.234321234321234e-35, "0.000000" }, - { 1.234321234321234e-34, "0.000000" }, - { 1.234321234321234e-33, "0.000000" }, - { 1.234321234321234e-32, "0.000000" }, - { 1.234321234321234e-31, "0.000000" }, - { 1.234321234321234e-30, "0.000000" }, - { 1.234321234321234e-29, "0.000000" }, - { 1.234321234321234e-28, "0.000000" }, - { 1.234321234321234e-27, "0.000000" }, - { 1.234321234321234e-26, "0.000000" }, - { 1.234321234321234e-25, "0.000000" }, - { 1.234321234321234e-24, "0.000000" }, - { 1.234321234321234e-23, "0.000000" }, - { 1.234321234321234e-22, "0.000000" }, - { 1.234321234321234e-21, "0.000000" }, - { 1.234321234321234e-20, "0.000000" }, - { 1.234321234321234e-19, "0.000000" }, - { 1.234321234321234e-18, "0.000000" }, - { 1.234321234321234e-17, "0.000000" }, - { 1.234321234321234e-16, "0.000000" }, - { 1.234321234321234e-15, "0.000000" }, - { 1.234321234321234e-14, "0.000000" }, - { 1.234321234321234e-13, "0.000000" }, - { 1.234321234321234e-12, "0.000000" }, - { 1.234321234321234e-11, "0.000000" }, - { 1.234321234321234e-10, "0.000000" }, - { 1.234321234321234e-9, "0.000000" }, - { 1.234321234321234e-8, "0.000000" }, - { 1.234321234321234e-7, "0.000000" }, - { 1.234321234321234e-6, "0.000001" }, - { 1.234321234321234e-5, "0.000012" }, - { 1.234321234321234e-4, "0.000123" }, - { 1.234321234321234e-3, "0.001234" }, - { 1.234321234321234e-2, "0.012343" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.234321" }, - { 1.234321234321234e1, "12.343212" }, - { 1.234321234321234e2, "123.432123" }, - { 1.234321234321234e3, "1234.321234" }, - { 1.234321234321234e4, "12343.212343" }, - { 1.234321234321234e5, "123432.123432" }, - { 1.234321234321234e6, "1234321.234321" }, - { 1.234321234321234e7, "12343212.343212" }, - { 1.234321234321234e8, "123432123.432123" }, - { 1.234321234321234e9, "1234321234.321234" }, - { 1.234321234321234e10, "12343212343.2123**" }, - { 1.234321234321234e11, "123432123432.123***" }, - { 1.234321234321234e12, "1234321234321.23****" }, - { 1.234321234321234e13, "12343212343212.3*****" }, - { 1.234321234321234e14, "123432123432123.******" }, - { 1.234321234321234e15, "1234321234321234.000000" }, - { 1.234321234321234e16, "123432123432123**.000000" }, - { 1.234321234321234e17, "123432123432123***.000000" }, - { 1.234321234321234e18, "123432123432123****.000000" }, - { 1.234321234321234e19, "123432123432123*****.000000" }, - { 1.234321234321234e20, "123432123432123******.000000" }, - { 1.234321234321234e21, "123432123432123*******.000000" }, - { 1.234321234321234e22, "123432123432123********.000000" }, - { 1.234321234321234e23, "123432123432123*********.000000" }, - { 1.234321234321234e24, "123432123432123**********.000000" }, - { 1.234321234321234e25, "123432123432123***********.000000" }, - { 1.234321234321234e26, "123432123432123************.000000" }, - { 1.234321234321234e27, "123432123432123*************.000000" }, - { 1.234321234321234e28, "123432123432123**************.000000" }, - { 1.234321234321234e29, "123432123432123***************.000000" }, - { 1.234321234321234e30, "123432123432123****************.000000" }, - { 1.234321234321234e31, "123432123432123*****************.000000" }, - { 1.234321234321234e32, "123432123432123******************.000000" }, - { 1.234321234321234e33, "123432123432123*******************.000000" }, - { 1.234321234321234e34, "123432123432123********************.000000" }, - { 1.234321234321234e35, "123432123432123*********************.000000" }, - { 1.234321234321234e36, "123432123432123**********************.000000" } + { 1.234321234321234e-37, "0.000000" }, + { 1.234321234321234e-36, "0.000000" }, + { 1.234321234321234e-35, "0.000000" }, + { 1.234321234321234e-34, "0.000000" }, + { 1.234321234321234e-33, "0.000000" }, + { 1.234321234321234e-32, "0.000000" }, + { 1.234321234321234e-31, "0.000000" }, + { 1.234321234321234e-30, "0.000000" }, + { 1.234321234321234e-29, "0.000000" }, + { 1.234321234321234e-28, "0.000000" }, + { 1.234321234321234e-27, "0.000000" }, + { 1.234321234321234e-26, "0.000000" }, + { 1.234321234321234e-25, "0.000000" }, + { 1.234321234321234e-24, "0.000000" }, + { 1.234321234321234e-23, "0.000000" }, + { 1.234321234321234e-22, "0.000000" }, + { 1.234321234321234e-21, "0.000000" }, + { 1.234321234321234e-20, "0.000000" }, + { 1.234321234321234e-19, "0.000000" }, + { 1.234321234321234e-18, "0.000000" }, + { 1.234321234321234e-17, "0.000000" }, + { 1.234321234321234e-16, "0.000000" }, + { 1.234321234321234e-15, "0.000000" }, + { 1.234321234321234e-14, "0.000000" }, + { 1.234321234321234e-13, "0.000000" }, + { 1.234321234321234e-12, "0.000000" }, + { 1.234321234321234e-11, "0.000000" }, + { 1.234321234321234e-10, "0.000000" }, + { 1.234321234321234e-9, "0.000000" }, + { 1.234321234321234e-8, "0.000000" }, + { 1.234321234321234e-7, "0.000000" }, + { 1.234321234321234e-6, "0.000001" }, + { 1.234321234321234e-5, "0.000012" }, + { 1.234321234321234e-4, "0.000123" }, + { 1.234321234321234e-3, "0.001234" }, + { 1.234321234321234e-2, "0.012343" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.234321" }, + { 1.234321234321234e1, "12.343212" }, + { 1.234321234321234e2, "123.432123" }, + { 1.234321234321234e3, "1234.321234" }, + { 1.234321234321234e4, "12343.212343" }, + { 1.234321234321234e5, "123432.123432" }, + { 1.234321234321234e6, "1234321.234321" }, + { 1.234321234321234e7, "12343212.343212" }, + { 1.234321234321234e8, "123432123.432123" }, + { 1.234321234321234e9, "1234321234.321234" }, + { 1.234321234321234e10, "12343212343.2123**" }, + { 1.234321234321234e11, "123432123432.123***" }, + { 1.234321234321234e12, "1234321234321.23****" }, + { 1.234321234321234e13, "12343212343212.3*****" }, + { 1.234321234321234e14, "123432123432123.******" }, + { 1.234321234321234e15, "1234321234321234.000000" }, + { 1.234321234321234e16, "123432123432123**.000000" }, + { 1.234321234321234e17, "123432123432123***.000000" }, + { 1.234321234321234e18, "123432123432123****.000000" }, + { 1.234321234321234e19, "123432123432123*****.000000" }, + { 1.234321234321234e20, "123432123432123******.000000" }, + { 1.234321234321234e21, "123432123432123*******.000000" }, + { 1.234321234321234e22, "123432123432123********.000000" }, + { 1.234321234321234e23, "123432123432123*********.000000" }, + { 1.234321234321234e24, "123432123432123**********.000000" }, + { 1.234321234321234e25, "123432123432123***********.000000" }, + { 1.234321234321234e26, "123432123432123************.000000" }, + { 1.234321234321234e27, "123432123432123*************.000000" }, + { 1.234321234321234e28, "123432123432123**************.000000" }, + { 1.234321234321234e29, "123432123432123***************.000000" }, + { 1.234321234321234e30, "123432123432123****************.000000" }, + { 1.234321234321234e31, "123432123432123*****************.000000" }, + { 1.234321234321234e32, "123432123432123******************.000000" }, + { 1.234321234321234e33, "123432123432123*******************.000000" }, + { 1.234321234321234e34, "123432123432123********************.000000" }, + { 1.234321234321234e35, "123432123432123*********************.000000" }, + { 1.234321234321234e36, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[100]; - int retval = - my_snprintf (result, sizeof (result), "%f", data[k].value); - ASSERT (strmatch (data[k].string, result)); - ASSERT (retval == strlen (result)); + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%f", data[k].value); + ASSERT (strmatch (data[k].string, result)); + ASSERT (retval == strlen (result)); } } @@ -912,7 +912,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%f %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -921,7 +921,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -930,8 +930,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -996,7 +996,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1005,8 +1005,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%050f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1053,89 +1053,89 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "0.000000" }, - { 1.234321234321234e-36L, "0.000000" }, - { 1.234321234321234e-35L, "0.000000" }, - { 1.234321234321234e-34L, "0.000000" }, - { 1.234321234321234e-33L, "0.000000" }, - { 1.234321234321234e-32L, "0.000000" }, - { 1.234321234321234e-31L, "0.000000" }, - { 1.234321234321234e-30L, "0.000000" }, - { 1.234321234321234e-29L, "0.000000" }, - { 1.234321234321234e-28L, "0.000000" }, - { 1.234321234321234e-27L, "0.000000" }, - { 1.234321234321234e-26L, "0.000000" }, - { 1.234321234321234e-25L, "0.000000" }, - { 1.234321234321234e-24L, "0.000000" }, - { 1.234321234321234e-23L, "0.000000" }, - { 1.234321234321234e-22L, "0.000000" }, - { 1.234321234321234e-21L, "0.000000" }, - { 1.234321234321234e-20L, "0.000000" }, - { 1.234321234321234e-19L, "0.000000" }, - { 1.234321234321234e-18L, "0.000000" }, - { 1.234321234321234e-17L, "0.000000" }, - { 1.234321234321234e-16L, "0.000000" }, - { 1.234321234321234e-15L, "0.000000" }, - { 1.234321234321234e-14L, "0.000000" }, - { 1.234321234321234e-13L, "0.000000" }, - { 1.234321234321234e-12L, "0.000000" }, - { 1.234321234321234e-11L, "0.000000" }, - { 1.234321234321234e-10L, "0.000000" }, - { 1.234321234321234e-9L, "0.000000" }, - { 1.234321234321234e-8L, "0.000000" }, - { 1.234321234321234e-7L, "0.000000" }, - { 1.234321234321234e-6L, "0.000001" }, - { 1.234321234321234e-5L, "0.000012" }, - { 1.234321234321234e-4L, "0.000123" }, - { 1.234321234321234e-3L, "0.001234" }, - { 1.234321234321234e-2L, "0.012343" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.234321" }, - { 1.234321234321234e1L, "12.343212" }, - { 1.234321234321234e2L, "123.432123" }, - { 1.234321234321234e3L, "1234.321234" }, - { 1.234321234321234e4L, "12343.212343" }, - { 1.234321234321234e5L, "123432.123432" }, - { 1.234321234321234e6L, "1234321.234321" }, - { 1.234321234321234e7L, "12343212.343212" }, - { 1.234321234321234e8L, "123432123.432123" }, - { 1.234321234321234e9L, "1234321234.321234" }, - { 1.234321234321234e10L, "12343212343.2123**" }, - { 1.234321234321234e11L, "123432123432.123***" }, - { 1.234321234321234e12L, "1234321234321.23****" }, - { 1.234321234321234e13L, "12343212343212.3*****" }, - { 1.234321234321234e14L, "123432123432123.******" }, - { 1.234321234321234e15L, "1234321234321234.000000" }, - { 1.234321234321234e16L, "123432123432123**.000000" }, - { 1.234321234321234e17L, "123432123432123***.000000" }, - { 1.234321234321234e18L, "123432123432123****.000000" }, - { 1.234321234321234e19L, "123432123432123*****.000000" }, - { 1.234321234321234e20L, "123432123432123******.000000" }, - { 1.234321234321234e21L, "123432123432123*******.000000" }, - { 1.234321234321234e22L, "123432123432123********.000000" }, - { 1.234321234321234e23L, "123432123432123*********.000000" }, - { 1.234321234321234e24L, "123432123432123**********.000000" }, - { 1.234321234321234e25L, "123432123432123***********.000000" }, - { 1.234321234321234e26L, "123432123432123************.000000" }, - { 1.234321234321234e27L, "123432123432123*************.000000" }, - { 1.234321234321234e28L, "123432123432123**************.000000" }, - { 1.234321234321234e29L, "123432123432123***************.000000" }, - { 1.234321234321234e30L, "123432123432123****************.000000" }, - { 1.234321234321234e31L, "123432123432123*****************.000000" }, - { 1.234321234321234e32L, "123432123432123******************.000000" }, - { 1.234321234321234e33L, "123432123432123*******************.000000" }, - { 1.234321234321234e34L, "123432123432123********************.000000" }, - { 1.234321234321234e35L, "123432123432123*********************.000000" }, - { 1.234321234321234e36L, "123432123432123**********************.000000" } + { 1.234321234321234e-37L, "0.000000" }, + { 1.234321234321234e-36L, "0.000000" }, + { 1.234321234321234e-35L, "0.000000" }, + { 1.234321234321234e-34L, "0.000000" }, + { 1.234321234321234e-33L, "0.000000" }, + { 1.234321234321234e-32L, "0.000000" }, + { 1.234321234321234e-31L, "0.000000" }, + { 1.234321234321234e-30L, "0.000000" }, + { 1.234321234321234e-29L, "0.000000" }, + { 1.234321234321234e-28L, "0.000000" }, + { 1.234321234321234e-27L, "0.000000" }, + { 1.234321234321234e-26L, "0.000000" }, + { 1.234321234321234e-25L, "0.000000" }, + { 1.234321234321234e-24L, "0.000000" }, + { 1.234321234321234e-23L, "0.000000" }, + { 1.234321234321234e-22L, "0.000000" }, + { 1.234321234321234e-21L, "0.000000" }, + { 1.234321234321234e-20L, "0.000000" }, + { 1.234321234321234e-19L, "0.000000" }, + { 1.234321234321234e-18L, "0.000000" }, + { 1.234321234321234e-17L, "0.000000" }, + { 1.234321234321234e-16L, "0.000000" }, + { 1.234321234321234e-15L, "0.000000" }, + { 1.234321234321234e-14L, "0.000000" }, + { 1.234321234321234e-13L, "0.000000" }, + { 1.234321234321234e-12L, "0.000000" }, + { 1.234321234321234e-11L, "0.000000" }, + { 1.234321234321234e-10L, "0.000000" }, + { 1.234321234321234e-9L, "0.000000" }, + { 1.234321234321234e-8L, "0.000000" }, + { 1.234321234321234e-7L, "0.000000" }, + { 1.234321234321234e-6L, "0.000001" }, + { 1.234321234321234e-5L, "0.000012" }, + { 1.234321234321234e-4L, "0.000123" }, + { 1.234321234321234e-3L, "0.001234" }, + { 1.234321234321234e-2L, "0.012343" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.234321" }, + { 1.234321234321234e1L, "12.343212" }, + { 1.234321234321234e2L, "123.432123" }, + { 1.234321234321234e3L, "1234.321234" }, + { 1.234321234321234e4L, "12343.212343" }, + { 1.234321234321234e5L, "123432.123432" }, + { 1.234321234321234e6L, "1234321.234321" }, + { 1.234321234321234e7L, "12343212.343212" }, + { 1.234321234321234e8L, "123432123.432123" }, + { 1.234321234321234e9L, "1234321234.321234" }, + { 1.234321234321234e10L, "12343212343.2123**" }, + { 1.234321234321234e11L, "123432123432.123***" }, + { 1.234321234321234e12L, "1234321234321.23****" }, + { 1.234321234321234e13L, "12343212343212.3*****" }, + { 1.234321234321234e14L, "123432123432123.******" }, + { 1.234321234321234e15L, "1234321234321234.000000" }, + { 1.234321234321234e16L, "123432123432123**.000000" }, + { 1.234321234321234e17L, "123432123432123***.000000" }, + { 1.234321234321234e18L, "123432123432123****.000000" }, + { 1.234321234321234e19L, "123432123432123*****.000000" }, + { 1.234321234321234e20L, "123432123432123******.000000" }, + { 1.234321234321234e21L, "123432123432123*******.000000" }, + { 1.234321234321234e22L, "123432123432123********.000000" }, + { 1.234321234321234e23L, "123432123432123*********.000000" }, + { 1.234321234321234e24L, "123432123432123**********.000000" }, + { 1.234321234321234e25L, "123432123432123***********.000000" }, + { 1.234321234321234e26L, "123432123432123************.000000" }, + { 1.234321234321234e27L, "123432123432123*************.000000" }, + { 1.234321234321234e28L, "123432123432123**************.000000" }, + { 1.234321234321234e29L, "123432123432123***************.000000" }, + { 1.234321234321234e30L, "123432123432123****************.000000" }, + { 1.234321234321234e31L, "123432123432123*****************.000000" }, + { 1.234321234321234e32L, "123432123432123******************.000000" }, + { 1.234321234321234e33L, "123432123432123*******************.000000" }, + { 1.234321234321234e34L, "123432123432123********************.000000" }, + { 1.234321234321234e35L, "123432123432123*********************.000000" }, + { 1.234321234321234e36L, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[100]; - int retval = - my_snprintf (result, sizeof (result), "%Lf", data[k].value); - ASSERT (strmatch (data[k].string, result)); - ASSERT (retval == strlen (result)); + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lf", data[k].value); + ASSERT (strmatch (data[k].string, result)); + ASSERT (retval == strlen (result)); } } @@ -1169,7 +1169,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1178,7 +1178,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1187,8 +1187,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -1199,8 +1199,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -1211,8 +1211,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -1229,8 +1229,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -1240,8 +1240,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -1251,8 +1251,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -1262,8 +1262,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -1273,8 +1273,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -1340,7 +1340,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1349,8 +1349,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1426,7 +1426,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%F %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1435,7 +1435,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1444,8 +1444,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%F %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1462,7 +1462,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1536,7 +1536,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%LF %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1545,7 +1545,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1554,8 +1554,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%LF %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1572,7 +1572,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1607,7 +1607,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", 12.75, 33, 44, 55); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1616,104 +1616,104 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", 1234567.0, 33, 44, 55); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.234321e-37" }, - { 1.234321234321234e-36, "1.234321e-36" }, - { 1.234321234321234e-35, "1.234321e-35" }, - { 1.234321234321234e-34, "1.234321e-34" }, - { 1.234321234321234e-33, "1.234321e-33" }, - { 1.234321234321234e-32, "1.234321e-32" }, - { 1.234321234321234e-31, "1.234321e-31" }, - { 1.234321234321234e-30, "1.234321e-30" }, - { 1.234321234321234e-29, "1.234321e-29" }, - { 1.234321234321234e-28, "1.234321e-28" }, - { 1.234321234321234e-27, "1.234321e-27" }, - { 1.234321234321234e-26, "1.234321e-26" }, - { 1.234321234321234e-25, "1.234321e-25" }, - { 1.234321234321234e-24, "1.234321e-24" }, - { 1.234321234321234e-23, "1.234321e-23" }, - { 1.234321234321234e-22, "1.234321e-22" }, - { 1.234321234321234e-21, "1.234321e-21" }, - { 1.234321234321234e-20, "1.234321e-20" }, - { 1.234321234321234e-19, "1.234321e-19" }, - { 1.234321234321234e-18, "1.234321e-18" }, - { 1.234321234321234e-17, "1.234321e-17" }, - { 1.234321234321234e-16, "1.234321e-16" }, - { 1.234321234321234e-15, "1.234321e-15" }, - { 1.234321234321234e-14, "1.234321e-14" }, - { 1.234321234321234e-13, "1.234321e-13" }, - { 1.234321234321234e-12, "1.234321e-12" }, - { 1.234321234321234e-11, "1.234321e-11" }, - { 1.234321234321234e-10, "1.234321e-10" }, - { 1.234321234321234e-9, "1.234321e-09" }, - { 1.234321234321234e-8, "1.234321e-08" }, - { 1.234321234321234e-7, "1.234321e-07" }, - { 1.234321234321234e-6, "1.234321e-06" }, - { 1.234321234321234e-5, "1.234321e-05" }, - { 1.234321234321234e-4, "1.234321e-04" }, - { 1.234321234321234e-3, "1.234321e-03" }, - { 1.234321234321234e-2, "1.234321e-02" }, - { 1.234321234321234e-1, "1.234321e-01" }, - { 1.234321234321234, "1.234321e+00" }, - { 1.234321234321234e1, "1.234321e+01" }, - { 1.234321234321234e2, "1.234321e+02" }, - { 1.234321234321234e3, "1.234321e+03" }, - { 1.234321234321234e4, "1.234321e+04" }, - { 1.234321234321234e5, "1.234321e+05" }, - { 1.234321234321234e6, "1.234321e+06" }, - { 1.234321234321234e7, "1.234321e+07" }, - { 1.234321234321234e8, "1.234321e+08" }, - { 1.234321234321234e9, "1.234321e+09" }, - { 1.234321234321234e10, "1.234321e+10" }, - { 1.234321234321234e11, "1.234321e+11" }, - { 1.234321234321234e12, "1.234321e+12" }, - { 1.234321234321234e13, "1.234321e+13" }, - { 1.234321234321234e14, "1.234321e+14" }, - { 1.234321234321234e15, "1.234321e+15" }, - { 1.234321234321234e16, "1.234321e+16" }, - { 1.234321234321234e17, "1.234321e+17" }, - { 1.234321234321234e18, "1.234321e+18" }, - { 1.234321234321234e19, "1.234321e+19" }, - { 1.234321234321234e20, "1.234321e+20" }, - { 1.234321234321234e21, "1.234321e+21" }, - { 1.234321234321234e22, "1.234321e+22" }, - { 1.234321234321234e23, "1.234321e+23" }, - { 1.234321234321234e24, "1.234321e+24" }, - { 1.234321234321234e25, "1.234321e+25" }, - { 1.234321234321234e26, "1.234321e+26" }, - { 1.234321234321234e27, "1.234321e+27" }, - { 1.234321234321234e28, "1.234321e+28" }, - { 1.234321234321234e29, "1.234321e+29" }, - { 1.234321234321234e30, "1.234321e+30" }, - { 1.234321234321234e31, "1.234321e+31" }, - { 1.234321234321234e32, "1.234321e+32" }, - { 1.234321234321234e33, "1.234321e+33" }, - { 1.234321234321234e34, "1.234321e+34" }, - { 1.234321234321234e35, "1.234321e+35" }, - { 1.234321234321234e36, "1.234321e+36" } + { 1.234321234321234e-37, "1.234321e-37" }, + { 1.234321234321234e-36, "1.234321e-36" }, + { 1.234321234321234e-35, "1.234321e-35" }, + { 1.234321234321234e-34, "1.234321e-34" }, + { 1.234321234321234e-33, "1.234321e-33" }, + { 1.234321234321234e-32, "1.234321e-32" }, + { 1.234321234321234e-31, "1.234321e-31" }, + { 1.234321234321234e-30, "1.234321e-30" }, + { 1.234321234321234e-29, "1.234321e-29" }, + { 1.234321234321234e-28, "1.234321e-28" }, + { 1.234321234321234e-27, "1.234321e-27" }, + { 1.234321234321234e-26, "1.234321e-26" }, + { 1.234321234321234e-25, "1.234321e-25" }, + { 1.234321234321234e-24, "1.234321e-24" }, + { 1.234321234321234e-23, "1.234321e-23" }, + { 1.234321234321234e-22, "1.234321e-22" }, + { 1.234321234321234e-21, "1.234321e-21" }, + { 1.234321234321234e-20, "1.234321e-20" }, + { 1.234321234321234e-19, "1.234321e-19" }, + { 1.234321234321234e-18, "1.234321e-18" }, + { 1.234321234321234e-17, "1.234321e-17" }, + { 1.234321234321234e-16, "1.234321e-16" }, + { 1.234321234321234e-15, "1.234321e-15" }, + { 1.234321234321234e-14, "1.234321e-14" }, + { 1.234321234321234e-13, "1.234321e-13" }, + { 1.234321234321234e-12, "1.234321e-12" }, + { 1.234321234321234e-11, "1.234321e-11" }, + { 1.234321234321234e-10, "1.234321e-10" }, + { 1.234321234321234e-9, "1.234321e-09" }, + { 1.234321234321234e-8, "1.234321e-08" }, + { 1.234321234321234e-7, "1.234321e-07" }, + { 1.234321234321234e-6, "1.234321e-06" }, + { 1.234321234321234e-5, "1.234321e-05" }, + { 1.234321234321234e-4, "1.234321e-04" }, + { 1.234321234321234e-3, "1.234321e-03" }, + { 1.234321234321234e-2, "1.234321e-02" }, + { 1.234321234321234e-1, "1.234321e-01" }, + { 1.234321234321234, "1.234321e+00" }, + { 1.234321234321234e1, "1.234321e+01" }, + { 1.234321234321234e2, "1.234321e+02" }, + { 1.234321234321234e3, "1.234321e+03" }, + { 1.234321234321234e4, "1.234321e+04" }, + { 1.234321234321234e5, "1.234321e+05" }, + { 1.234321234321234e6, "1.234321e+06" }, + { 1.234321234321234e7, "1.234321e+07" }, + { 1.234321234321234e8, "1.234321e+08" }, + { 1.234321234321234e9, "1.234321e+09" }, + { 1.234321234321234e10, "1.234321e+10" }, + { 1.234321234321234e11, "1.234321e+11" }, + { 1.234321234321234e12, "1.234321e+12" }, + { 1.234321234321234e13, "1.234321e+13" }, + { 1.234321234321234e14, "1.234321e+14" }, + { 1.234321234321234e15, "1.234321e+15" }, + { 1.234321234321234e16, "1.234321e+16" }, + { 1.234321234321234e17, "1.234321e+17" }, + { 1.234321234321234e18, "1.234321e+18" }, + { 1.234321234321234e19, "1.234321e+19" }, + { 1.234321234321234e20, "1.234321e+20" }, + { 1.234321234321234e21, "1.234321e+21" }, + { 1.234321234321234e22, "1.234321e+22" }, + { 1.234321234321234e23, "1.234321e+23" }, + { 1.234321234321234e24, "1.234321e+24" }, + { 1.234321234321234e25, "1.234321e+25" }, + { 1.234321234321234e26, "1.234321e+26" }, + { 1.234321234321234e27, "1.234321e+27" }, + { 1.234321234321234e28, "1.234321e+28" }, + { 1.234321234321234e29, "1.234321e+29" }, + { 1.234321234321234e30, "1.234321e+30" }, + { 1.234321234321234e31, "1.234321e+31" }, + { 1.234321234321234e32, "1.234321e+32" }, + { 1.234321234321234e33, "1.234321e+33" }, + { 1.234321234321234e34, "1.234321e+34" }, + { 1.234321234321234e35, "1.234321e+35" }, + { 1.234321234321234e36, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[100]; - int retval = - my_snprintf (result, sizeof (result), "%e", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%e", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -1722,7 +1722,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", -0.03125, 33, 44, 55); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); } @@ -1731,7 +1731,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", 0.0, 33, 44, 55); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1741,7 +1741,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) my_snprintf (result, sizeof (result), "%e %d", -zerod, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1750,7 +1750,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1759,7 +1759,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1768,8 +1768,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1778,7 +1778,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%15e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1787,7 +1787,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%-15e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1796,7 +1796,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%+e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1805,7 +1805,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "% e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1814,7 +1814,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1823,7 +1823,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#.e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1832,7 +1832,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#.e %d", 9.75, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1841,7 +1841,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015e %d", 1234.0, 33, 44, 55); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1850,7 +1850,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1859,8 +1859,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%050e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1869,7 +1869,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.e %d", 1234.0, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1878,7 +1878,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.4e %d", 999.951, 33, 44, 55); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (retval == strlen (result)); } @@ -1887,7 +1887,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.4e %d", 999.996, 33, 44, 55); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1896,7 +1896,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", 12.75L, 33, 44, 55); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1905,104 +1905,104 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", 1234567.0L, 33, 44, 55); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.234321e-37" }, - { 1.234321234321234e-36L, "1.234321e-36" }, - { 1.234321234321234e-35L, "1.234321e-35" }, - { 1.234321234321234e-34L, "1.234321e-34" }, - { 1.234321234321234e-33L, "1.234321e-33" }, - { 1.234321234321234e-32L, "1.234321e-32" }, - { 1.234321234321234e-31L, "1.234321e-31" }, - { 1.234321234321234e-30L, "1.234321e-30" }, - { 1.234321234321234e-29L, "1.234321e-29" }, - { 1.234321234321234e-28L, "1.234321e-28" }, - { 1.234321234321234e-27L, "1.234321e-27" }, - { 1.234321234321234e-26L, "1.234321e-26" }, - { 1.234321234321234e-25L, "1.234321e-25" }, - { 1.234321234321234e-24L, "1.234321e-24" }, - { 1.234321234321234e-23L, "1.234321e-23" }, - { 1.234321234321234e-22L, "1.234321e-22" }, - { 1.234321234321234e-21L, "1.234321e-21" }, - { 1.234321234321234e-20L, "1.234321e-20" }, - { 1.234321234321234e-19L, "1.234321e-19" }, - { 1.234321234321234e-18L, "1.234321e-18" }, - { 1.234321234321234e-17L, "1.234321e-17" }, - { 1.234321234321234e-16L, "1.234321e-16" }, - { 1.234321234321234e-15L, "1.234321e-15" }, - { 1.234321234321234e-14L, "1.234321e-14" }, - { 1.234321234321234e-13L, "1.234321e-13" }, - { 1.234321234321234e-12L, "1.234321e-12" }, - { 1.234321234321234e-11L, "1.234321e-11" }, - { 1.234321234321234e-10L, "1.234321e-10" }, - { 1.234321234321234e-9L, "1.234321e-09" }, - { 1.234321234321234e-8L, "1.234321e-08" }, - { 1.234321234321234e-7L, "1.234321e-07" }, - { 1.234321234321234e-6L, "1.234321e-06" }, - { 1.234321234321234e-5L, "1.234321e-05" }, - { 1.234321234321234e-4L, "1.234321e-04" }, - { 1.234321234321234e-3L, "1.234321e-03" }, - { 1.234321234321234e-2L, "1.234321e-02" }, - { 1.234321234321234e-1L, "1.234321e-01" }, - { 1.234321234321234L, "1.234321e+00" }, - { 1.234321234321234e1L, "1.234321e+01" }, - { 1.234321234321234e2L, "1.234321e+02" }, - { 1.234321234321234e3L, "1.234321e+03" }, - { 1.234321234321234e4L, "1.234321e+04" }, - { 1.234321234321234e5L, "1.234321e+05" }, - { 1.234321234321234e6L, "1.234321e+06" }, - { 1.234321234321234e7L, "1.234321e+07" }, - { 1.234321234321234e8L, "1.234321e+08" }, - { 1.234321234321234e9L, "1.234321e+09" }, - { 1.234321234321234e10L, "1.234321e+10" }, - { 1.234321234321234e11L, "1.234321e+11" }, - { 1.234321234321234e12L, "1.234321e+12" }, - { 1.234321234321234e13L, "1.234321e+13" }, - { 1.234321234321234e14L, "1.234321e+14" }, - { 1.234321234321234e15L, "1.234321e+15" }, - { 1.234321234321234e16L, "1.234321e+16" }, - { 1.234321234321234e17L, "1.234321e+17" }, - { 1.234321234321234e18L, "1.234321e+18" }, - { 1.234321234321234e19L, "1.234321e+19" }, - { 1.234321234321234e20L, "1.234321e+20" }, - { 1.234321234321234e21L, "1.234321e+21" }, - { 1.234321234321234e22L, "1.234321e+22" }, - { 1.234321234321234e23L, "1.234321e+23" }, - { 1.234321234321234e24L, "1.234321e+24" }, - { 1.234321234321234e25L, "1.234321e+25" }, - { 1.234321234321234e26L, "1.234321e+26" }, - { 1.234321234321234e27L, "1.234321e+27" }, - { 1.234321234321234e28L, "1.234321e+28" }, - { 1.234321234321234e29L, "1.234321e+29" }, - { 1.234321234321234e30L, "1.234321e+30" }, - { 1.234321234321234e31L, "1.234321e+31" }, - { 1.234321234321234e32L, "1.234321e+32" }, - { 1.234321234321234e33L, "1.234321e+33" }, - { 1.234321234321234e34L, "1.234321e+34" }, - { 1.234321234321234e35L, "1.234321e+35" }, - { 1.234321234321234e36L, "1.234321e+36" } + { 1.234321234321234e-37L, "1.234321e-37" }, + { 1.234321234321234e-36L, "1.234321e-36" }, + { 1.234321234321234e-35L, "1.234321e-35" }, + { 1.234321234321234e-34L, "1.234321e-34" }, + { 1.234321234321234e-33L, "1.234321e-33" }, + { 1.234321234321234e-32L, "1.234321e-32" }, + { 1.234321234321234e-31L, "1.234321e-31" }, + { 1.234321234321234e-30L, "1.234321e-30" }, + { 1.234321234321234e-29L, "1.234321e-29" }, + { 1.234321234321234e-28L, "1.234321e-28" }, + { 1.234321234321234e-27L, "1.234321e-27" }, + { 1.234321234321234e-26L, "1.234321e-26" }, + { 1.234321234321234e-25L, "1.234321e-25" }, + { 1.234321234321234e-24L, "1.234321e-24" }, + { 1.234321234321234e-23L, "1.234321e-23" }, + { 1.234321234321234e-22L, "1.234321e-22" }, + { 1.234321234321234e-21L, "1.234321e-21" }, + { 1.234321234321234e-20L, "1.234321e-20" }, + { 1.234321234321234e-19L, "1.234321e-19" }, + { 1.234321234321234e-18L, "1.234321e-18" }, + { 1.234321234321234e-17L, "1.234321e-17" }, + { 1.234321234321234e-16L, "1.234321e-16" }, + { 1.234321234321234e-15L, "1.234321e-15" }, + { 1.234321234321234e-14L, "1.234321e-14" }, + { 1.234321234321234e-13L, "1.234321e-13" }, + { 1.234321234321234e-12L, "1.234321e-12" }, + { 1.234321234321234e-11L, "1.234321e-11" }, + { 1.234321234321234e-10L, "1.234321e-10" }, + { 1.234321234321234e-9L, "1.234321e-09" }, + { 1.234321234321234e-8L, "1.234321e-08" }, + { 1.234321234321234e-7L, "1.234321e-07" }, + { 1.234321234321234e-6L, "1.234321e-06" }, + { 1.234321234321234e-5L, "1.234321e-05" }, + { 1.234321234321234e-4L, "1.234321e-04" }, + { 1.234321234321234e-3L, "1.234321e-03" }, + { 1.234321234321234e-2L, "1.234321e-02" }, + { 1.234321234321234e-1L, "1.234321e-01" }, + { 1.234321234321234L, "1.234321e+00" }, + { 1.234321234321234e1L, "1.234321e+01" }, + { 1.234321234321234e2L, "1.234321e+02" }, + { 1.234321234321234e3L, "1.234321e+03" }, + { 1.234321234321234e4L, "1.234321e+04" }, + { 1.234321234321234e5L, "1.234321e+05" }, + { 1.234321234321234e6L, "1.234321e+06" }, + { 1.234321234321234e7L, "1.234321e+07" }, + { 1.234321234321234e8L, "1.234321e+08" }, + { 1.234321234321234e9L, "1.234321e+09" }, + { 1.234321234321234e10L, "1.234321e+10" }, + { 1.234321234321234e11L, "1.234321e+11" }, + { 1.234321234321234e12L, "1.234321e+12" }, + { 1.234321234321234e13L, "1.234321e+13" }, + { 1.234321234321234e14L, "1.234321e+14" }, + { 1.234321234321234e15L, "1.234321e+15" }, + { 1.234321234321234e16L, "1.234321e+16" }, + { 1.234321234321234e17L, "1.234321e+17" }, + { 1.234321234321234e18L, "1.234321e+18" }, + { 1.234321234321234e19L, "1.234321e+19" }, + { 1.234321234321234e20L, "1.234321e+20" }, + { 1.234321234321234e21L, "1.234321e+21" }, + { 1.234321234321234e22L, "1.234321e+22" }, + { 1.234321234321234e23L, "1.234321e+23" }, + { 1.234321234321234e24L, "1.234321e+24" }, + { 1.234321234321234e25L, "1.234321e+25" }, + { 1.234321234321234e26L, "1.234321e+26" }, + { 1.234321234321234e27L, "1.234321e+27" }, + { 1.234321234321234e28L, "1.234321e+28" }, + { 1.234321234321234e29L, "1.234321e+29" }, + { 1.234321234321234e30L, "1.234321e+30" }, + { 1.234321234321234e31L, "1.234321e+31" }, + { 1.234321234321234e32L, "1.234321e+32" }, + { 1.234321234321234e33L, "1.234321e+33" }, + { 1.234321234321234e34L, "1.234321e+34" }, + { 1.234321234321234e35L, "1.234321e+35" }, + { 1.234321234321234e36L, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[100]; - int retval = - my_snprintf (result, sizeof (result), "%Le", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Le", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -2011,7 +2011,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", -0.03125L, 33, 44, 55); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); } @@ -2020,7 +2020,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", 0.0L, 33, 44, 55); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2030,7 +2030,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) my_snprintf (result, sizeof (result), "%Le %d", minus_zerol, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2039,7 +2039,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2048,7 +2048,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2057,8 +2057,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -2069,8 +2069,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -2081,8 +2081,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -2099,8 +2099,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -2110,8 +2110,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -2121,8 +2121,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -2132,8 +2132,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -2143,8 +2143,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -2154,7 +2154,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%15Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2163,7 +2163,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%-15Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2172,7 +2172,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%+Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2181,7 +2181,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "% Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2190,7 +2190,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2199,7 +2199,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#.Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2208,7 +2208,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#.Le %d", 9.75L, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2217,7 +2217,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015Le %d", 1234.0L, 33, 44, 55); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2226,7 +2226,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2235,8 +2235,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%050Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2245,7 +2245,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.Le %d", 1234.0L, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2254,7 +2254,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.4Le %d", 999.951L, 33, 44, 55); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (retval == strlen (result)); } @@ -2263,7 +2263,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.4Le %d", 999.996L, 33, 44, 55); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2282,105 +2282,105 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%g %d", 1234567.0, 33, 44, 55); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.23432e-37" }, - { 1.234321234321234e-36, "1.23432e-36" }, - { 1.234321234321234e-35, "1.23432e-35" }, - { 1.234321234321234e-34, "1.23432e-34" }, - { 1.234321234321234e-33, "1.23432e-33" }, - { 1.234321234321234e-32, "1.23432e-32" }, - { 1.234321234321234e-31, "1.23432e-31" }, - { 1.234321234321234e-30, "1.23432e-30" }, - { 1.234321234321234e-29, "1.23432e-29" }, - { 1.234321234321234e-28, "1.23432e-28" }, - { 1.234321234321234e-27, "1.23432e-27" }, - { 1.234321234321234e-26, "1.23432e-26" }, - { 1.234321234321234e-25, "1.23432e-25" }, - { 1.234321234321234e-24, "1.23432e-24" }, - { 1.234321234321234e-23, "1.23432e-23" }, - { 1.234321234321234e-22, "1.23432e-22" }, - { 1.234321234321234e-21, "1.23432e-21" }, - { 1.234321234321234e-20, "1.23432e-20" }, - { 1.234321234321234e-19, "1.23432e-19" }, - { 1.234321234321234e-18, "1.23432e-18" }, - { 1.234321234321234e-17, "1.23432e-17" }, - { 1.234321234321234e-16, "1.23432e-16" }, - { 1.234321234321234e-15, "1.23432e-15" }, - { 1.234321234321234e-14, "1.23432e-14" }, - { 1.234321234321234e-13, "1.23432e-13" }, - { 1.234321234321234e-12, "1.23432e-12" }, - { 1.234321234321234e-11, "1.23432e-11" }, - { 1.234321234321234e-10, "1.23432e-10" }, - { 1.234321234321234e-9, "1.23432e-09" }, - { 1.234321234321234e-8, "1.23432e-08" }, - { 1.234321234321234e-7, "1.23432e-07" }, - { 1.234321234321234e-6, "1.23432e-06" }, - { 1.234321234321234e-5, "1.23432e-05" }, - { 1.234321234321234e-4, "0.000123432" }, - { 1.234321234321234e-3, "0.00123432" }, - { 1.234321234321234e-2, "0.0123432" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.23432" }, - { 1.234321234321234e1, "12.3432" }, - { 1.234321234321234e2, "123.432" }, - { 1.234321234321234e3, "1234.32" }, - { 1.234321234321234e4, "12343.2" }, - { 1.234321234321234e5, "123432" }, - { 1.234321234321234e6, "1.23432e+06" }, - { 1.234321234321234e7, "1.23432e+07" }, - { 1.234321234321234e8, "1.23432e+08" }, - { 1.234321234321234e9, "1.23432e+09" }, - { 1.234321234321234e10, "1.23432e+10" }, - { 1.234321234321234e11, "1.23432e+11" }, - { 1.234321234321234e12, "1.23432e+12" }, - { 1.234321234321234e13, "1.23432e+13" }, - { 1.234321234321234e14, "1.23432e+14" }, - { 1.234321234321234e15, "1.23432e+15" }, - { 1.234321234321234e16, "1.23432e+16" }, - { 1.234321234321234e17, "1.23432e+17" }, - { 1.234321234321234e18, "1.23432e+18" }, - { 1.234321234321234e19, "1.23432e+19" }, - { 1.234321234321234e20, "1.23432e+20" }, - { 1.234321234321234e21, "1.23432e+21" }, - { 1.234321234321234e22, "1.23432e+22" }, - { 1.234321234321234e23, "1.23432e+23" }, - { 1.234321234321234e24, "1.23432e+24" }, - { 1.234321234321234e25, "1.23432e+25" }, - { 1.234321234321234e26, "1.23432e+26" }, - { 1.234321234321234e27, "1.23432e+27" }, - { 1.234321234321234e28, "1.23432e+28" }, - { 1.234321234321234e29, "1.23432e+29" }, - { 1.234321234321234e30, "1.23432e+30" }, - { 1.234321234321234e31, "1.23432e+31" }, - { 1.234321234321234e32, "1.23432e+32" }, - { 1.234321234321234e33, "1.23432e+33" }, - { 1.234321234321234e34, "1.23432e+34" }, - { 1.234321234321234e35, "1.23432e+35" }, - { 1.234321234321234e36, "1.23432e+36" } + { 1.234321234321234e-37, "1.23432e-37" }, + { 1.234321234321234e-36, "1.23432e-36" }, + { 1.234321234321234e-35, "1.23432e-35" }, + { 1.234321234321234e-34, "1.23432e-34" }, + { 1.234321234321234e-33, "1.23432e-33" }, + { 1.234321234321234e-32, "1.23432e-32" }, + { 1.234321234321234e-31, "1.23432e-31" }, + { 1.234321234321234e-30, "1.23432e-30" }, + { 1.234321234321234e-29, "1.23432e-29" }, + { 1.234321234321234e-28, "1.23432e-28" }, + { 1.234321234321234e-27, "1.23432e-27" }, + { 1.234321234321234e-26, "1.23432e-26" }, + { 1.234321234321234e-25, "1.23432e-25" }, + { 1.234321234321234e-24, "1.23432e-24" }, + { 1.234321234321234e-23, "1.23432e-23" }, + { 1.234321234321234e-22, "1.23432e-22" }, + { 1.234321234321234e-21, "1.23432e-21" }, + { 1.234321234321234e-20, "1.23432e-20" }, + { 1.234321234321234e-19, "1.23432e-19" }, + { 1.234321234321234e-18, "1.23432e-18" }, + { 1.234321234321234e-17, "1.23432e-17" }, + { 1.234321234321234e-16, "1.23432e-16" }, + { 1.234321234321234e-15, "1.23432e-15" }, + { 1.234321234321234e-14, "1.23432e-14" }, + { 1.234321234321234e-13, "1.23432e-13" }, + { 1.234321234321234e-12, "1.23432e-12" }, + { 1.234321234321234e-11, "1.23432e-11" }, + { 1.234321234321234e-10, "1.23432e-10" }, + { 1.234321234321234e-9, "1.23432e-09" }, + { 1.234321234321234e-8, "1.23432e-08" }, + { 1.234321234321234e-7, "1.23432e-07" }, + { 1.234321234321234e-6, "1.23432e-06" }, + { 1.234321234321234e-5, "1.23432e-05" }, + { 1.234321234321234e-4, "0.000123432" }, + { 1.234321234321234e-3, "0.00123432" }, + { 1.234321234321234e-2, "0.0123432" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.23432" }, + { 1.234321234321234e1, "12.3432" }, + { 1.234321234321234e2, "123.432" }, + { 1.234321234321234e3, "1234.32" }, + { 1.234321234321234e4, "12343.2" }, + { 1.234321234321234e5, "123432" }, + { 1.234321234321234e6, "1.23432e+06" }, + { 1.234321234321234e7, "1.23432e+07" }, + { 1.234321234321234e8, "1.23432e+08" }, + { 1.234321234321234e9, "1.23432e+09" }, + { 1.234321234321234e10, "1.23432e+10" }, + { 1.234321234321234e11, "1.23432e+11" }, + { 1.234321234321234e12, "1.23432e+12" }, + { 1.234321234321234e13, "1.23432e+13" }, + { 1.234321234321234e14, "1.23432e+14" }, + { 1.234321234321234e15, "1.23432e+15" }, + { 1.234321234321234e16, "1.23432e+16" }, + { 1.234321234321234e17, "1.23432e+17" }, + { 1.234321234321234e18, "1.23432e+18" }, + { 1.234321234321234e19, "1.23432e+19" }, + { 1.234321234321234e20, "1.23432e+20" }, + { 1.234321234321234e21, "1.23432e+21" }, + { 1.234321234321234e22, "1.23432e+22" }, + { 1.234321234321234e23, "1.23432e+23" }, + { 1.234321234321234e24, "1.23432e+24" }, + { 1.234321234321234e25, "1.23432e+25" }, + { 1.234321234321234e26, "1.23432e+26" }, + { 1.234321234321234e27, "1.23432e+27" }, + { 1.234321234321234e28, "1.23432e+28" }, + { 1.234321234321234e29, "1.23432e+29" }, + { 1.234321234321234e30, "1.23432e+30" }, + { 1.234321234321234e31, "1.23432e+31" }, + { 1.234321234321234e32, "1.23432e+32" }, + { 1.234321234321234e33, "1.23432e+33" }, + { 1.234321234321234e34, "1.23432e+34" }, + { 1.234321234321234e35, "1.23432e+35" }, + { 1.234321234321234e36, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[100]; - int retval = - my_snprintf (result, sizeof (result), "%g", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%g", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -2414,7 +2414,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%g %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2423,7 +2423,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2432,8 +2432,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2490,7 +2490,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#.g %d", 9.75, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2507,7 +2507,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2516,8 +2516,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%050g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2526,7 +2526,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.g %d", 1234.0, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2559,105 +2559,105 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", 1234567.0L, 33, 44, 55); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.23432e-37" }, - { 1.234321234321234e-36L, "1.23432e-36" }, - { 1.234321234321234e-35L, "1.23432e-35" }, - { 1.234321234321234e-34L, "1.23432e-34" }, - { 1.234321234321234e-33L, "1.23432e-33" }, - { 1.234321234321234e-32L, "1.23432e-32" }, - { 1.234321234321234e-31L, "1.23432e-31" }, - { 1.234321234321234e-30L, "1.23432e-30" }, - { 1.234321234321234e-29L, "1.23432e-29" }, - { 1.234321234321234e-28L, "1.23432e-28" }, - { 1.234321234321234e-27L, "1.23432e-27" }, - { 1.234321234321234e-26L, "1.23432e-26" }, - { 1.234321234321234e-25L, "1.23432e-25" }, - { 1.234321234321234e-24L, "1.23432e-24" }, - { 1.234321234321234e-23L, "1.23432e-23" }, - { 1.234321234321234e-22L, "1.23432e-22" }, - { 1.234321234321234e-21L, "1.23432e-21" }, - { 1.234321234321234e-20L, "1.23432e-20" }, - { 1.234321234321234e-19L, "1.23432e-19" }, - { 1.234321234321234e-18L, "1.23432e-18" }, - { 1.234321234321234e-17L, "1.23432e-17" }, - { 1.234321234321234e-16L, "1.23432e-16" }, - { 1.234321234321234e-15L, "1.23432e-15" }, - { 1.234321234321234e-14L, "1.23432e-14" }, - { 1.234321234321234e-13L, "1.23432e-13" }, - { 1.234321234321234e-12L, "1.23432e-12" }, - { 1.234321234321234e-11L, "1.23432e-11" }, - { 1.234321234321234e-10L, "1.23432e-10" }, - { 1.234321234321234e-9L, "1.23432e-09" }, - { 1.234321234321234e-8L, "1.23432e-08" }, - { 1.234321234321234e-7L, "1.23432e-07" }, - { 1.234321234321234e-6L, "1.23432e-06" }, - { 1.234321234321234e-5L, "1.23432e-05" }, - { 1.234321234321234e-4L, "0.000123432" }, - { 1.234321234321234e-3L, "0.00123432" }, - { 1.234321234321234e-2L, "0.0123432" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.23432" }, - { 1.234321234321234e1L, "12.3432" }, - { 1.234321234321234e2L, "123.432" }, - { 1.234321234321234e3L, "1234.32" }, - { 1.234321234321234e4L, "12343.2" }, - { 1.234321234321234e5L, "123432" }, - { 1.234321234321234e6L, "1.23432e+06" }, - { 1.234321234321234e7L, "1.23432e+07" }, - { 1.234321234321234e8L, "1.23432e+08" }, - { 1.234321234321234e9L, "1.23432e+09" }, - { 1.234321234321234e10L, "1.23432e+10" }, - { 1.234321234321234e11L, "1.23432e+11" }, - { 1.234321234321234e12L, "1.23432e+12" }, - { 1.234321234321234e13L, "1.23432e+13" }, - { 1.234321234321234e14L, "1.23432e+14" }, - { 1.234321234321234e15L, "1.23432e+15" }, - { 1.234321234321234e16L, "1.23432e+16" }, - { 1.234321234321234e17L, "1.23432e+17" }, - { 1.234321234321234e18L, "1.23432e+18" }, - { 1.234321234321234e19L, "1.23432e+19" }, - { 1.234321234321234e20L, "1.23432e+20" }, - { 1.234321234321234e21L, "1.23432e+21" }, - { 1.234321234321234e22L, "1.23432e+22" }, - { 1.234321234321234e23L, "1.23432e+23" }, - { 1.234321234321234e24L, "1.23432e+24" }, - { 1.234321234321234e25L, "1.23432e+25" }, - { 1.234321234321234e26L, "1.23432e+26" }, - { 1.234321234321234e27L, "1.23432e+27" }, - { 1.234321234321234e28L, "1.23432e+28" }, - { 1.234321234321234e29L, "1.23432e+29" }, - { 1.234321234321234e30L, "1.23432e+30" }, - { 1.234321234321234e31L, "1.23432e+31" }, - { 1.234321234321234e32L, "1.23432e+32" }, - { 1.234321234321234e33L, "1.23432e+33" }, - { 1.234321234321234e34L, "1.23432e+34" }, - { 1.234321234321234e35L, "1.23432e+35" }, - { 1.234321234321234e36L, "1.23432e+36" } + { 1.234321234321234e-37L, "1.23432e-37" }, + { 1.234321234321234e-36L, "1.23432e-36" }, + { 1.234321234321234e-35L, "1.23432e-35" }, + { 1.234321234321234e-34L, "1.23432e-34" }, + { 1.234321234321234e-33L, "1.23432e-33" }, + { 1.234321234321234e-32L, "1.23432e-32" }, + { 1.234321234321234e-31L, "1.23432e-31" }, + { 1.234321234321234e-30L, "1.23432e-30" }, + { 1.234321234321234e-29L, "1.23432e-29" }, + { 1.234321234321234e-28L, "1.23432e-28" }, + { 1.234321234321234e-27L, "1.23432e-27" }, + { 1.234321234321234e-26L, "1.23432e-26" }, + { 1.234321234321234e-25L, "1.23432e-25" }, + { 1.234321234321234e-24L, "1.23432e-24" }, + { 1.234321234321234e-23L, "1.23432e-23" }, + { 1.234321234321234e-22L, "1.23432e-22" }, + { 1.234321234321234e-21L, "1.23432e-21" }, + { 1.234321234321234e-20L, "1.23432e-20" }, + { 1.234321234321234e-19L, "1.23432e-19" }, + { 1.234321234321234e-18L, "1.23432e-18" }, + { 1.234321234321234e-17L, "1.23432e-17" }, + { 1.234321234321234e-16L, "1.23432e-16" }, + { 1.234321234321234e-15L, "1.23432e-15" }, + { 1.234321234321234e-14L, "1.23432e-14" }, + { 1.234321234321234e-13L, "1.23432e-13" }, + { 1.234321234321234e-12L, "1.23432e-12" }, + { 1.234321234321234e-11L, "1.23432e-11" }, + { 1.234321234321234e-10L, "1.23432e-10" }, + { 1.234321234321234e-9L, "1.23432e-09" }, + { 1.234321234321234e-8L, "1.23432e-08" }, + { 1.234321234321234e-7L, "1.23432e-07" }, + { 1.234321234321234e-6L, "1.23432e-06" }, + { 1.234321234321234e-5L, "1.23432e-05" }, + { 1.234321234321234e-4L, "0.000123432" }, + { 1.234321234321234e-3L, "0.00123432" }, + { 1.234321234321234e-2L, "0.0123432" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.23432" }, + { 1.234321234321234e1L, "12.3432" }, + { 1.234321234321234e2L, "123.432" }, + { 1.234321234321234e3L, "1234.32" }, + { 1.234321234321234e4L, "12343.2" }, + { 1.234321234321234e5L, "123432" }, + { 1.234321234321234e6L, "1.23432e+06" }, + { 1.234321234321234e7L, "1.23432e+07" }, + { 1.234321234321234e8L, "1.23432e+08" }, + { 1.234321234321234e9L, "1.23432e+09" }, + { 1.234321234321234e10L, "1.23432e+10" }, + { 1.234321234321234e11L, "1.23432e+11" }, + { 1.234321234321234e12L, "1.23432e+12" }, + { 1.234321234321234e13L, "1.23432e+13" }, + { 1.234321234321234e14L, "1.23432e+14" }, + { 1.234321234321234e15L, "1.23432e+15" }, + { 1.234321234321234e16L, "1.23432e+16" }, + { 1.234321234321234e17L, "1.23432e+17" }, + { 1.234321234321234e18L, "1.23432e+18" }, + { 1.234321234321234e19L, "1.23432e+19" }, + { 1.234321234321234e20L, "1.23432e+20" }, + { 1.234321234321234e21L, "1.23432e+21" }, + { 1.234321234321234e22L, "1.23432e+22" }, + { 1.234321234321234e23L, "1.23432e+23" }, + { 1.234321234321234e24L, "1.23432e+24" }, + { 1.234321234321234e25L, "1.23432e+25" }, + { 1.234321234321234e26L, "1.23432e+26" }, + { 1.234321234321234e27L, "1.23432e+27" }, + { 1.234321234321234e28L, "1.23432e+28" }, + { 1.234321234321234e29L, "1.23432e+29" }, + { 1.234321234321234e30L, "1.23432e+30" }, + { 1.234321234321234e31L, "1.23432e+31" }, + { 1.234321234321234e32L, "1.23432e+32" }, + { 1.234321234321234e33L, "1.23432e+33" }, + { 1.234321234321234e34L, "1.23432e+34" }, + { 1.234321234321234e35L, "1.23432e+35" }, + { 1.234321234321234e36L, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[100]; - int retval = - my_snprintf (result, sizeof (result), "%Lg", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%Lg", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -2691,7 +2691,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2700,7 +2700,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2709,8 +2709,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -2721,8 +2721,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -2733,8 +2733,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -2751,8 +2751,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -2762,8 +2762,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -2773,8 +2773,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -2784,8 +2784,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -2795,8 +2795,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -2854,7 +2854,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%#.Lg %d", 9.75L, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2871,7 +2871,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%015Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2880,8 +2880,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2890,7 +2890,7 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) int retval = my_snprintf (result, sizeof (result), "%.Lg %d", 1234.0L, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -3075,17 +3075,17 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) for (i = 1; i <= 8; i++) { - char *block; - char result[5000]; - int retval; - - block = (char *) malloc (i); - memcpy (block, "abcdefgh", i); - retval = my_snprintf (result, sizeof (result), "%.*s", (int) i, block); - ASSERT (memcmp (result, block, i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (retval == strlen (result)); - free (block); + char *block; + char result[5000]; + int retval; + + block = (char *) malloc (i); + memcpy (block, "abcdefgh", i); + retval = my_snprintf (result, sizeof (result), "%.*s", (int) i, block); + ASSERT (memcmp (result, block, i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (retval == strlen (result)); + free (block); } } #if HAVE_WCHAR_T @@ -3094,19 +3094,19 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) for (i = 1; i <= 8; i++) { - wchar_t *block; - size_t j; - char result[5000]; - int retval; - - block = (wchar_t *) malloc (i * sizeof (wchar_t)); - for (j = 0; j < i; j++) - block[j] = "abcdefgh"[j]; - retval = my_snprintf (result, sizeof (result), "%.*ls", (int) i, block); - ASSERT (memcmp (result, "abcdefgh", i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (retval == strlen (result)); - free (block); + wchar_t *block; + size_t j; + char result[5000]; + int retval; + + block = (wchar_t *) malloc (i * sizeof (wchar_t)); + for (j = 0; j < i; j++) + block[j] = "abcdefgh"[j]; + retval = my_snprintf (result, sizeof (result), "%.*ls", (int) i, block); + ASSERT (memcmp (result, "abcdefgh", i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (retval == strlen (result)); + free (block); } } #endif diff --git a/tests/test-snprintf.c b/tests/test-snprintf.c index 790c99964..55bca339b 100644 --- a/tests/test-snprintf.c +++ b/tests/test-snprintf.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -47,25 +47,25 @@ main (int argc, char *argv[]) memcpy (buf, "DEADBEEF", 8); retval = snprintf (buf, size, "%d", 12345); if (size < 6) - { + { #if CHECK_SNPRINTF_POSIX - ASSERT (retval < 0 || retval >= size); + ASSERT (retval < 0 || retval >= size); #endif - if (size > 0) - { - ASSERT (memcmp (buf, "12345", size - 1) == 0); - ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size); - } + if (size > 0) + { + ASSERT (memcmp (buf, "12345", size - 1) == 0); + ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size); + } #if !CHECK_SNPRINTF_POSIX - if (size > 0) + if (size > 0) #endif - ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); - } + ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); + } else - { - ASSERT (retval == 5); - ASSERT (memcmp (buf, "12345\0EF", 8) == 0); - } + { + ASSERT (retval == 5); + ASSERT (memcmp (buf, "12345\0EF", 8) == 0); + } } return 0; diff --git a/tests/test-sprintf-posix.c b/tests/test-sprintf-posix.c index be35fe1a7..e5dab357c 100644 --- a/tests/test-sprintf-posix.c +++ b/tests/test-sprintf-posix.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-sprintf-posix.h" diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index ded5042ab..a1e414a56 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -79,15 +79,15 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas if (start_index < end_index) { if (string[start_index] == '-') - start_index++; + start_index++; if (start_index + 3 <= end_index - && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) - { - start_index += 3; - if (start_index == end_index - || (string[start_index] == '(' && string[end_index - 1] == ')')) - return 1; - } + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } } return 0; } @@ -150,9 +150,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%a %d", 3.1416015625, 33, 44, 55); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -161,9 +161,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%A %d", -3.1416015625, 33, 44, 55); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -205,8 +205,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%a %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -215,9 +215,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.0a %d", 1.5, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -226,9 +226,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.0a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -237,9 +237,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.1a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -248,9 +248,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.2a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -259,9 +259,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.3a %d", 1.51, 33, 44, 55); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -270,9 +270,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.3a %d", 1.49999, 33, 44, 55); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -282,9 +282,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.1a %d", 1.999, 33, 44, 55); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -293,9 +293,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%10a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -304,9 +304,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.10a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -315,9 +315,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.50a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -326,9 +326,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%-10a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -337,9 +337,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%+a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -348,9 +348,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "% a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -359,9 +359,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -370,9 +370,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#a %d", 1.0, 33, 44, 55); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -381,9 +381,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%010a %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -404,8 +404,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -414,9 +414,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", 3.1416015625L, 33, 44, 55); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -425,9 +425,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%LA %d", -3.1416015625L, 33, 44, 55); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -469,8 +469,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -481,8 +481,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -493,8 +493,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -511,8 +511,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -522,8 +522,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -533,8 +533,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -544,8 +544,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -555,8 +555,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -566,9 +566,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.0La %d", 1.5L, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -577,9 +577,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.0La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -588,9 +588,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.1La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -599,9 +599,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.2La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -610,9 +610,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.3La %d", 1.51L, 33, 44, 55); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -621,9 +621,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.3La %d", 1.49999L, 33, 44, 55); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -634,9 +634,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.1La %d", 1.999L, 33, 44, 55); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (retval == strlen (result)); } @@ -645,9 +645,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%10La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -656,9 +656,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.10La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -667,9 +667,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.50La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -678,9 +678,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%-10La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -689,9 +689,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%+La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -700,9 +700,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "% La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -711,9 +711,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -722,9 +722,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#La %d", 1.0L, 33, 44, 55); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -733,9 +733,9 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%010La %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (retval == strlen (result)); } @@ -756,8 +756,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -782,89 +782,89 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "0.000000" }, - { 1.234321234321234e-36, "0.000000" }, - { 1.234321234321234e-35, "0.000000" }, - { 1.234321234321234e-34, "0.000000" }, - { 1.234321234321234e-33, "0.000000" }, - { 1.234321234321234e-32, "0.000000" }, - { 1.234321234321234e-31, "0.000000" }, - { 1.234321234321234e-30, "0.000000" }, - { 1.234321234321234e-29, "0.000000" }, - { 1.234321234321234e-28, "0.000000" }, - { 1.234321234321234e-27, "0.000000" }, - { 1.234321234321234e-26, "0.000000" }, - { 1.234321234321234e-25, "0.000000" }, - { 1.234321234321234e-24, "0.000000" }, - { 1.234321234321234e-23, "0.000000" }, - { 1.234321234321234e-22, "0.000000" }, - { 1.234321234321234e-21, "0.000000" }, - { 1.234321234321234e-20, "0.000000" }, - { 1.234321234321234e-19, "0.000000" }, - { 1.234321234321234e-18, "0.000000" }, - { 1.234321234321234e-17, "0.000000" }, - { 1.234321234321234e-16, "0.000000" }, - { 1.234321234321234e-15, "0.000000" }, - { 1.234321234321234e-14, "0.000000" }, - { 1.234321234321234e-13, "0.000000" }, - { 1.234321234321234e-12, "0.000000" }, - { 1.234321234321234e-11, "0.000000" }, - { 1.234321234321234e-10, "0.000000" }, - { 1.234321234321234e-9, "0.000000" }, - { 1.234321234321234e-8, "0.000000" }, - { 1.234321234321234e-7, "0.000000" }, - { 1.234321234321234e-6, "0.000001" }, - { 1.234321234321234e-5, "0.000012" }, - { 1.234321234321234e-4, "0.000123" }, - { 1.234321234321234e-3, "0.001234" }, - { 1.234321234321234e-2, "0.012343" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.234321" }, - { 1.234321234321234e1, "12.343212" }, - { 1.234321234321234e2, "123.432123" }, - { 1.234321234321234e3, "1234.321234" }, - { 1.234321234321234e4, "12343.212343" }, - { 1.234321234321234e5, "123432.123432" }, - { 1.234321234321234e6, "1234321.234321" }, - { 1.234321234321234e7, "12343212.343212" }, - { 1.234321234321234e8, "123432123.432123" }, - { 1.234321234321234e9, "1234321234.321234" }, - { 1.234321234321234e10, "12343212343.2123**" }, - { 1.234321234321234e11, "123432123432.123***" }, - { 1.234321234321234e12, "1234321234321.23****" }, - { 1.234321234321234e13, "12343212343212.3*****" }, - { 1.234321234321234e14, "123432123432123.******" }, - { 1.234321234321234e15, "1234321234321234.000000" }, - { 1.234321234321234e16, "123432123432123**.000000" }, - { 1.234321234321234e17, "123432123432123***.000000" }, - { 1.234321234321234e18, "123432123432123****.000000" }, - { 1.234321234321234e19, "123432123432123*****.000000" }, - { 1.234321234321234e20, "123432123432123******.000000" }, - { 1.234321234321234e21, "123432123432123*******.000000" }, - { 1.234321234321234e22, "123432123432123********.000000" }, - { 1.234321234321234e23, "123432123432123*********.000000" }, - { 1.234321234321234e24, "123432123432123**********.000000" }, - { 1.234321234321234e25, "123432123432123***********.000000" }, - { 1.234321234321234e26, "123432123432123************.000000" }, - { 1.234321234321234e27, "123432123432123*************.000000" }, - { 1.234321234321234e28, "123432123432123**************.000000" }, - { 1.234321234321234e29, "123432123432123***************.000000" }, - { 1.234321234321234e30, "123432123432123****************.000000" }, - { 1.234321234321234e31, "123432123432123*****************.000000" }, - { 1.234321234321234e32, "123432123432123******************.000000" }, - { 1.234321234321234e33, "123432123432123*******************.000000" }, - { 1.234321234321234e34, "123432123432123********************.000000" }, - { 1.234321234321234e35, "123432123432123*********************.000000" }, - { 1.234321234321234e36, "123432123432123**********************.000000" } + { 1.234321234321234e-37, "0.000000" }, + { 1.234321234321234e-36, "0.000000" }, + { 1.234321234321234e-35, "0.000000" }, + { 1.234321234321234e-34, "0.000000" }, + { 1.234321234321234e-33, "0.000000" }, + { 1.234321234321234e-32, "0.000000" }, + { 1.234321234321234e-31, "0.000000" }, + { 1.234321234321234e-30, "0.000000" }, + { 1.234321234321234e-29, "0.000000" }, + { 1.234321234321234e-28, "0.000000" }, + { 1.234321234321234e-27, "0.000000" }, + { 1.234321234321234e-26, "0.000000" }, + { 1.234321234321234e-25, "0.000000" }, + { 1.234321234321234e-24, "0.000000" }, + { 1.234321234321234e-23, "0.000000" }, + { 1.234321234321234e-22, "0.000000" }, + { 1.234321234321234e-21, "0.000000" }, + { 1.234321234321234e-20, "0.000000" }, + { 1.234321234321234e-19, "0.000000" }, + { 1.234321234321234e-18, "0.000000" }, + { 1.234321234321234e-17, "0.000000" }, + { 1.234321234321234e-16, "0.000000" }, + { 1.234321234321234e-15, "0.000000" }, + { 1.234321234321234e-14, "0.000000" }, + { 1.234321234321234e-13, "0.000000" }, + { 1.234321234321234e-12, "0.000000" }, + { 1.234321234321234e-11, "0.000000" }, + { 1.234321234321234e-10, "0.000000" }, + { 1.234321234321234e-9, "0.000000" }, + { 1.234321234321234e-8, "0.000000" }, + { 1.234321234321234e-7, "0.000000" }, + { 1.234321234321234e-6, "0.000001" }, + { 1.234321234321234e-5, "0.000012" }, + { 1.234321234321234e-4, "0.000123" }, + { 1.234321234321234e-3, "0.001234" }, + { 1.234321234321234e-2, "0.012343" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.234321" }, + { 1.234321234321234e1, "12.343212" }, + { 1.234321234321234e2, "123.432123" }, + { 1.234321234321234e3, "1234.321234" }, + { 1.234321234321234e4, "12343.212343" }, + { 1.234321234321234e5, "123432.123432" }, + { 1.234321234321234e6, "1234321.234321" }, + { 1.234321234321234e7, "12343212.343212" }, + { 1.234321234321234e8, "123432123.432123" }, + { 1.234321234321234e9, "1234321234.321234" }, + { 1.234321234321234e10, "12343212343.2123**" }, + { 1.234321234321234e11, "123432123432.123***" }, + { 1.234321234321234e12, "1234321234321.23****" }, + { 1.234321234321234e13, "12343212343212.3*****" }, + { 1.234321234321234e14, "123432123432123.******" }, + { 1.234321234321234e15, "1234321234321234.000000" }, + { 1.234321234321234e16, "123432123432123**.000000" }, + { 1.234321234321234e17, "123432123432123***.000000" }, + { 1.234321234321234e18, "123432123432123****.000000" }, + { 1.234321234321234e19, "123432123432123*****.000000" }, + { 1.234321234321234e20, "123432123432123******.000000" }, + { 1.234321234321234e21, "123432123432123*******.000000" }, + { 1.234321234321234e22, "123432123432123********.000000" }, + { 1.234321234321234e23, "123432123432123*********.000000" }, + { 1.234321234321234e24, "123432123432123**********.000000" }, + { 1.234321234321234e25, "123432123432123***********.000000" }, + { 1.234321234321234e26, "123432123432123************.000000" }, + { 1.234321234321234e27, "123432123432123*************.000000" }, + { 1.234321234321234e28, "123432123432123**************.000000" }, + { 1.234321234321234e29, "123432123432123***************.000000" }, + { 1.234321234321234e30, "123432123432123****************.000000" }, + { 1.234321234321234e31, "123432123432123*****************.000000" }, + { 1.234321234321234e32, "123432123432123******************.000000" }, + { 1.234321234321234e33, "123432123432123*******************.000000" }, + { 1.234321234321234e34, "123432123432123********************.000000" }, + { 1.234321234321234e35, "123432123432123*********************.000000" }, + { 1.234321234321234e36, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[1000]; - int retval = - my_sprintf (result, "%f", data[k].value); - ASSERT (strmatch (data[k].string, result)); - ASSERT (retval == strlen (result)); + char result[1000]; + int retval = + my_sprintf (result, "%f", data[k].value); + ASSERT (strmatch (data[k].string, result)); + ASSERT (retval == strlen (result)); } } @@ -898,7 +898,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%f %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -907,7 +907,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -916,8 +916,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -982,7 +982,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -991,8 +991,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%050f %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1039,89 +1039,89 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "0.000000" }, - { 1.234321234321234e-36L, "0.000000" }, - { 1.234321234321234e-35L, "0.000000" }, - { 1.234321234321234e-34L, "0.000000" }, - { 1.234321234321234e-33L, "0.000000" }, - { 1.234321234321234e-32L, "0.000000" }, - { 1.234321234321234e-31L, "0.000000" }, - { 1.234321234321234e-30L, "0.000000" }, - { 1.234321234321234e-29L, "0.000000" }, - { 1.234321234321234e-28L, "0.000000" }, - { 1.234321234321234e-27L, "0.000000" }, - { 1.234321234321234e-26L, "0.000000" }, - { 1.234321234321234e-25L, "0.000000" }, - { 1.234321234321234e-24L, "0.000000" }, - { 1.234321234321234e-23L, "0.000000" }, - { 1.234321234321234e-22L, "0.000000" }, - { 1.234321234321234e-21L, "0.000000" }, - { 1.234321234321234e-20L, "0.000000" }, - { 1.234321234321234e-19L, "0.000000" }, - { 1.234321234321234e-18L, "0.000000" }, - { 1.234321234321234e-17L, "0.000000" }, - { 1.234321234321234e-16L, "0.000000" }, - { 1.234321234321234e-15L, "0.000000" }, - { 1.234321234321234e-14L, "0.000000" }, - { 1.234321234321234e-13L, "0.000000" }, - { 1.234321234321234e-12L, "0.000000" }, - { 1.234321234321234e-11L, "0.000000" }, - { 1.234321234321234e-10L, "0.000000" }, - { 1.234321234321234e-9L, "0.000000" }, - { 1.234321234321234e-8L, "0.000000" }, - { 1.234321234321234e-7L, "0.000000" }, - { 1.234321234321234e-6L, "0.000001" }, - { 1.234321234321234e-5L, "0.000012" }, - { 1.234321234321234e-4L, "0.000123" }, - { 1.234321234321234e-3L, "0.001234" }, - { 1.234321234321234e-2L, "0.012343" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.234321" }, - { 1.234321234321234e1L, "12.343212" }, - { 1.234321234321234e2L, "123.432123" }, - { 1.234321234321234e3L, "1234.321234" }, - { 1.234321234321234e4L, "12343.212343" }, - { 1.234321234321234e5L, "123432.123432" }, - { 1.234321234321234e6L, "1234321.234321" }, - { 1.234321234321234e7L, "12343212.343212" }, - { 1.234321234321234e8L, "123432123.432123" }, - { 1.234321234321234e9L, "1234321234.321234" }, - { 1.234321234321234e10L, "12343212343.2123**" }, - { 1.234321234321234e11L, "123432123432.123***" }, - { 1.234321234321234e12L, "1234321234321.23****" }, - { 1.234321234321234e13L, "12343212343212.3*****" }, - { 1.234321234321234e14L, "123432123432123.******" }, - { 1.234321234321234e15L, "1234321234321234.000000" }, - { 1.234321234321234e16L, "123432123432123**.000000" }, - { 1.234321234321234e17L, "123432123432123***.000000" }, - { 1.234321234321234e18L, "123432123432123****.000000" }, - { 1.234321234321234e19L, "123432123432123*****.000000" }, - { 1.234321234321234e20L, "123432123432123******.000000" }, - { 1.234321234321234e21L, "123432123432123*******.000000" }, - { 1.234321234321234e22L, "123432123432123********.000000" }, - { 1.234321234321234e23L, "123432123432123*********.000000" }, - { 1.234321234321234e24L, "123432123432123**********.000000" }, - { 1.234321234321234e25L, "123432123432123***********.000000" }, - { 1.234321234321234e26L, "123432123432123************.000000" }, - { 1.234321234321234e27L, "123432123432123*************.000000" }, - { 1.234321234321234e28L, "123432123432123**************.000000" }, - { 1.234321234321234e29L, "123432123432123***************.000000" }, - { 1.234321234321234e30L, "123432123432123****************.000000" }, - { 1.234321234321234e31L, "123432123432123*****************.000000" }, - { 1.234321234321234e32L, "123432123432123******************.000000" }, - { 1.234321234321234e33L, "123432123432123*******************.000000" }, - { 1.234321234321234e34L, "123432123432123********************.000000" }, - { 1.234321234321234e35L, "123432123432123*********************.000000" }, - { 1.234321234321234e36L, "123432123432123**********************.000000" } + { 1.234321234321234e-37L, "0.000000" }, + { 1.234321234321234e-36L, "0.000000" }, + { 1.234321234321234e-35L, "0.000000" }, + { 1.234321234321234e-34L, "0.000000" }, + { 1.234321234321234e-33L, "0.000000" }, + { 1.234321234321234e-32L, "0.000000" }, + { 1.234321234321234e-31L, "0.000000" }, + { 1.234321234321234e-30L, "0.000000" }, + { 1.234321234321234e-29L, "0.000000" }, + { 1.234321234321234e-28L, "0.000000" }, + { 1.234321234321234e-27L, "0.000000" }, + { 1.234321234321234e-26L, "0.000000" }, + { 1.234321234321234e-25L, "0.000000" }, + { 1.234321234321234e-24L, "0.000000" }, + { 1.234321234321234e-23L, "0.000000" }, + { 1.234321234321234e-22L, "0.000000" }, + { 1.234321234321234e-21L, "0.000000" }, + { 1.234321234321234e-20L, "0.000000" }, + { 1.234321234321234e-19L, "0.000000" }, + { 1.234321234321234e-18L, "0.000000" }, + { 1.234321234321234e-17L, "0.000000" }, + { 1.234321234321234e-16L, "0.000000" }, + { 1.234321234321234e-15L, "0.000000" }, + { 1.234321234321234e-14L, "0.000000" }, + { 1.234321234321234e-13L, "0.000000" }, + { 1.234321234321234e-12L, "0.000000" }, + { 1.234321234321234e-11L, "0.000000" }, + { 1.234321234321234e-10L, "0.000000" }, + { 1.234321234321234e-9L, "0.000000" }, + { 1.234321234321234e-8L, "0.000000" }, + { 1.234321234321234e-7L, "0.000000" }, + { 1.234321234321234e-6L, "0.000001" }, + { 1.234321234321234e-5L, "0.000012" }, + { 1.234321234321234e-4L, "0.000123" }, + { 1.234321234321234e-3L, "0.001234" }, + { 1.234321234321234e-2L, "0.012343" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.234321" }, + { 1.234321234321234e1L, "12.343212" }, + { 1.234321234321234e2L, "123.432123" }, + { 1.234321234321234e3L, "1234.321234" }, + { 1.234321234321234e4L, "12343.212343" }, + { 1.234321234321234e5L, "123432.123432" }, + { 1.234321234321234e6L, "1234321.234321" }, + { 1.234321234321234e7L, "12343212.343212" }, + { 1.234321234321234e8L, "123432123.432123" }, + { 1.234321234321234e9L, "1234321234.321234" }, + { 1.234321234321234e10L, "12343212343.2123**" }, + { 1.234321234321234e11L, "123432123432.123***" }, + { 1.234321234321234e12L, "1234321234321.23****" }, + { 1.234321234321234e13L, "12343212343212.3*****" }, + { 1.234321234321234e14L, "123432123432123.******" }, + { 1.234321234321234e15L, "1234321234321234.000000" }, + { 1.234321234321234e16L, "123432123432123**.000000" }, + { 1.234321234321234e17L, "123432123432123***.000000" }, + { 1.234321234321234e18L, "123432123432123****.000000" }, + { 1.234321234321234e19L, "123432123432123*****.000000" }, + { 1.234321234321234e20L, "123432123432123******.000000" }, + { 1.234321234321234e21L, "123432123432123*******.000000" }, + { 1.234321234321234e22L, "123432123432123********.000000" }, + { 1.234321234321234e23L, "123432123432123*********.000000" }, + { 1.234321234321234e24L, "123432123432123**********.000000" }, + { 1.234321234321234e25L, "123432123432123***********.000000" }, + { 1.234321234321234e26L, "123432123432123************.000000" }, + { 1.234321234321234e27L, "123432123432123*************.000000" }, + { 1.234321234321234e28L, "123432123432123**************.000000" }, + { 1.234321234321234e29L, "123432123432123***************.000000" }, + { 1.234321234321234e30L, "123432123432123****************.000000" }, + { 1.234321234321234e31L, "123432123432123*****************.000000" }, + { 1.234321234321234e32L, "123432123432123******************.000000" }, + { 1.234321234321234e33L, "123432123432123*******************.000000" }, + { 1.234321234321234e34L, "123432123432123********************.000000" }, + { 1.234321234321234e35L, "123432123432123*********************.000000" }, + { 1.234321234321234e36L, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[1000]; - int retval = - my_sprintf (result, "%Lf", data[k].value); - ASSERT (strmatch (data[k].string, result)); - ASSERT (retval == strlen (result)); + char result[1000]; + int retval = + my_sprintf (result, "%Lf", data[k].value); + ASSERT (strmatch (data[k].string, result)); + ASSERT (retval == strlen (result)); } } @@ -1155,7 +1155,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1164,7 +1164,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1173,8 +1173,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -1185,8 +1185,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -1197,8 +1197,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -1215,8 +1215,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -1226,8 +1226,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -1237,8 +1237,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -1248,8 +1248,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -1259,8 +1259,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lf %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -1326,7 +1326,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1335,8 +1335,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1412,7 +1412,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%F %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1421,7 +1421,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1430,8 +1430,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%F %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1448,7 +1448,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1522,7 +1522,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%LF %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1531,7 +1531,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1540,8 +1540,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%LF %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1558,7 +1558,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (retval == strlen (result)); } @@ -1593,7 +1593,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", 12.75, 33, 44, 55); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1602,104 +1602,104 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", 1234567.0, 33, 44, 55); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.234321e-37" }, - { 1.234321234321234e-36, "1.234321e-36" }, - { 1.234321234321234e-35, "1.234321e-35" }, - { 1.234321234321234e-34, "1.234321e-34" }, - { 1.234321234321234e-33, "1.234321e-33" }, - { 1.234321234321234e-32, "1.234321e-32" }, - { 1.234321234321234e-31, "1.234321e-31" }, - { 1.234321234321234e-30, "1.234321e-30" }, - { 1.234321234321234e-29, "1.234321e-29" }, - { 1.234321234321234e-28, "1.234321e-28" }, - { 1.234321234321234e-27, "1.234321e-27" }, - { 1.234321234321234e-26, "1.234321e-26" }, - { 1.234321234321234e-25, "1.234321e-25" }, - { 1.234321234321234e-24, "1.234321e-24" }, - { 1.234321234321234e-23, "1.234321e-23" }, - { 1.234321234321234e-22, "1.234321e-22" }, - { 1.234321234321234e-21, "1.234321e-21" }, - { 1.234321234321234e-20, "1.234321e-20" }, - { 1.234321234321234e-19, "1.234321e-19" }, - { 1.234321234321234e-18, "1.234321e-18" }, - { 1.234321234321234e-17, "1.234321e-17" }, - { 1.234321234321234e-16, "1.234321e-16" }, - { 1.234321234321234e-15, "1.234321e-15" }, - { 1.234321234321234e-14, "1.234321e-14" }, - { 1.234321234321234e-13, "1.234321e-13" }, - { 1.234321234321234e-12, "1.234321e-12" }, - { 1.234321234321234e-11, "1.234321e-11" }, - { 1.234321234321234e-10, "1.234321e-10" }, - { 1.234321234321234e-9, "1.234321e-09" }, - { 1.234321234321234e-8, "1.234321e-08" }, - { 1.234321234321234e-7, "1.234321e-07" }, - { 1.234321234321234e-6, "1.234321e-06" }, - { 1.234321234321234e-5, "1.234321e-05" }, - { 1.234321234321234e-4, "1.234321e-04" }, - { 1.234321234321234e-3, "1.234321e-03" }, - { 1.234321234321234e-2, "1.234321e-02" }, - { 1.234321234321234e-1, "1.234321e-01" }, - { 1.234321234321234, "1.234321e+00" }, - { 1.234321234321234e1, "1.234321e+01" }, - { 1.234321234321234e2, "1.234321e+02" }, - { 1.234321234321234e3, "1.234321e+03" }, - { 1.234321234321234e4, "1.234321e+04" }, - { 1.234321234321234e5, "1.234321e+05" }, - { 1.234321234321234e6, "1.234321e+06" }, - { 1.234321234321234e7, "1.234321e+07" }, - { 1.234321234321234e8, "1.234321e+08" }, - { 1.234321234321234e9, "1.234321e+09" }, - { 1.234321234321234e10, "1.234321e+10" }, - { 1.234321234321234e11, "1.234321e+11" }, - { 1.234321234321234e12, "1.234321e+12" }, - { 1.234321234321234e13, "1.234321e+13" }, - { 1.234321234321234e14, "1.234321e+14" }, - { 1.234321234321234e15, "1.234321e+15" }, - { 1.234321234321234e16, "1.234321e+16" }, - { 1.234321234321234e17, "1.234321e+17" }, - { 1.234321234321234e18, "1.234321e+18" }, - { 1.234321234321234e19, "1.234321e+19" }, - { 1.234321234321234e20, "1.234321e+20" }, - { 1.234321234321234e21, "1.234321e+21" }, - { 1.234321234321234e22, "1.234321e+22" }, - { 1.234321234321234e23, "1.234321e+23" }, - { 1.234321234321234e24, "1.234321e+24" }, - { 1.234321234321234e25, "1.234321e+25" }, - { 1.234321234321234e26, "1.234321e+26" }, - { 1.234321234321234e27, "1.234321e+27" }, - { 1.234321234321234e28, "1.234321e+28" }, - { 1.234321234321234e29, "1.234321e+29" }, - { 1.234321234321234e30, "1.234321e+30" }, - { 1.234321234321234e31, "1.234321e+31" }, - { 1.234321234321234e32, "1.234321e+32" }, - { 1.234321234321234e33, "1.234321e+33" }, - { 1.234321234321234e34, "1.234321e+34" }, - { 1.234321234321234e35, "1.234321e+35" }, - { 1.234321234321234e36, "1.234321e+36" } + { 1.234321234321234e-37, "1.234321e-37" }, + { 1.234321234321234e-36, "1.234321e-36" }, + { 1.234321234321234e-35, "1.234321e-35" }, + { 1.234321234321234e-34, "1.234321e-34" }, + { 1.234321234321234e-33, "1.234321e-33" }, + { 1.234321234321234e-32, "1.234321e-32" }, + { 1.234321234321234e-31, "1.234321e-31" }, + { 1.234321234321234e-30, "1.234321e-30" }, + { 1.234321234321234e-29, "1.234321e-29" }, + { 1.234321234321234e-28, "1.234321e-28" }, + { 1.234321234321234e-27, "1.234321e-27" }, + { 1.234321234321234e-26, "1.234321e-26" }, + { 1.234321234321234e-25, "1.234321e-25" }, + { 1.234321234321234e-24, "1.234321e-24" }, + { 1.234321234321234e-23, "1.234321e-23" }, + { 1.234321234321234e-22, "1.234321e-22" }, + { 1.234321234321234e-21, "1.234321e-21" }, + { 1.234321234321234e-20, "1.234321e-20" }, + { 1.234321234321234e-19, "1.234321e-19" }, + { 1.234321234321234e-18, "1.234321e-18" }, + { 1.234321234321234e-17, "1.234321e-17" }, + { 1.234321234321234e-16, "1.234321e-16" }, + { 1.234321234321234e-15, "1.234321e-15" }, + { 1.234321234321234e-14, "1.234321e-14" }, + { 1.234321234321234e-13, "1.234321e-13" }, + { 1.234321234321234e-12, "1.234321e-12" }, + { 1.234321234321234e-11, "1.234321e-11" }, + { 1.234321234321234e-10, "1.234321e-10" }, + { 1.234321234321234e-9, "1.234321e-09" }, + { 1.234321234321234e-8, "1.234321e-08" }, + { 1.234321234321234e-7, "1.234321e-07" }, + { 1.234321234321234e-6, "1.234321e-06" }, + { 1.234321234321234e-5, "1.234321e-05" }, + { 1.234321234321234e-4, "1.234321e-04" }, + { 1.234321234321234e-3, "1.234321e-03" }, + { 1.234321234321234e-2, "1.234321e-02" }, + { 1.234321234321234e-1, "1.234321e-01" }, + { 1.234321234321234, "1.234321e+00" }, + { 1.234321234321234e1, "1.234321e+01" }, + { 1.234321234321234e2, "1.234321e+02" }, + { 1.234321234321234e3, "1.234321e+03" }, + { 1.234321234321234e4, "1.234321e+04" }, + { 1.234321234321234e5, "1.234321e+05" }, + { 1.234321234321234e6, "1.234321e+06" }, + { 1.234321234321234e7, "1.234321e+07" }, + { 1.234321234321234e8, "1.234321e+08" }, + { 1.234321234321234e9, "1.234321e+09" }, + { 1.234321234321234e10, "1.234321e+10" }, + { 1.234321234321234e11, "1.234321e+11" }, + { 1.234321234321234e12, "1.234321e+12" }, + { 1.234321234321234e13, "1.234321e+13" }, + { 1.234321234321234e14, "1.234321e+14" }, + { 1.234321234321234e15, "1.234321e+15" }, + { 1.234321234321234e16, "1.234321e+16" }, + { 1.234321234321234e17, "1.234321e+17" }, + { 1.234321234321234e18, "1.234321e+18" }, + { 1.234321234321234e19, "1.234321e+19" }, + { 1.234321234321234e20, "1.234321e+20" }, + { 1.234321234321234e21, "1.234321e+21" }, + { 1.234321234321234e22, "1.234321e+22" }, + { 1.234321234321234e23, "1.234321e+23" }, + { 1.234321234321234e24, "1.234321e+24" }, + { 1.234321234321234e25, "1.234321e+25" }, + { 1.234321234321234e26, "1.234321e+26" }, + { 1.234321234321234e27, "1.234321e+27" }, + { 1.234321234321234e28, "1.234321e+28" }, + { 1.234321234321234e29, "1.234321e+29" }, + { 1.234321234321234e30, "1.234321e+30" }, + { 1.234321234321234e31, "1.234321e+31" }, + { 1.234321234321234e32, "1.234321e+32" }, + { 1.234321234321234e33, "1.234321e+33" }, + { 1.234321234321234e34, "1.234321e+34" }, + { 1.234321234321234e35, "1.234321e+35" }, + { 1.234321234321234e36, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[1000]; - int retval = - my_sprintf (result, "%e", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[1000]; + int retval = + my_sprintf (result, "%e", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -1708,7 +1708,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", -0.03125, 33, 44, 55); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); } @@ -1717,7 +1717,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", 0.0, 33, 44, 55); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1727,7 +1727,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) my_sprintf (result, "%e %d", -zerod, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1736,7 +1736,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1745,7 +1745,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1754,8 +1754,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1764,7 +1764,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%15e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1773,7 +1773,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%-15e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1782,7 +1782,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%+e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1791,7 +1791,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "% e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1800,7 +1800,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1809,7 +1809,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#.e %d", 1.75, 33, 44, 55); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -1818,7 +1818,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#.e %d", 9.75, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1827,7 +1827,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015e %d", 1234.0, 33, 44, 55); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1836,7 +1836,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -1845,8 +1845,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%050e %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -1855,7 +1855,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.e %d", 1234.0, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1864,7 +1864,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.4e %d", 999.951, 33, 44, 55); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (retval == strlen (result)); } @@ -1873,7 +1873,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.4e %d", 999.996, 33, 44, 55); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -1882,7 +1882,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", 12.75L, 33, 44, 55); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -1891,104 +1891,104 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", 1234567.0L, 33, 44, 55); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.234321e-37" }, - { 1.234321234321234e-36L, "1.234321e-36" }, - { 1.234321234321234e-35L, "1.234321e-35" }, - { 1.234321234321234e-34L, "1.234321e-34" }, - { 1.234321234321234e-33L, "1.234321e-33" }, - { 1.234321234321234e-32L, "1.234321e-32" }, - { 1.234321234321234e-31L, "1.234321e-31" }, - { 1.234321234321234e-30L, "1.234321e-30" }, - { 1.234321234321234e-29L, "1.234321e-29" }, - { 1.234321234321234e-28L, "1.234321e-28" }, - { 1.234321234321234e-27L, "1.234321e-27" }, - { 1.234321234321234e-26L, "1.234321e-26" }, - { 1.234321234321234e-25L, "1.234321e-25" }, - { 1.234321234321234e-24L, "1.234321e-24" }, - { 1.234321234321234e-23L, "1.234321e-23" }, - { 1.234321234321234e-22L, "1.234321e-22" }, - { 1.234321234321234e-21L, "1.234321e-21" }, - { 1.234321234321234e-20L, "1.234321e-20" }, - { 1.234321234321234e-19L, "1.234321e-19" }, - { 1.234321234321234e-18L, "1.234321e-18" }, - { 1.234321234321234e-17L, "1.234321e-17" }, - { 1.234321234321234e-16L, "1.234321e-16" }, - { 1.234321234321234e-15L, "1.234321e-15" }, - { 1.234321234321234e-14L, "1.234321e-14" }, - { 1.234321234321234e-13L, "1.234321e-13" }, - { 1.234321234321234e-12L, "1.234321e-12" }, - { 1.234321234321234e-11L, "1.234321e-11" }, - { 1.234321234321234e-10L, "1.234321e-10" }, - { 1.234321234321234e-9L, "1.234321e-09" }, - { 1.234321234321234e-8L, "1.234321e-08" }, - { 1.234321234321234e-7L, "1.234321e-07" }, - { 1.234321234321234e-6L, "1.234321e-06" }, - { 1.234321234321234e-5L, "1.234321e-05" }, - { 1.234321234321234e-4L, "1.234321e-04" }, - { 1.234321234321234e-3L, "1.234321e-03" }, - { 1.234321234321234e-2L, "1.234321e-02" }, - { 1.234321234321234e-1L, "1.234321e-01" }, - { 1.234321234321234L, "1.234321e+00" }, - { 1.234321234321234e1L, "1.234321e+01" }, - { 1.234321234321234e2L, "1.234321e+02" }, - { 1.234321234321234e3L, "1.234321e+03" }, - { 1.234321234321234e4L, "1.234321e+04" }, - { 1.234321234321234e5L, "1.234321e+05" }, - { 1.234321234321234e6L, "1.234321e+06" }, - { 1.234321234321234e7L, "1.234321e+07" }, - { 1.234321234321234e8L, "1.234321e+08" }, - { 1.234321234321234e9L, "1.234321e+09" }, - { 1.234321234321234e10L, "1.234321e+10" }, - { 1.234321234321234e11L, "1.234321e+11" }, - { 1.234321234321234e12L, "1.234321e+12" }, - { 1.234321234321234e13L, "1.234321e+13" }, - { 1.234321234321234e14L, "1.234321e+14" }, - { 1.234321234321234e15L, "1.234321e+15" }, - { 1.234321234321234e16L, "1.234321e+16" }, - { 1.234321234321234e17L, "1.234321e+17" }, - { 1.234321234321234e18L, "1.234321e+18" }, - { 1.234321234321234e19L, "1.234321e+19" }, - { 1.234321234321234e20L, "1.234321e+20" }, - { 1.234321234321234e21L, "1.234321e+21" }, - { 1.234321234321234e22L, "1.234321e+22" }, - { 1.234321234321234e23L, "1.234321e+23" }, - { 1.234321234321234e24L, "1.234321e+24" }, - { 1.234321234321234e25L, "1.234321e+25" }, - { 1.234321234321234e26L, "1.234321e+26" }, - { 1.234321234321234e27L, "1.234321e+27" }, - { 1.234321234321234e28L, "1.234321e+28" }, - { 1.234321234321234e29L, "1.234321e+29" }, - { 1.234321234321234e30L, "1.234321e+30" }, - { 1.234321234321234e31L, "1.234321e+31" }, - { 1.234321234321234e32L, "1.234321e+32" }, - { 1.234321234321234e33L, "1.234321e+33" }, - { 1.234321234321234e34L, "1.234321e+34" }, - { 1.234321234321234e35L, "1.234321e+35" }, - { 1.234321234321234e36L, "1.234321e+36" } + { 1.234321234321234e-37L, "1.234321e-37" }, + { 1.234321234321234e-36L, "1.234321e-36" }, + { 1.234321234321234e-35L, "1.234321e-35" }, + { 1.234321234321234e-34L, "1.234321e-34" }, + { 1.234321234321234e-33L, "1.234321e-33" }, + { 1.234321234321234e-32L, "1.234321e-32" }, + { 1.234321234321234e-31L, "1.234321e-31" }, + { 1.234321234321234e-30L, "1.234321e-30" }, + { 1.234321234321234e-29L, "1.234321e-29" }, + { 1.234321234321234e-28L, "1.234321e-28" }, + { 1.234321234321234e-27L, "1.234321e-27" }, + { 1.234321234321234e-26L, "1.234321e-26" }, + { 1.234321234321234e-25L, "1.234321e-25" }, + { 1.234321234321234e-24L, "1.234321e-24" }, + { 1.234321234321234e-23L, "1.234321e-23" }, + { 1.234321234321234e-22L, "1.234321e-22" }, + { 1.234321234321234e-21L, "1.234321e-21" }, + { 1.234321234321234e-20L, "1.234321e-20" }, + { 1.234321234321234e-19L, "1.234321e-19" }, + { 1.234321234321234e-18L, "1.234321e-18" }, + { 1.234321234321234e-17L, "1.234321e-17" }, + { 1.234321234321234e-16L, "1.234321e-16" }, + { 1.234321234321234e-15L, "1.234321e-15" }, + { 1.234321234321234e-14L, "1.234321e-14" }, + { 1.234321234321234e-13L, "1.234321e-13" }, + { 1.234321234321234e-12L, "1.234321e-12" }, + { 1.234321234321234e-11L, "1.234321e-11" }, + { 1.234321234321234e-10L, "1.234321e-10" }, + { 1.234321234321234e-9L, "1.234321e-09" }, + { 1.234321234321234e-8L, "1.234321e-08" }, + { 1.234321234321234e-7L, "1.234321e-07" }, + { 1.234321234321234e-6L, "1.234321e-06" }, + { 1.234321234321234e-5L, "1.234321e-05" }, + { 1.234321234321234e-4L, "1.234321e-04" }, + { 1.234321234321234e-3L, "1.234321e-03" }, + { 1.234321234321234e-2L, "1.234321e-02" }, + { 1.234321234321234e-1L, "1.234321e-01" }, + { 1.234321234321234L, "1.234321e+00" }, + { 1.234321234321234e1L, "1.234321e+01" }, + { 1.234321234321234e2L, "1.234321e+02" }, + { 1.234321234321234e3L, "1.234321e+03" }, + { 1.234321234321234e4L, "1.234321e+04" }, + { 1.234321234321234e5L, "1.234321e+05" }, + { 1.234321234321234e6L, "1.234321e+06" }, + { 1.234321234321234e7L, "1.234321e+07" }, + { 1.234321234321234e8L, "1.234321e+08" }, + { 1.234321234321234e9L, "1.234321e+09" }, + { 1.234321234321234e10L, "1.234321e+10" }, + { 1.234321234321234e11L, "1.234321e+11" }, + { 1.234321234321234e12L, "1.234321e+12" }, + { 1.234321234321234e13L, "1.234321e+13" }, + { 1.234321234321234e14L, "1.234321e+14" }, + { 1.234321234321234e15L, "1.234321e+15" }, + { 1.234321234321234e16L, "1.234321e+16" }, + { 1.234321234321234e17L, "1.234321e+17" }, + { 1.234321234321234e18L, "1.234321e+18" }, + { 1.234321234321234e19L, "1.234321e+19" }, + { 1.234321234321234e20L, "1.234321e+20" }, + { 1.234321234321234e21L, "1.234321e+21" }, + { 1.234321234321234e22L, "1.234321e+22" }, + { 1.234321234321234e23L, "1.234321e+23" }, + { 1.234321234321234e24L, "1.234321e+24" }, + { 1.234321234321234e25L, "1.234321e+25" }, + { 1.234321234321234e26L, "1.234321e+26" }, + { 1.234321234321234e27L, "1.234321e+27" }, + { 1.234321234321234e28L, "1.234321e+28" }, + { 1.234321234321234e29L, "1.234321e+29" }, + { 1.234321234321234e30L, "1.234321e+30" }, + { 1.234321234321234e31L, "1.234321e+31" }, + { 1.234321234321234e32L, "1.234321e+32" }, + { 1.234321234321234e33L, "1.234321e+33" }, + { 1.234321234321234e34L, "1.234321e+34" }, + { 1.234321234321234e35L, "1.234321e+35" }, + { 1.234321234321234e36L, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[1000]; - int retval = - my_sprintf (result, "%Le", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[1000]; + int retval = + my_sprintf (result, "%Le", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -1997,7 +1997,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", -0.03125L, 33, 44, 55); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); } @@ -2006,7 +2006,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", 0.0L, 33, 44, 55); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2016,7 +2016,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) my_sprintf (result, "%Le %d", minus_zerol, 33, 44, 55); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2025,7 +2025,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2034,7 +2034,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2043,8 +2043,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -2055,8 +2055,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -2067,8 +2067,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -2085,8 +2085,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -2096,8 +2096,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -2107,8 +2107,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -2118,8 +2118,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -2129,8 +2129,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Le %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -2140,7 +2140,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%15Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2149,7 +2149,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%-15Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2158,7 +2158,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%+Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2167,7 +2167,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "% Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2176,7 +2176,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2185,7 +2185,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#.Le %d", 1.75L, 33, 44, 55); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); } @@ -2194,7 +2194,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#.Le %d", 9.75L, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2203,7 +2203,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015Le %d", 1234.0L, 33, 44, 55); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2212,7 +2212,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2221,8 +2221,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%050Le %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2231,7 +2231,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.Le %d", 1234.0L, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2240,7 +2240,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.4Le %d", 999.951L, 33, 44, 55); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (retval == strlen (result)); } @@ -2249,7 +2249,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.4Le %d", 999.996L, 33, 44, 55); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2268,105 +2268,105 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%g %d", 1234567.0, 33, 44, 55); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.23432e-37" }, - { 1.234321234321234e-36, "1.23432e-36" }, - { 1.234321234321234e-35, "1.23432e-35" }, - { 1.234321234321234e-34, "1.23432e-34" }, - { 1.234321234321234e-33, "1.23432e-33" }, - { 1.234321234321234e-32, "1.23432e-32" }, - { 1.234321234321234e-31, "1.23432e-31" }, - { 1.234321234321234e-30, "1.23432e-30" }, - { 1.234321234321234e-29, "1.23432e-29" }, - { 1.234321234321234e-28, "1.23432e-28" }, - { 1.234321234321234e-27, "1.23432e-27" }, - { 1.234321234321234e-26, "1.23432e-26" }, - { 1.234321234321234e-25, "1.23432e-25" }, - { 1.234321234321234e-24, "1.23432e-24" }, - { 1.234321234321234e-23, "1.23432e-23" }, - { 1.234321234321234e-22, "1.23432e-22" }, - { 1.234321234321234e-21, "1.23432e-21" }, - { 1.234321234321234e-20, "1.23432e-20" }, - { 1.234321234321234e-19, "1.23432e-19" }, - { 1.234321234321234e-18, "1.23432e-18" }, - { 1.234321234321234e-17, "1.23432e-17" }, - { 1.234321234321234e-16, "1.23432e-16" }, - { 1.234321234321234e-15, "1.23432e-15" }, - { 1.234321234321234e-14, "1.23432e-14" }, - { 1.234321234321234e-13, "1.23432e-13" }, - { 1.234321234321234e-12, "1.23432e-12" }, - { 1.234321234321234e-11, "1.23432e-11" }, - { 1.234321234321234e-10, "1.23432e-10" }, - { 1.234321234321234e-9, "1.23432e-09" }, - { 1.234321234321234e-8, "1.23432e-08" }, - { 1.234321234321234e-7, "1.23432e-07" }, - { 1.234321234321234e-6, "1.23432e-06" }, - { 1.234321234321234e-5, "1.23432e-05" }, - { 1.234321234321234e-4, "0.000123432" }, - { 1.234321234321234e-3, "0.00123432" }, - { 1.234321234321234e-2, "0.0123432" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.23432" }, - { 1.234321234321234e1, "12.3432" }, - { 1.234321234321234e2, "123.432" }, - { 1.234321234321234e3, "1234.32" }, - { 1.234321234321234e4, "12343.2" }, - { 1.234321234321234e5, "123432" }, - { 1.234321234321234e6, "1.23432e+06" }, - { 1.234321234321234e7, "1.23432e+07" }, - { 1.234321234321234e8, "1.23432e+08" }, - { 1.234321234321234e9, "1.23432e+09" }, - { 1.234321234321234e10, "1.23432e+10" }, - { 1.234321234321234e11, "1.23432e+11" }, - { 1.234321234321234e12, "1.23432e+12" }, - { 1.234321234321234e13, "1.23432e+13" }, - { 1.234321234321234e14, "1.23432e+14" }, - { 1.234321234321234e15, "1.23432e+15" }, - { 1.234321234321234e16, "1.23432e+16" }, - { 1.234321234321234e17, "1.23432e+17" }, - { 1.234321234321234e18, "1.23432e+18" }, - { 1.234321234321234e19, "1.23432e+19" }, - { 1.234321234321234e20, "1.23432e+20" }, - { 1.234321234321234e21, "1.23432e+21" }, - { 1.234321234321234e22, "1.23432e+22" }, - { 1.234321234321234e23, "1.23432e+23" }, - { 1.234321234321234e24, "1.23432e+24" }, - { 1.234321234321234e25, "1.23432e+25" }, - { 1.234321234321234e26, "1.23432e+26" }, - { 1.234321234321234e27, "1.23432e+27" }, - { 1.234321234321234e28, "1.23432e+28" }, - { 1.234321234321234e29, "1.23432e+29" }, - { 1.234321234321234e30, "1.23432e+30" }, - { 1.234321234321234e31, "1.23432e+31" }, - { 1.234321234321234e32, "1.23432e+32" }, - { 1.234321234321234e33, "1.23432e+33" }, - { 1.234321234321234e34, "1.23432e+34" }, - { 1.234321234321234e35, "1.23432e+35" }, - { 1.234321234321234e36, "1.23432e+36" } + { 1.234321234321234e-37, "1.23432e-37" }, + { 1.234321234321234e-36, "1.23432e-36" }, + { 1.234321234321234e-35, "1.23432e-35" }, + { 1.234321234321234e-34, "1.23432e-34" }, + { 1.234321234321234e-33, "1.23432e-33" }, + { 1.234321234321234e-32, "1.23432e-32" }, + { 1.234321234321234e-31, "1.23432e-31" }, + { 1.234321234321234e-30, "1.23432e-30" }, + { 1.234321234321234e-29, "1.23432e-29" }, + { 1.234321234321234e-28, "1.23432e-28" }, + { 1.234321234321234e-27, "1.23432e-27" }, + { 1.234321234321234e-26, "1.23432e-26" }, + { 1.234321234321234e-25, "1.23432e-25" }, + { 1.234321234321234e-24, "1.23432e-24" }, + { 1.234321234321234e-23, "1.23432e-23" }, + { 1.234321234321234e-22, "1.23432e-22" }, + { 1.234321234321234e-21, "1.23432e-21" }, + { 1.234321234321234e-20, "1.23432e-20" }, + { 1.234321234321234e-19, "1.23432e-19" }, + { 1.234321234321234e-18, "1.23432e-18" }, + { 1.234321234321234e-17, "1.23432e-17" }, + { 1.234321234321234e-16, "1.23432e-16" }, + { 1.234321234321234e-15, "1.23432e-15" }, + { 1.234321234321234e-14, "1.23432e-14" }, + { 1.234321234321234e-13, "1.23432e-13" }, + { 1.234321234321234e-12, "1.23432e-12" }, + { 1.234321234321234e-11, "1.23432e-11" }, + { 1.234321234321234e-10, "1.23432e-10" }, + { 1.234321234321234e-9, "1.23432e-09" }, + { 1.234321234321234e-8, "1.23432e-08" }, + { 1.234321234321234e-7, "1.23432e-07" }, + { 1.234321234321234e-6, "1.23432e-06" }, + { 1.234321234321234e-5, "1.23432e-05" }, + { 1.234321234321234e-4, "0.000123432" }, + { 1.234321234321234e-3, "0.00123432" }, + { 1.234321234321234e-2, "0.0123432" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.23432" }, + { 1.234321234321234e1, "12.3432" }, + { 1.234321234321234e2, "123.432" }, + { 1.234321234321234e3, "1234.32" }, + { 1.234321234321234e4, "12343.2" }, + { 1.234321234321234e5, "123432" }, + { 1.234321234321234e6, "1.23432e+06" }, + { 1.234321234321234e7, "1.23432e+07" }, + { 1.234321234321234e8, "1.23432e+08" }, + { 1.234321234321234e9, "1.23432e+09" }, + { 1.234321234321234e10, "1.23432e+10" }, + { 1.234321234321234e11, "1.23432e+11" }, + { 1.234321234321234e12, "1.23432e+12" }, + { 1.234321234321234e13, "1.23432e+13" }, + { 1.234321234321234e14, "1.23432e+14" }, + { 1.234321234321234e15, "1.23432e+15" }, + { 1.234321234321234e16, "1.23432e+16" }, + { 1.234321234321234e17, "1.23432e+17" }, + { 1.234321234321234e18, "1.23432e+18" }, + { 1.234321234321234e19, "1.23432e+19" }, + { 1.234321234321234e20, "1.23432e+20" }, + { 1.234321234321234e21, "1.23432e+21" }, + { 1.234321234321234e22, "1.23432e+22" }, + { 1.234321234321234e23, "1.23432e+23" }, + { 1.234321234321234e24, "1.23432e+24" }, + { 1.234321234321234e25, "1.23432e+25" }, + { 1.234321234321234e26, "1.23432e+26" }, + { 1.234321234321234e27, "1.23432e+27" }, + { 1.234321234321234e28, "1.23432e+28" }, + { 1.234321234321234e29, "1.23432e+29" }, + { 1.234321234321234e30, "1.23432e+30" }, + { 1.234321234321234e31, "1.23432e+31" }, + { 1.234321234321234e32, "1.23432e+32" }, + { 1.234321234321234e33, "1.23432e+33" }, + { 1.234321234321234e34, "1.23432e+34" }, + { 1.234321234321234e35, "1.23432e+35" }, + { 1.234321234321234e36, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[1000]; - int retval = - my_sprintf (result, "%g", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[1000]; + int retval = + my_sprintf (result, "%g", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -2400,7 +2400,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%g %d", 1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2409,7 +2409,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2418,8 +2418,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2476,7 +2476,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#.g %d", 9.75, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2493,7 +2493,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2502,8 +2502,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%050g %d", NaNd (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2512,7 +2512,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.g %d", 1234.0, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -2545,105 +2545,105 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", 1234567.0L, 33, 44, 55); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); } { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.23432e-37" }, - { 1.234321234321234e-36L, "1.23432e-36" }, - { 1.234321234321234e-35L, "1.23432e-35" }, - { 1.234321234321234e-34L, "1.23432e-34" }, - { 1.234321234321234e-33L, "1.23432e-33" }, - { 1.234321234321234e-32L, "1.23432e-32" }, - { 1.234321234321234e-31L, "1.23432e-31" }, - { 1.234321234321234e-30L, "1.23432e-30" }, - { 1.234321234321234e-29L, "1.23432e-29" }, - { 1.234321234321234e-28L, "1.23432e-28" }, - { 1.234321234321234e-27L, "1.23432e-27" }, - { 1.234321234321234e-26L, "1.23432e-26" }, - { 1.234321234321234e-25L, "1.23432e-25" }, - { 1.234321234321234e-24L, "1.23432e-24" }, - { 1.234321234321234e-23L, "1.23432e-23" }, - { 1.234321234321234e-22L, "1.23432e-22" }, - { 1.234321234321234e-21L, "1.23432e-21" }, - { 1.234321234321234e-20L, "1.23432e-20" }, - { 1.234321234321234e-19L, "1.23432e-19" }, - { 1.234321234321234e-18L, "1.23432e-18" }, - { 1.234321234321234e-17L, "1.23432e-17" }, - { 1.234321234321234e-16L, "1.23432e-16" }, - { 1.234321234321234e-15L, "1.23432e-15" }, - { 1.234321234321234e-14L, "1.23432e-14" }, - { 1.234321234321234e-13L, "1.23432e-13" }, - { 1.234321234321234e-12L, "1.23432e-12" }, - { 1.234321234321234e-11L, "1.23432e-11" }, - { 1.234321234321234e-10L, "1.23432e-10" }, - { 1.234321234321234e-9L, "1.23432e-09" }, - { 1.234321234321234e-8L, "1.23432e-08" }, - { 1.234321234321234e-7L, "1.23432e-07" }, - { 1.234321234321234e-6L, "1.23432e-06" }, - { 1.234321234321234e-5L, "1.23432e-05" }, - { 1.234321234321234e-4L, "0.000123432" }, - { 1.234321234321234e-3L, "0.00123432" }, - { 1.234321234321234e-2L, "0.0123432" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.23432" }, - { 1.234321234321234e1L, "12.3432" }, - { 1.234321234321234e2L, "123.432" }, - { 1.234321234321234e3L, "1234.32" }, - { 1.234321234321234e4L, "12343.2" }, - { 1.234321234321234e5L, "123432" }, - { 1.234321234321234e6L, "1.23432e+06" }, - { 1.234321234321234e7L, "1.23432e+07" }, - { 1.234321234321234e8L, "1.23432e+08" }, - { 1.234321234321234e9L, "1.23432e+09" }, - { 1.234321234321234e10L, "1.23432e+10" }, - { 1.234321234321234e11L, "1.23432e+11" }, - { 1.234321234321234e12L, "1.23432e+12" }, - { 1.234321234321234e13L, "1.23432e+13" }, - { 1.234321234321234e14L, "1.23432e+14" }, - { 1.234321234321234e15L, "1.23432e+15" }, - { 1.234321234321234e16L, "1.23432e+16" }, - { 1.234321234321234e17L, "1.23432e+17" }, - { 1.234321234321234e18L, "1.23432e+18" }, - { 1.234321234321234e19L, "1.23432e+19" }, - { 1.234321234321234e20L, "1.23432e+20" }, - { 1.234321234321234e21L, "1.23432e+21" }, - { 1.234321234321234e22L, "1.23432e+22" }, - { 1.234321234321234e23L, "1.23432e+23" }, - { 1.234321234321234e24L, "1.23432e+24" }, - { 1.234321234321234e25L, "1.23432e+25" }, - { 1.234321234321234e26L, "1.23432e+26" }, - { 1.234321234321234e27L, "1.23432e+27" }, - { 1.234321234321234e28L, "1.23432e+28" }, - { 1.234321234321234e29L, "1.23432e+29" }, - { 1.234321234321234e30L, "1.23432e+30" }, - { 1.234321234321234e31L, "1.23432e+31" }, - { 1.234321234321234e32L, "1.23432e+32" }, - { 1.234321234321234e33L, "1.23432e+33" }, - { 1.234321234321234e34L, "1.23432e+34" }, - { 1.234321234321234e35L, "1.23432e+35" }, - { 1.234321234321234e36L, "1.23432e+36" } + { 1.234321234321234e-37L, "1.23432e-37" }, + { 1.234321234321234e-36L, "1.23432e-36" }, + { 1.234321234321234e-35L, "1.23432e-35" }, + { 1.234321234321234e-34L, "1.23432e-34" }, + { 1.234321234321234e-33L, "1.23432e-33" }, + { 1.234321234321234e-32L, "1.23432e-32" }, + { 1.234321234321234e-31L, "1.23432e-31" }, + { 1.234321234321234e-30L, "1.23432e-30" }, + { 1.234321234321234e-29L, "1.23432e-29" }, + { 1.234321234321234e-28L, "1.23432e-28" }, + { 1.234321234321234e-27L, "1.23432e-27" }, + { 1.234321234321234e-26L, "1.23432e-26" }, + { 1.234321234321234e-25L, "1.23432e-25" }, + { 1.234321234321234e-24L, "1.23432e-24" }, + { 1.234321234321234e-23L, "1.23432e-23" }, + { 1.234321234321234e-22L, "1.23432e-22" }, + { 1.234321234321234e-21L, "1.23432e-21" }, + { 1.234321234321234e-20L, "1.23432e-20" }, + { 1.234321234321234e-19L, "1.23432e-19" }, + { 1.234321234321234e-18L, "1.23432e-18" }, + { 1.234321234321234e-17L, "1.23432e-17" }, + { 1.234321234321234e-16L, "1.23432e-16" }, + { 1.234321234321234e-15L, "1.23432e-15" }, + { 1.234321234321234e-14L, "1.23432e-14" }, + { 1.234321234321234e-13L, "1.23432e-13" }, + { 1.234321234321234e-12L, "1.23432e-12" }, + { 1.234321234321234e-11L, "1.23432e-11" }, + { 1.234321234321234e-10L, "1.23432e-10" }, + { 1.234321234321234e-9L, "1.23432e-09" }, + { 1.234321234321234e-8L, "1.23432e-08" }, + { 1.234321234321234e-7L, "1.23432e-07" }, + { 1.234321234321234e-6L, "1.23432e-06" }, + { 1.234321234321234e-5L, "1.23432e-05" }, + { 1.234321234321234e-4L, "0.000123432" }, + { 1.234321234321234e-3L, "0.00123432" }, + { 1.234321234321234e-2L, "0.0123432" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.23432" }, + { 1.234321234321234e1L, "12.3432" }, + { 1.234321234321234e2L, "123.432" }, + { 1.234321234321234e3L, "1234.32" }, + { 1.234321234321234e4L, "12343.2" }, + { 1.234321234321234e5L, "123432" }, + { 1.234321234321234e6L, "1.23432e+06" }, + { 1.234321234321234e7L, "1.23432e+07" }, + { 1.234321234321234e8L, "1.23432e+08" }, + { 1.234321234321234e9L, "1.23432e+09" }, + { 1.234321234321234e10L, "1.23432e+10" }, + { 1.234321234321234e11L, "1.23432e+11" }, + { 1.234321234321234e12L, "1.23432e+12" }, + { 1.234321234321234e13L, "1.23432e+13" }, + { 1.234321234321234e14L, "1.23432e+14" }, + { 1.234321234321234e15L, "1.23432e+15" }, + { 1.234321234321234e16L, "1.23432e+16" }, + { 1.234321234321234e17L, "1.23432e+17" }, + { 1.234321234321234e18L, "1.23432e+18" }, + { 1.234321234321234e19L, "1.23432e+19" }, + { 1.234321234321234e20L, "1.23432e+20" }, + { 1.234321234321234e21L, "1.23432e+21" }, + { 1.234321234321234e22L, "1.23432e+22" }, + { 1.234321234321234e23L, "1.23432e+23" }, + { 1.234321234321234e24L, "1.23432e+24" }, + { 1.234321234321234e25L, "1.23432e+25" }, + { 1.234321234321234e26L, "1.23432e+26" }, + { 1.234321234321234e27L, "1.23432e+27" }, + { 1.234321234321234e28L, "1.23432e+28" }, + { 1.234321234321234e29L, "1.23432e+29" }, + { 1.234321234321234e30L, "1.23432e+30" }, + { 1.234321234321234e31L, "1.23432e+31" }, + { 1.234321234321234e32L, "1.23432e+32" }, + { 1.234321234321234e33L, "1.23432e+33" }, + { 1.234321234321234e34L, "1.23432e+34" }, + { 1.234321234321234e35L, "1.23432e+35" }, + { 1.234321234321234e36L, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char result[1000]; - int retval = - my_sprintf (result, "%Lg", data[k].value); - const char *expected = data[k].string; - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); + char result[1000]; + int retval = + my_sprintf (result, "%Lg", data[k].value); + const char *expected = data[k].string; + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); } } @@ -2677,7 +2677,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2686,7 +2686,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2695,8 +2695,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) @@ -2707,8 +2707,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { @@ -2719,8 +2719,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%La %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities, @@ -2737,8 +2737,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Infinity. */ @@ -2748,8 +2748,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Zero. */ @@ -2759,8 +2759,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Unnormalized number. */ @@ -2770,8 +2770,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } { /* Pseudo-Denormal. */ @@ -2781,8 +2781,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%Lg %d", x.value, 33, 44, 55); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } #endif @@ -2840,7 +2840,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%#.Lg %d", 9.75L, 33, 44, 55); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); } @@ -2857,7 +2857,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%015Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); } @@ -2866,8 +2866,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); } @@ -2876,7 +2876,7 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) int retval = my_sprintf (result, "%.Lg %d", 1234.0L, 33, 44, 55); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); } @@ -3061,17 +3061,17 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) for (i = 1; i <= 8; i++) { - char *block; - char result[5000]; - int retval; - - block = (char *) malloc (i); - memcpy (block, "abcdefgh", i); - retval = my_sprintf (result, "%.*s", (int) i, block); - ASSERT (memcmp (result, block, i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (retval == strlen (result)); - free (block); + char *block; + char result[5000]; + int retval; + + block = (char *) malloc (i); + memcpy (block, "abcdefgh", i); + retval = my_sprintf (result, "%.*s", (int) i, block); + ASSERT (memcmp (result, block, i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (retval == strlen (result)); + free (block); } } #if HAVE_WCHAR_T @@ -3080,19 +3080,19 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) for (i = 1; i <= 8; i++) { - wchar_t *block; - size_t j; - char result[5000]; - int retval; - - block = (wchar_t *) malloc (i * sizeof (wchar_t)); - for (j = 0; j < i; j++) - block[j] = "abcdefgh"[j]; - retval = my_sprintf (result, "%.*ls", (int) i, block); - ASSERT (memcmp (result, "abcdefgh", i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (retval == strlen (result)); - free (block); + wchar_t *block; + size_t j; + char result[5000]; + int retval; + + block = (wchar_t *) malloc (i * sizeof (wchar_t)); + for (j = 0; j < i; j++) + block[j] = "abcdefgh"[j]; + retval = my_sprintf (result, "%.*ls", (int) i, block); + ASSERT (memcmp (result, "abcdefgh", i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (retval == strlen (result)); + free (block); } } #endif diff --git a/tests/test-strcasestr.c b/tests/test-strcasestr.c index 4abf49a05..8ecd3a9ad 100644 --- a/tests/test-strcasestr.c +++ b/tests/test-strcasestr.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -91,16 +91,16 @@ main () char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = 'B'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (strcasestr (haystack, needle) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (strcasestr (haystack, needle) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -115,15 +115,15 @@ main () char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (strcasestr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (strcasestr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -134,18 +134,18 @@ main () char *needle = (char *) malloc (m + 2); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = '\0'; - memset (needle, 'a', m); - needle[m] = 'B'; - needle[m + 1] = '\0'; + memset (needle, 'a', m); + needle[m] = 'B'; + needle[m + 1] = '\0'; - result = strcasestr (haystack, needle); - ASSERT (result == haystack + m); + result = strcasestr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-strerror.c b/tests/test-strerror.c index 27eb969a7..ba23edc91 100644 --- a/tests/test-strerror.c +++ b/tests/test-strerror.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-striconv.c b/tests/test-striconv.c index f39f142f3..0dc044955 100644 --- a/tests/test-striconv.c +++ b/tests/test-striconv.c @@ -30,15 +30,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -62,7 +62,7 @@ main () char *result = NULL; size_t length = 0; int retval = mem_cd_iconv (input, strlen (input), cd_88591_to_utf8, - &result, &length); + &result, &length); ASSERT (retval == 0); ASSERT (length == strlen (expected)); ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); @@ -76,7 +76,7 @@ main () char *result = NULL; size_t length = 0; int retval = mem_cd_iconv (input, strlen (input), cd_utf8_to_88591, - &result, &length); + &result, &length); ASSERT (retval == 0); ASSERT (length == strlen (expected)); ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); @@ -89,7 +89,7 @@ main () char *result = NULL; size_t length = 0; int retval = mem_cd_iconv (input, strlen (input), cd_utf8_to_88591, - &result, &length); + &result, &length); ASSERT (retval == -1 && errno == EILSEQ); ASSERT (result == NULL); } @@ -100,7 +100,7 @@ main () char *result = NULL; size_t length = 0; int retval = mem_cd_iconv (input, strlen (input), cd_utf8_to_88591, - &result, &length); + &result, &length); ASSERT (retval == 0); ASSERT (length == 0); free (result); diff --git a/tests/test-striconveh.c b/tests/test-striconveh.c index 9e742818b..bd2579ee1 100644 --- a/tests/test-striconveh.c +++ b/tests/test-striconveh.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -128,149 +128,149 @@ main () for (indirect = 0; indirect <= 1; indirect++) { for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; - static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; - for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - (indirect - ? &cdeh_88592_to_88591_indirectly - : &cdeh_88592_to_88591), - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } - } + { + enum iconv_ilseq_handler handler = handlers[h]; + static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; + static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; + for (o = 0; o < 2; o++) + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + (indirect + ? &cdeh_88592_to_88591_indirectly + : &cdeh_88592_to_88591), + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } + } } /* Test conversion from ASCII to ISO-8859-1 with invalid input (EILSEQ). */ for (indirect = 0; indirect <= 1; indirect++) { for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ - for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - (indirect - ? &cdeh_ascii_to_88591_indirectly - : &cdeh_ascii_to_88591), - handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } - } + { + enum iconv_ilseq_handler handler = handlers[h]; + static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ + for (o = 0; o < 2; o++) + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + (indirect + ? &cdeh_ascii_to_88591_indirectly + : &cdeh_ascii_to_88591), + handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } + } } /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ for (indirect = 0; indirect <= 1; indirect++) { for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ - for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - (indirect - ? &cdeh_88592_to_88591_indirectly - : &cdeh_88592_to_88591), - handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i + 5)); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } - } + { + enum iconv_ilseq_handler handler = handlers[h]; + static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ + for (o = 0; o < 2; o++) + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + (indirect + ? &cdeh_88592_to_88591_indirectly + : &cdeh_88592_to_88591), + handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i + 5)); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } + } } /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ @@ -280,30 +280,30 @@ main () static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - &cdeh_88591_to_utf8, - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i < 12 ? i + 1 : - i < 18 ? i + 2 : - i + 3)); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + &cdeh_88591_to_utf8, + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i < 12 ? i + 1 : + i < 18 ? i + 2 : + i + 3)); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ @@ -313,34 +313,34 @@ main () static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - &cdeh_utf8_to_88591, - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 41; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i == 1 ? (size_t)(-1) : - i < 13 ? i - 1 : - i == 13 ? (size_t)(-1) : - i < 20 ? i - 2 : - i == 20 ? (size_t)(-1) : - i < 40 ? i - 3 : - (size_t)(-1))); - ASSERT (offsets[41] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + &cdeh_utf8_to_88591, + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 41; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i == 1 ? (size_t)(-1) : + i < 13 ? i - 1 : + i == 13 ? (size_t)(-1) : + i < 20 ? i - 2 : + i == 20 ? (size_t)(-1) : + i < 40 ? i - 3 : + (size_t)(-1))); + ASSERT (offsets[41] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from ASCII to UTF-8 with invalid input (EILSEQ). */ @@ -349,42 +349,42 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - &cdeh_ascii_to_utf8, - handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + &cdeh_ascii_to_utf8, + handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ @@ -393,61 +393,61 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - &cdeh_utf8_to_88591, - handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i - 1)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i + 4)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + &cdeh_utf8_to_88591, + handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i - 1)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i + 4)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ @@ -456,105 +456,105 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\342"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - &cdeh_utf8_to_88591, - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == 0); - if (o) - { - ASSERT (offsets[0] == 0); - ASSERT (offsets[1] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + &cdeh_utf8_to_88591, + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == 0); + if (o) + { + ASSERT (offsets[0] == 0); + ASSERT (offsets[1] == MAGIC); + free (offsets); + } + free (result); + } } if (cd_utf7_to_utf8 != (iconv_t)(-1)) { /* Disabled on Solaris, because Solaris 9 iconv() is buggy: it returns - -1 / EILSEQ when converting the 7th byte of the input "+VDLYP9hA". */ + -1 / EILSEQ when converting the 7th byte of the input "+VDLYP9hA". */ # if !(defined __sun && !defined _LIBICONV_VERSION) /* Test conversion from UTF-7 to UTF-8 with EINVAL. */ for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - /* This is base64 encoded 0x54 0x32 0xD8 0x3F 0xD8 0x40. It would - convert to U+5432 U+D83F U+D840 but these are Unicode surrogates. */ - static const char input[] = "+VDLYP9hA"; - static const char expected1[] = "\345\220\262"; /* 吲 glibc */ - static const char expected2[] = ""; /* libiconv */ - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, 7, - &cdeh_utf7_to_utf8, - handler, - NULL, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected1) || length == strlen (expected2)); - ASSERT (result != NULL); - if (length == strlen (expected1)) - ASSERT (memcmp (result, expected1, strlen (expected1)) == 0); - else - ASSERT (memcmp (result, expected2, strlen (expected2)) == 0); - free (result); - } + { + enum iconv_ilseq_handler handler = handlers[h]; + /* This is base64 encoded 0x54 0x32 0xD8 0x3F 0xD8 0x40. It would + convert to U+5432 U+D83F U+D840 but these are Unicode surrogates. */ + static const char input[] = "+VDLYP9hA"; + static const char expected1[] = "\345\220\262"; /* 吲 glibc */ + static const char expected2[] = ""; /* libiconv */ + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, 7, + &cdeh_utf7_to_utf8, + handler, + NULL, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected1) || length == strlen (expected2)); + ASSERT (result != NULL); + if (length == strlen (expected1)) + ASSERT (memcmp (result, expected1, strlen (expected1)) == 0); + else + ASSERT (memcmp (result, expected2, strlen (expected2)) == 0); + free (result); + } /* Test conversion from UTF-7 to UTF-8 with EILSEQ. */ for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - /* This is base64 encoded 0xD8 0x3F 0xD8 0x40 0xD8 0x41. It would - convert to U+D83F U+D840 U+D841 but these are Unicode surrogates. */ - static const char input[] = "+2D/YQNhB"; - char *result = NULL; - size_t length = 0; - int retval = mem_cd_iconveh (input, strlen (input), - &cdeh_utf7_to_utf8, - handler, - NULL, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - break; - case iconveh_question_mark: - case iconveh_escape_sequence: - { - /* glibc result */ - static const char expected1[] = "?????"; - /* libiconv <= 1.12 result */ - static const char expected2[] = "?2D/YQNhB"; - /* libiconv behaviour changed in version 1.13: the result is - '?' U+0FF6 U+1036; this is U+D83F U+D840 U+D841 shifted left - by 6 bits. */ - static const char expected3[] = "?\340\277\266\341\200\266"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected1) - || length == strlen (expected2) - || length == strlen (expected3)); - ASSERT (result != NULL); - if (length == strlen (expected1)) - ASSERT (memcmp (result, expected1, strlen (expected1)) == 0); - else if (length == strlen (expected2)) - ASSERT (memcmp (result, expected2, strlen (expected2)) == 0); - else - ASSERT (memcmp (result, expected3, strlen (expected3)) == 0); - free (result); - } - break; - } - } + { + enum iconv_ilseq_handler handler = handlers[h]; + /* This is base64 encoded 0xD8 0x3F 0xD8 0x40 0xD8 0x41. It would + convert to U+D83F U+D840 U+D841 but these are Unicode surrogates. */ + static const char input[] = "+2D/YQNhB"; + char *result = NULL; + size_t length = 0; + int retval = mem_cd_iconveh (input, strlen (input), + &cdeh_utf7_to_utf8, + handler, + NULL, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + break; + case iconveh_question_mark: + case iconveh_escape_sequence: + { + /* glibc result */ + static const char expected1[] = "?????"; + /* libiconv <= 1.12 result */ + static const char expected2[] = "?2D/YQNhB"; + /* libiconv behaviour changed in version 1.13: the result is + '?' U+0FF6 U+1036; this is U+D83F U+D840 U+D841 shifted left + by 6 bits. */ + static const char expected3[] = "?\340\277\266\341\200\266"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected1) + || length == strlen (expected2) + || length == strlen (expected3)); + ASSERT (result != NULL); + if (length == strlen (expected1)) + ASSERT (memcmp (result, expected1, strlen (expected1)) == 0); + else if (length == strlen (expected2)) + ASSERT (memcmp (result, expected2, strlen (expected2)) == 0); + else + ASSERT (memcmp (result, expected3, strlen (expected3)) == 0); + free (result); + } + break; + } + } # endif } @@ -564,86 +564,86 @@ main () for (indirect = 0; indirect <= 1; indirect++) { for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; - static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; - char *result = str_cd_iconveh (input, - (indirect - ? &cdeh_88592_to_88591_indirectly - : &cdeh_88592_to_88591), - handler); - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } + { + enum iconv_ilseq_handler handler = handlers[h]; + static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; + static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; + char *result = str_cd_iconveh (input, + (indirect + ? &cdeh_88592_to_88591_indirectly + : &cdeh_88592_to_88591), + handler); + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } } /* Test conversion from ASCII to ISO-8859-1 with invalid input (EILSEQ). */ for (indirect = 0; indirect <= 1; indirect++) { for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ - char *result = str_cd_iconveh (input, - (indirect - ? &cdeh_ascii_to_88591_indirectly - : &cdeh_ascii_to_88591), - handler); - switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } - } + { + enum iconv_ilseq_handler handler = handlers[h]; + static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ + char *result = str_cd_iconveh (input, + (indirect + ? &cdeh_ascii_to_88591_indirectly + : &cdeh_ascii_to_88591), + handler); + switch (handler) + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } + } } /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ for (indirect = 0; indirect <= 1; indirect++) { for (h = 0; h < SIZEOF (handlers); h++) - { - enum iconv_ilseq_handler handler = handlers[h]; - static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ - char *result = str_cd_iconveh (input, - (indirect - ? &cdeh_88592_to_88591_indirectly - : &cdeh_88592_to_88591), - handler); - switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } - } + { + enum iconv_ilseq_handler handler = handlers[h]; + static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ + char *result = str_cd_iconveh (input, + (indirect + ? &cdeh_88592_to_88591_indirectly + : &cdeh_88592_to_88591), + handler); + switch (handler) + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } + } } /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ @@ -653,8 +653,8 @@ main () static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; char *result = str_cd_iconveh (input, - &cdeh_88591_to_utf8, - handler); + &cdeh_88591_to_utf8, + handler); ASSERT (result != NULL); ASSERT (strcmp (result, expected) == 0); free (result); @@ -667,8 +667,8 @@ main () static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; char *result = str_cd_iconveh (input, - &cdeh_utf8_to_88591, - handler); + &cdeh_utf8_to_88591, + handler); ASSERT (result != NULL); ASSERT (strcmp (result, expected) == 0); free (result); @@ -680,23 +680,23 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafa? Maszkowski */ char *result = str_cd_iconveh (input, - &cdeh_ascii_to_utf8, - handler); + &cdeh_ascii_to_utf8, + handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ @@ -705,30 +705,30 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ char *result = str_cd_iconveh (input, - &cdeh_utf8_to_88591, - handler); + &cdeh_utf8_to_88591, + handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Costs: 27 ?"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Costs: 27 \\u20AC"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Costs: 27 ?"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Costs: 27 \\u20AC"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ @@ -737,8 +737,8 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\342"; char *result = str_cd_iconveh (input, - &cdeh_utf8_to_88591, - handler); + &cdeh_utf8_to_88591, + handler); ASSERT (result != NULL); ASSERT (strcmp (result, "") == 0); free (result); @@ -762,27 +762,27 @@ main () static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveh (input, strlen (input), - "ISO-8859-2", "ISO-8859-1", - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveh (input, strlen (input), + "ISO-8859-2", "ISO-8859-1", + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ @@ -791,58 +791,58 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveh (input, strlen (input), - "ISO-8859-2", "ISO-8859-1", - handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i + 5)); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveh (input, strlen (input), + "ISO-8859-2", "ISO-8859-1", + handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i + 5)); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ @@ -852,30 +852,30 @@ main () static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveh (input, strlen (input), - "ISO-8859-1", "UTF-8", - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i < 12 ? i + 1 : - i < 18 ? i + 2 : - i + 3)); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveh (input, strlen (input), + "ISO-8859-1", "UTF-8", + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i < 12 ? i + 1 : + i < 18 ? i + 2 : + i + 3)); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ @@ -885,34 +885,34 @@ main () static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveh (input, strlen (input), - "UTF-8", "ISO-8859-1", - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 41; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i == 1 ? (size_t)(-1) : - i < 13 ? i - 1 : - i == 13 ? (size_t)(-1) : - i < 20 ? i - 2 : - i == 20 ? (size_t)(-1) : - i < 40 ? i - 3 : - (size_t)(-1))); - ASSERT (offsets[41] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveh (input, strlen (input), + "UTF-8", "ISO-8859-1", + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 41; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i == 1 ? (size_t)(-1) : + i < 13 ? i - 1 : + i == 13 ? (size_t)(-1) : + i < 20 ? i - 2 : + i == 20 ? (size_t)(-1) : + i < 40 ? i - 3 : + (size_t)(-1))); + ASSERT (offsets[41] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ @@ -921,61 +921,61 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveh (input, strlen (input), - "UTF-8", "ISO-8859-1", - handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i - 1)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i + 4)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveh (input, strlen (input), + "UTF-8", "ISO-8859-1", + handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i - 1)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i + 4)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ @@ -984,25 +984,25 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\342"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveh (input, strlen (input), - "UTF-8", "ISO-8859-1", - handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == 0); - if (o) - { - ASSERT (offsets[0] == 0); - ASSERT (offsets[1] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveh (input, strlen (input), + "UTF-8", "ISO-8859-1", + handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == 0); + if (o) + { + ASSERT (offsets[0] == 0); + ASSERT (offsets[1] == MAGIC); + free (offsets); + } + free (result); + } } /* ------------------------- Test str_iconveh() ------------------------- */ @@ -1026,27 +1026,27 @@ main () static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ char *result = str_iconveh (input, "ISO-8859-2", "ISO-8859-1", handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ @@ -1080,27 +1080,27 @@ main () static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ char *result = str_iconveh (input, "UTF-8", "ISO-8859-1", handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Costs: 27 ?"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Costs: 27 \\u20AC"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Costs: 27 ?"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Costs: 27 \\u20AC"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ diff --git a/tests/test-striconveha.c b/tests/test-striconveha.c index 47e9a46e0..96660b260 100644 --- a/tests/test-striconveha.c +++ b/tests/test-striconveha.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -75,27 +75,27 @@ main () static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "ISO-8859-2", "ISO-8859-1", - false, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "ISO-8859-2", "ISO-8859-1", + false, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from ISO-8859-2 to ISO-8859-1 with EILSEQ. */ @@ -104,58 +104,58 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "ISO-8859-2", "ISO-8859-1", - false, handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i + 5)); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "ISO-8859-2", "ISO-8859-1", + false, handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i + 5)); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ @@ -165,30 +165,30 @@ main () static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const char expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "ISO-8859-1", "UTF-8", - false, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i < 12 ? i + 1 : - i < 18 ? i + 2 : - i + 3)); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "ISO-8859-1", "UTF-8", + false, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i < 12 ? i + 1 : + i < 18 ? i + 2 : + i + 3)); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-8 to ISO-8859-1 with no errors. */ @@ -198,34 +198,34 @@ main () static const char input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "UTF-8", "ISO-8859-1", - false, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 41; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i == 1 ? (size_t)(-1) : - i < 13 ? i - 1 : - i == 13 ? (size_t)(-1) : - i < 20 ? i - 2 : - i == 20 ? (size_t)(-1) : - i < 40 ? i - 3 : - (size_t)(-1))); - ASSERT (offsets[41] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "UTF-8", "ISO-8859-1", + false, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 41; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i == 1 ? (size_t)(-1) : + i < 13 ? i - 1 : + i == 13 ? (size_t)(-1) : + i < 20 ? i - 2 : + i == 20 ? (size_t)(-1) : + i < 40 ? i - 3 : + (size_t)(-1))); + ASSERT (offsets[41] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ @@ -234,61 +234,61 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "UTF-8", "ISO-8859-1", - false, handler, - offsets, - &result, &length); - switch (handler) - { - case iconveh_error: - ASSERT (retval == -1 && errno == EILSEQ); - ASSERT (result == NULL); - if (o) - free (offsets); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i - 1)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i + 4)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "UTF-8", "ISO-8859-1", + false, handler, + offsets, + &result, &length); + switch (handler) + { + case iconveh_error: + ASSERT (retval == -1 && errno == EILSEQ); + ASSERT (result == NULL); + if (o) + free (offsets); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i - 1)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i + 4)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ @@ -297,25 +297,25 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\342"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "UTF-8", "ISO-8859-1", - false, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == 0); - if (o) - { - ASSERT (offsets[0] == 0); - ASSERT (offsets[1] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "UTF-8", "ISO-8859-1", + false, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == 0); + if (o) + { + ASSERT (offsets[0] == 0); + ASSERT (offsets[1] == MAGIC); + free (offsets); + } + free (result); + } } /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ @@ -327,27 +327,27 @@ main () static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "autodetect_jp", "UTF-8", - false, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "autodetect_jp", "UTF-8", + false, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { @@ -355,27 +355,27 @@ main () static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "autodetect_jp", "UTF-8", - false, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "autodetect_jp", "UTF-8", + false, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { @@ -383,33 +383,33 @@ main () static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ static const char expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "autodetect_jp", "UTF-8", - false, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i == 0 ? 0 : - i == 5 ? 3 : - i == 7 ? 6 : - i == 9 ? 9 : - i == 11 ? 12 : - i == 13 ? 15 : - (size_t)(-1))); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "autodetect_jp", "UTF-8", + false, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i == 0 ? 0 : + i == 5 ? 3 : + i == 7 ? 6 : + i == 9 ? 9 : + i == 11 ? 12 : + i == 13 ? 15 : + (size_t)(-1))); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } } # endif @@ -421,27 +421,27 @@ main () static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ static const char expected[] = "Costs: 27 EUR"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - char *result = NULL; - size_t length = 0; - int retval = mem_iconveha (input, strlen (input), - "UTF-8", "ISO-8859-1", - true, handler, - offsets, - &result, &length); - ASSERT (retval == 0); - ASSERT (length == strlen (expected)); - ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 13; i++) - ASSERT (offsets[i] == (i < 11 ? i : (size_t)(-1))); - ASSERT (offsets[13] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + char *result = NULL; + size_t length = 0; + int retval = mem_iconveha (input, strlen (input), + "UTF-8", "ISO-8859-1", + true, handler, + offsets, + &result, &length); + ASSERT (retval == 0); + ASSERT (length == strlen (expected)); + ASSERT (result != NULL && memcmp (result, expected, strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 13; i++) + ASSERT (offsets[i] == (i < 11 ? i : (size_t)(-1))); + ASSERT (offsets[13] == MAGIC); + free (offsets); + } + free (result); + } } # endif @@ -466,27 +466,27 @@ main () static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ char *result = str_iconveha (input, "ISO-8859-2", "ISO-8859-1", false, handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } /* Test conversion from ISO-8859-1 to UTF-8 with no errors. */ @@ -520,27 +520,27 @@ main () static const char input[] = "Costs: 27 \342\202\254"; /* EURO SIGN */ char *result = str_iconveha (input, "UTF-8", "ISO-8859-1", false, handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Costs: 27 ?"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Costs: 27 \\u20AC"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Costs: 27 ?"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Costs: 27 \\u20AC"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ diff --git a/tests/test-strsignal.c b/tests/test-strsignal.c index a4be4b7a7..3b362dd19 100644 --- a/tests/test-strsignal.c +++ b/tests/test-strsignal.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #if HAVE_DECL_SYS_SIGLIST diff --git a/tests/test-strstr.c b/tests/test-strstr.c index 37f4bace6..c89a1ace4 100644 --- a/tests/test-strstr.c +++ b/tests/test-strstr.c @@ -27,15 +27,15 @@ #include "zerosize-ptr.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -111,16 +111,16 @@ main (int argc, char *argv[]) char *haystack = (char *) malloc (m + 1); if (haystack != NULL) { - memset (haystack, 'A', m); - haystack[0] = 'B'; - haystack[m] = '\0'; + memset (haystack, 'A', m); + haystack[0] = 'B'; + haystack[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (strstr (haystack, needle) == haystack + 1); - } + for (; repeat > 0; repeat--) + { + ASSERT (strstr (haystack, needle) == haystack + 1); + } - free (haystack); + free (haystack); } } @@ -135,15 +135,15 @@ main (int argc, char *argv[]) char *needle = (char *) malloc (m + 1); if (needle != NULL) { - memset (needle, 'A', m); - needle[m] = '\0'; + memset (needle, 'A', m); + needle[m] = '\0'; - for (; repeat > 0; repeat--) - { - ASSERT (strstr (haystack, needle) == NULL); - } + for (; repeat > 0; repeat--) + { + ASSERT (strstr (haystack, needle) == NULL); + } - free (needle); + free (needle); } } @@ -154,18 +154,18 @@ main (int argc, char *argv[]) char *needle = (char *) malloc (m + 2); if (haystack != NULL && needle != NULL) { - const char *result; + const char *result; - memset (haystack, 'A', 2 * m); - haystack[2 * m] = 'B'; - haystack[2 * m + 1] = '\0'; + memset (haystack, 'A', 2 * m); + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = '\0'; - memset (needle, 'A', m); - needle[m] = 'B'; - needle[m + 1] = '\0'; + memset (needle, 'A', m); + needle[m] = 'B'; + needle[m + 1] = '\0'; - result = strstr (haystack, needle); - ASSERT (result == haystack + m); + result = strstr (haystack, needle); + ASSERT (result == haystack + m); } free (needle); free (haystack); diff --git a/tests/test-strtod.c b/tests/test-strtod.c index 69dd4749e..14f73b9ca 100644 --- a/tests/test-strtod.c +++ b/tests/test-strtod.c @@ -28,15 +28,15 @@ #include "isnand-nolibm.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - /* FIXME abort ();*/status = 1; \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + /* FIXME abort ();*/status = 1; \ + } \ + } \ while (0) /* Avoid requiring -lm just for fabs. */ @@ -806,16 +806,16 @@ main (void) char *input = malloc (m + 1); if (input) { - char *ptr; - double result; - memset (input, '\t', m - 1); - input[m - 1] = '1'; - input[m] = '\0'; - errno = 0; - result = strtod (input, &ptr); - ASSERT (result == 1.0); - ASSERT (ptr == input + m); - ASSERT (errno == 0); + char *ptr; + double result; + memset (input, '\t', m - 1); + input[m - 1] = '1'; + input[m] = '\0'; + errno = 0; + result = strtod (input, &ptr); + ASSERT (result == 1.0); + ASSERT (ptr == input + m); + ASSERT (errno == 0); } free (input); } @@ -824,16 +824,16 @@ main (void) char *input = malloc (m + 1); if (input) { - char *ptr; - double result; - memset (input, '0', m - 1); - input[m - 1] = '1'; - input[m] = '\0'; - errno = 0; - result = strtod (input, &ptr); - ASSERT (result == 1.0); - ASSERT (ptr == input + m); - ASSERT (errno == 0); + char *ptr; + double result; + memset (input, '0', m - 1); + input[m - 1] = '1'; + input[m] = '\0'; + errno = 0; + result = strtod (input, &ptr); + ASSERT (result == 1.0); + ASSERT (ptr == input + m); + ASSERT (errno == 0); } free (input); } @@ -845,25 +845,25 @@ main (void) char *input = malloc (m + 1); if (input) { - char *ptr; - double result; - input[0] = '.'; - memset (input + 1, '0', m - 10); - input[m - 9] = '1'; - input[m - 8] = 'e'; - input[m - 7] = '+'; - input[m - 6] = '9'; - input[m - 5] = '9'; - input[m - 4] = '9'; - input[m - 3] = '9'; - input[m - 2] = '9'; - input[m - 1] = '1'; - input[m] = '\0'; - errno = 0; - result = strtod (input, &ptr); - ASSERT (result == 1.0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ - ASSERT (ptr == input + m); /* OSF/1 5.1 */ - ASSERT (errno == 0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ + char *ptr; + double result; + input[0] = '.'; + memset (input + 1, '0', m - 10); + input[m - 9] = '1'; + input[m - 8] = 'e'; + input[m - 7] = '+'; + input[m - 6] = '9'; + input[m - 5] = '9'; + input[m - 4] = '9'; + input[m - 3] = '9'; + input[m - 2] = '9'; + input[m - 1] = '1'; + input[m] = '\0'; + errno = 0; + result = strtod (input, &ptr); + ASSERT (result == 1.0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ + ASSERT (ptr == input + m); /* OSF/1 5.1 */ + ASSERT (errno == 0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ } free (input); } @@ -872,24 +872,24 @@ main (void) char *input = malloc (m + 1); if (input) { - char *ptr; - double result; - input[0] = '1'; - memset (input + 1, '0', m - 9); - input[m - 8] = 'e'; - input[m - 7] = '-'; - input[m - 6] = '9'; - input[m - 5] = '9'; - input[m - 4] = '9'; - input[m - 3] = '9'; - input[m - 2] = '9'; - input[m - 1] = '1'; - input[m] = '\0'; - errno = 0; - result = strtod (input, &ptr); - ASSERT (result == 1.0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ - ASSERT (ptr == input + m); - ASSERT (errno == 0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ + char *ptr; + double result; + input[0] = '1'; + memset (input + 1, '0', m - 9); + input[m - 8] = 'e'; + input[m - 7] = '-'; + input[m - 6] = '9'; + input[m - 5] = '9'; + input[m - 4] = '9'; + input[m - 3] = '9'; + input[m - 2] = '9'; + input[m - 1] = '1'; + input[m] = '\0'; + errno = 0; + result = strtod (input, &ptr); + ASSERT (result == 1.0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ + ASSERT (ptr == input + m); + ASSERT (errno == 0); /* MacOS X 10.3, FreeBSD 6.2, NetBSD 3.0, OpenBSD 4.0, IRIX 6.5, OSF/1 5.1, mingw */ } free (input); } @@ -899,20 +899,20 @@ main (void) char *input = malloc (m + 1); if (input) { - char *ptr; - double result; - input[0] = '-'; - input[1] = '0'; - input[2] = 'e'; - input[3] = '1'; - memset (input + 4, '0', m - 3); - input[m] = '\0'; - errno = 0; - result = strtod (input, &ptr); - ASSERT (result == 0.0); - ASSERT (!!signbit (result) == !!signbit (-zero)); /* IRIX 6.5, OSF/1 4.0 */ - ASSERT (ptr == input + m); - ASSERT (errno == 0); + char *ptr; + double result; + input[0] = '-'; + input[1] = '0'; + input[2] = 'e'; + input[3] = '1'; + memset (input + 4, '0', m - 3); + input[m] = '\0'; + errno = 0; + result = strtod (input, &ptr); + ASSERT (result == 0.0); + ASSERT (!!signbit (result) == !!signbit (-zero)); /* IRIX 6.5, OSF/1 4.0 */ + ASSERT (ptr == input + m); + ASSERT (errno == 0); } free (input); } diff --git a/tests/test-strverscmp.c b/tests/test-strverscmp.c index a98695baa..220f2d6f6 100644 --- a/tests/test-strverscmp.c +++ b/tests/test-strverscmp.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/test-symlink.c b/tests/test-symlink.c index 26e97d017..4b593b653 100644 --- a/tests/test-symlink.c +++ b/tests/test-symlink.c @@ -31,11 +31,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-symlinkat.c b/tests/test-symlinkat.c index 993087204..c76244f31 100644 --- a/tests/test-symlinkat.c +++ b/tests/test-symlinkat.c @@ -36,11 +36,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) @@ -118,6 +118,6 @@ main (void) ASSERT (close (dfd) == 0); if (result == 77) fputs ("skipping test: symlinks not supported on this file system\n", - stderr); + stderr); return result; } diff --git a/tests/test-times.c b/tests/test-times.c index 377a1392c..496b9a825 100644 --- a/tests/test-times.c +++ b/tests/test-times.c @@ -72,7 +72,7 @@ main (int argc, char *argv[]) base = malloc (size * sizeof (double)); for (i = 0; i < size; i++) - base[i] = i * i; + base[i] = i * i; qsort (base, size, sizeof (double), doublecmp); diff --git a/tests/test-tls.c b/tests/test-tls.c index 5a73f72a3..9cdfe1de3 100644 --- a/tests/test-tls.c +++ b/tests/test-tls.c @@ -97,7 +97,7 @@ worker_thread (void *arg) values[i] = (((unsigned int) rand() >> 3) % 1000000) * THREAD_COUNT + id; /* Hopefully no arithmetic overflow. */ if ((values[i] % THREAD_COUNT) != id) - abort (); + abort (); } perhaps_yield (); @@ -127,13 +127,13 @@ worker_thread (void *arg) i = ((unsigned int) rand() >> 3) % KEYS_COUNT; j = ((unsigned int) rand() >> 3) % KEYS_COUNT; if (i != j) - { - void *vi = gl_tls_get (mykeys[i]); - void *vj = gl_tls_get (mykeys[j]); + { + void *vi = gl_tls_get (mykeys[i]); + void *vj = gl_tls_get (mykeys[j]); - gl_tls_set (mykeys[i], vj); - gl_tls_set (mykeys[j], vi); - } + gl_tls_set (mykeys[i], vj); + gl_tls_set (mykeys[j], vi); + } perhaps_yield (); } @@ -159,22 +159,22 @@ test_tls (void) gl_thread_t threads[THREAD_COUNT]; if (pass == 0) - for (i = 0; i < KEYS_COUNT; i++) - gl_tls_key_init (mykeys[i], free); + for (i = 0; i < KEYS_COUNT; i++) + gl_tls_key_init (mykeys[i], free); else - for (i = KEYS_COUNT - 1; i >= 0; i--) - gl_tls_key_init (mykeys[i], free); + for (i = KEYS_COUNT - 1; i >= 0; i--) + gl_tls_key_init (mykeys[i], free); /* Spawn the threads. */ for (i = 0; i < THREAD_COUNT; i++) - threads[i] = gl_thread_create (worker_thread, NULL); + threads[i] = gl_thread_create (worker_thread, NULL); /* Wait for the threads to terminate. */ for (i = 0; i < THREAD_COUNT; i++) - gl_thread_join (threads[i], NULL); + gl_thread_join (threads[i], NULL); for (i = 0; i < KEYS_COUNT; i++) - gl_tls_key_destroy (mykeys[i]); + gl_tls_key_destroy (mykeys[i]); } } diff --git a/tests/test-trunc1.c b/tests/test-trunc1.c index b9e8a3c88..671d3f5b5 100644 --- a/tests/test-trunc1.c +++ b/tests/test-trunc1.c @@ -27,15 +27,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0. diff --git a/tests/test-trunc2.c b/tests/test-trunc2.c index b13433faa..f704bcb1e 100644 --- a/tests/test-trunc2.c +++ b/tests/test-trunc2.c @@ -29,15 +29,15 @@ #include "isnand-nolibm.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) @@ -74,27 +74,27 @@ trunc_reference (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; } @@ -114,11 +114,11 @@ correct_result_p (DOUBLE x, DOUBLE result) return (x >= 0 ? (x < 1 ? result == L_(0.0) : - x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 : - equal (result, x)) + x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 : + equal (result, x)) : (x > -1 ? result == L_(0.0) : - x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 : - equal (result, x))); + x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 : + equal (result, x))); } /* Test the function for a given argument. */ @@ -135,9 +135,9 @@ check (double x) return 0; else { - fprintf (stderr, "trunc %g(%a) = %g(%a) or %g(%a)?\n", - x, x, reference, reference, result, result); - return 1; + fprintf (stderr, "trunc %g(%a) = %g(%a) or %g(%a)?\n", + x, x, reference, reference, result, result); + return 1; } } } @@ -154,14 +154,14 @@ main () for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++) for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++) { - /* Combine highbits and lowbits into a floating-point number, - sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ - union { double f; uint64_t i; } janus; - janus.i = ((uint64_t) highbits << (64 - NUM_HIGHBITS)) - | ((uint64_t) ((int64_t) ((uint64_t) lowbits << (64 - NUM_LOWBITS)) - >> (64 - NUM_LOWBITS - NUM_HIGHBITS)) - >> NUM_HIGHBITS); - error |= check (janus.f); + /* Combine highbits and lowbits into a floating-point number, + sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ + union { double f; uint64_t i; } janus; + janus.i = ((uint64_t) highbits << (64 - NUM_HIGHBITS)) + | ((uint64_t) ((int64_t) ((uint64_t) lowbits << (64 - NUM_LOWBITS)) + >> (64 - NUM_LOWBITS - NUM_HIGHBITS)) + >> NUM_HIGHBITS); + error |= check (janus.f); } return (error ? 1 : 0); } diff --git a/tests/test-truncf1.c b/tests/test-truncf1.c index a9abed443..834899b58 100644 --- a/tests/test-truncf1.c +++ b/tests/test-truncf1.c @@ -27,15 +27,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f. diff --git a/tests/test-truncf2.c b/tests/test-truncf2.c index dd849ab20..91ebb74af 100644 --- a/tests/test-truncf2.c +++ b/tests/test-truncf2.c @@ -29,15 +29,15 @@ #include "isnanf-nolibm.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) @@ -74,27 +74,27 @@ truncf_reference (DOUBLE x) { /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z += TWO_MANT_DIG; - z -= TWO_MANT_DIG; - /* Enforce rounding down. */ - if (z > y) - z -= L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z += TWO_MANT_DIG; + z -= TWO_MANT_DIG; + /* Enforce rounding down. */ + if (z > y) + z -= L_(1.0); + } } else if (z < L_(0.0)) { /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) - { - /* Round to the next integer (nearest or up or down, doesn't matter). */ - z -= TWO_MANT_DIG; - z += TWO_MANT_DIG; - /* Enforce rounding up. */ - if (z < y) - z += L_(1.0); - } + { + /* Round to the next integer (nearest or up or down, doesn't matter). */ + z -= TWO_MANT_DIG; + z += TWO_MANT_DIG; + /* Enforce rounding up. */ + if (z < y) + z += L_(1.0); + } } return z; } @@ -114,11 +114,11 @@ correct_result_p (DOUBLE x, DOUBLE result) return (x >= 0 ? (x < 1 ? result == L_(0.0) : - x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 : - equal (result, x)) + x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 : + equal (result, x)) : (x > -1 ? result == L_(0.0) : - x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 : - equal (result, x))); + x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 : + equal (result, x))); } /* Test the function for a given argument. */ @@ -135,9 +135,9 @@ check (float x) return 0; else { - fprintf (stderr, "truncf %g(%a) = %g(%a) or %g(%a)?\n", - x, x, reference, reference, result, result); - return 1; + fprintf (stderr, "truncf %g(%a) = %g(%a) or %g(%a)?\n", + x, x, reference, reference, result, result); + return 1; } } } @@ -154,14 +154,14 @@ main () for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++) for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++) { - /* Combine highbits and lowbits into a floating-point number, - sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ - union { float f; uint32_t i; } janus; - janus.i = ((uint32_t) highbits << (32 - NUM_HIGHBITS)) - | ((uint32_t) ((int32_t) ((uint32_t) lowbits << (32 - NUM_LOWBITS)) - >> (32 - NUM_LOWBITS - NUM_HIGHBITS)) - >> NUM_HIGHBITS); - error |= check (janus.f); + /* Combine highbits and lowbits into a floating-point number, + sign-extending the lowbits to 32-NUM_HIGHBITS bits. */ + union { float f; uint32_t i; } janus; + janus.i = ((uint32_t) highbits << (32 - NUM_HIGHBITS)) + | ((uint32_t) ((int32_t) ((uint32_t) lowbits << (32 - NUM_LOWBITS)) + >> (32 - NUM_LOWBITS - NUM_HIGHBITS)) + >> NUM_HIGHBITS); + error |= check (janus.f); } return (error ? 1 : 0); } diff --git a/tests/test-truncl.c b/tests/test-truncl.c index f8ce551e9..7e3dd1793 100644 --- a/tests/test-truncl.c +++ b/tests/test-truncl.c @@ -29,15 +29,15 @@ #include "nan.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* On HP-UX 10.20, negating 0.0L does not yield -0.0L. diff --git a/tests/test-tsearch.c b/tests/test-tsearch.c index eb465e834..273f3ab31 100644 --- a/tests/test-tsearch.c +++ b/tests/test-tsearch.c @@ -120,10 +120,10 @@ walk_action (const void *nodep, const VISIT which, const int depth) else { if (depths[key] != depth) - { - fputs ("Depth for one element is not constant during tree walk.\n", - stdout); - } + { + fputs ("Depth for one element is not constant during tree walk.\n", + stdout); + } } } @@ -139,8 +139,8 @@ walk_tree (void *root, int expected_count) for (i = 0; i < expected_count; ++i) if (z[i] != 1) { - fputs ("Node was not visited.\n", stdout); - error = 1; + fputs ("Node was not visited.\n", stdout); + error = 1; } #if BALANCED @@ -163,7 +163,7 @@ mangle_tree (enum order how, enum action what, void **root, int lag) if (how == randomorder) { for (i = 0; i < SIZE; ++i) - y[i] = i; + y[i] = i; memfry (y); } @@ -173,77 +173,77 @@ mangle_tree (enum order how, enum action what, void **root, int lag) int j, k; switch (how) - { - case randomorder: - if (i >= lag) - k = y[i - lag]; - else - /* Ensure that the array index is within bounds. */ - k = y[(SIZE - i - 1 + lag) % SIZE]; - j = y[i % SIZE]; - break; - - case ascending: - k = i - lag; - j = i; - break; - - case descending: - k = SIZE - i - 1 + lag; - j = SIZE - i - 1; - break; - - default: - /* This never should happen, but gcc isn't smart enough to - recognize it. */ - abort (); - } + { + case randomorder: + if (i >= lag) + k = y[i - lag]; + else + /* Ensure that the array index is within bounds. */ + k = y[(SIZE - i - 1 + lag) % SIZE]; + j = y[i % SIZE]; + break; + + case ascending: + k = i - lag; + j = i; + break; + + case descending: + k = SIZE - i - 1 + lag; + j = SIZE - i - 1; + break; + + default: + /* This never should happen, but gcc isn't smart enough to + recognize it. */ + abort (); + } switch (what) - { - case build_and_del: - case build: - if (i < SIZE) - { - if (tfind (x + j, (void *const *) root, cmp_fn) != NULL) - { - fputs ("Found element which is not in tree yet.\n", stdout); - error = 1; - } - elem = tsearch (x + j, root, cmp_fn); - if (elem == 0 - || tfind (x + j, (void *const *) root, cmp_fn) == NULL) - { - fputs ("Couldn't find element after it was added.\n", - stdout); - error = 1; - } - } - - if (what == build || i < lag) - break; - - j = k; - /* fall through */ - - case delete: - elem = tfind (x + j, (void *const *) root, cmp_fn); - if (elem == NULL || tdelete (x + j, root, cmp_fn) == NULL) - { - fputs ("Error deleting element.\n", stdout); - error = 1; - } - break; - - case find: - if (tfind (x + j, (void *const *) root, cmp_fn) == NULL) - { - fputs ("Couldn't find element after it was added.\n", stdout); - error = 1; - } - break; - - } + { + case build_and_del: + case build: + if (i < SIZE) + { + if (tfind (x + j, (void *const *) root, cmp_fn) != NULL) + { + fputs ("Found element which is not in tree yet.\n", stdout); + error = 1; + } + elem = tsearch (x + j, root, cmp_fn); + if (elem == 0 + || tfind (x + j, (void *const *) root, cmp_fn) == NULL) + { + fputs ("Couldn't find element after it was added.\n", + stdout); + error = 1; + } + } + + if (what == build || i < lag) + break; + + j = k; + /* fall through */ + + case delete: + elem = tfind (x + j, (void *const *) root, cmp_fn); + if (elem == NULL || tdelete (x + j, root, cmp_fn) == NULL) + { + fputs ("Error deleting element.\n", stdout); + error = 1; + } + break; + + case find: + if (tfind (x + j, (void *const *) root, cmp_fn) == NULL) + { + fputs ("Couldn't find element after it was added.\n", stdout); + error = 1; + } + break; + + } } } @@ -310,9 +310,9 @@ main (int argc, char **argv) mangle_tree (randomorder, delete, &root, 0); for (j = 1; j < SIZE; j *= 2) - { - mangle_tree (randomorder, build_and_del, &root, j); - } + { + mangle_tree (randomorder, build_and_del, &root, j); + } fputs (error ? " failed!\n" : " ok.\n", stdout); total_error |= error; diff --git a/tests/test-uname.c b/tests/test-uname.c index fa42a251a..a458698a6 100644 --- a/tests/test-uname.c +++ b/tests/test-uname.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) diff --git a/tests/test-unlink.c b/tests/test-unlink.c index 3d7a8753a..447a01473 100644 --- a/tests/test-unlink.c +++ b/tests/test-unlink.c @@ -34,11 +34,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) diff --git a/tests/test-unlinkat.c b/tests/test-unlinkat.c index 8fa96430c..a98dc8dc4 100644 --- a/tests/test-unlinkat.c +++ b/tests/test-unlinkat.c @@ -33,11 +33,11 @@ do \ { \ if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ } \ while (0) @@ -80,6 +80,6 @@ main (void) ASSERT (close (dfd) == 0); if (result1 == 77) fputs ("skipping test: symlinks not supported on this file system\n", - stderr); + stderr); return result1; } diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index 0162196a0..0c20a6044 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ @@ -104,15 +104,15 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas if (start_index < end_index) { if (string[start_index] == '-') - start_index++; + start_index++; if (start_index + 3 <= end_index - && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) - { - start_index += 3; - if (start_index == end_index - || (string[start_index] == '(' && string[end_index - 1] == ')')) - return 1; - } + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } } return 0; } @@ -147,10 +147,10 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) ASSERT (strcmp (result, "12345") == 0); ASSERT (length == 5); if (size < 6) - ASSERT (result != buf); + ASSERT (result != buf); ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); if (result != buf) - free (result); + free (result); } /* Test support of size specifiers as in C99. */ @@ -204,9 +204,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%a %d", 3.1416015625, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -217,9 +217,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%A %d", -3.1416015625, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -271,8 +271,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%a %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -283,9 +283,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.0a %d", 1.5, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -296,9 +296,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.0a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -309,9 +309,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.1a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -322,9 +322,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.2a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -335,9 +335,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.3a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -348,9 +348,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.3a %d", 1.49999, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -362,9 +362,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.1a %d", 1.999, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -375,9 +375,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -388,9 +388,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -401,9 +401,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.50a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -414,9 +414,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%-10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -427,9 +427,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%+a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -440,9 +440,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "% a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -453,9 +453,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -466,9 +466,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#a %d", 1.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -479,9 +479,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%010a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -506,8 +506,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -518,9 +518,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", 3.1416015625L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -531,9 +531,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%LA %d", -3.1416015625L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -585,8 +585,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -599,8 +599,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -613,8 +613,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -633,8 +633,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -646,8 +646,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -659,8 +659,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -672,8 +672,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -685,8 +685,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -698,9 +698,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.0La %d", 1.5L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -711,9 +711,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.0La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -724,9 +724,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.1La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -737,9 +737,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.2La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -750,9 +750,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.3La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -763,9 +763,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.3La %d", 1.49999L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -778,9 +778,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.1La %d", 1.999L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -791,9 +791,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -804,9 +804,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -817,9 +817,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.50La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -830,9 +830,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%-10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -843,9 +843,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%+La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -856,9 +856,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "% La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -869,9 +869,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -882,9 +882,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#La %d", 1.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -895,9 +895,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%010La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -922,8 +922,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -953,91 +953,91 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "0.000000" }, - { 1.234321234321234e-36, "0.000000" }, - { 1.234321234321234e-35, "0.000000" }, - { 1.234321234321234e-34, "0.000000" }, - { 1.234321234321234e-33, "0.000000" }, - { 1.234321234321234e-32, "0.000000" }, - { 1.234321234321234e-31, "0.000000" }, - { 1.234321234321234e-30, "0.000000" }, - { 1.234321234321234e-29, "0.000000" }, - { 1.234321234321234e-28, "0.000000" }, - { 1.234321234321234e-27, "0.000000" }, - { 1.234321234321234e-26, "0.000000" }, - { 1.234321234321234e-25, "0.000000" }, - { 1.234321234321234e-24, "0.000000" }, - { 1.234321234321234e-23, "0.000000" }, - { 1.234321234321234e-22, "0.000000" }, - { 1.234321234321234e-21, "0.000000" }, - { 1.234321234321234e-20, "0.000000" }, - { 1.234321234321234e-19, "0.000000" }, - { 1.234321234321234e-18, "0.000000" }, - { 1.234321234321234e-17, "0.000000" }, - { 1.234321234321234e-16, "0.000000" }, - { 1.234321234321234e-15, "0.000000" }, - { 1.234321234321234e-14, "0.000000" }, - { 1.234321234321234e-13, "0.000000" }, - { 1.234321234321234e-12, "0.000000" }, - { 1.234321234321234e-11, "0.000000" }, - { 1.234321234321234e-10, "0.000000" }, - { 1.234321234321234e-9, "0.000000" }, - { 1.234321234321234e-8, "0.000000" }, - { 1.234321234321234e-7, "0.000000" }, - { 1.234321234321234e-6, "0.000001" }, - { 1.234321234321234e-5, "0.000012" }, - { 1.234321234321234e-4, "0.000123" }, - { 1.234321234321234e-3, "0.001234" }, - { 1.234321234321234e-2, "0.012343" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.234321" }, - { 1.234321234321234e1, "12.343212" }, - { 1.234321234321234e2, "123.432123" }, - { 1.234321234321234e3, "1234.321234" }, - { 1.234321234321234e4, "12343.212343" }, - { 1.234321234321234e5, "123432.123432" }, - { 1.234321234321234e6, "1234321.234321" }, - { 1.234321234321234e7, "12343212.343212" }, - { 1.234321234321234e8, "123432123.432123" }, - { 1.234321234321234e9, "1234321234.321234" }, - { 1.234321234321234e10, "12343212343.2123**" }, - { 1.234321234321234e11, "123432123432.123***" }, - { 1.234321234321234e12, "1234321234321.23****" }, - { 1.234321234321234e13, "12343212343212.3*****" }, - { 1.234321234321234e14, "123432123432123.******" }, - { 1.234321234321234e15, "1234321234321234.000000" }, - { 1.234321234321234e16, "123432123432123**.000000" }, - { 1.234321234321234e17, "123432123432123***.000000" }, - { 1.234321234321234e18, "123432123432123****.000000" }, - { 1.234321234321234e19, "123432123432123*****.000000" }, - { 1.234321234321234e20, "123432123432123******.000000" }, - { 1.234321234321234e21, "123432123432123*******.000000" }, - { 1.234321234321234e22, "123432123432123********.000000" }, - { 1.234321234321234e23, "123432123432123*********.000000" }, - { 1.234321234321234e24, "123432123432123**********.000000" }, - { 1.234321234321234e25, "123432123432123***********.000000" }, - { 1.234321234321234e26, "123432123432123************.000000" }, - { 1.234321234321234e27, "123432123432123*************.000000" }, - { 1.234321234321234e28, "123432123432123**************.000000" }, - { 1.234321234321234e29, "123432123432123***************.000000" }, - { 1.234321234321234e30, "123432123432123****************.000000" }, - { 1.234321234321234e31, "123432123432123*****************.000000" }, - { 1.234321234321234e32, "123432123432123******************.000000" }, - { 1.234321234321234e33, "123432123432123*******************.000000" }, - { 1.234321234321234e34, "123432123432123********************.000000" }, - { 1.234321234321234e35, "123432123432123*********************.000000" }, - { 1.234321234321234e36, "123432123432123**********************.000000" } + { 1.234321234321234e-37, "0.000000" }, + { 1.234321234321234e-36, "0.000000" }, + { 1.234321234321234e-35, "0.000000" }, + { 1.234321234321234e-34, "0.000000" }, + { 1.234321234321234e-33, "0.000000" }, + { 1.234321234321234e-32, "0.000000" }, + { 1.234321234321234e-31, "0.000000" }, + { 1.234321234321234e-30, "0.000000" }, + { 1.234321234321234e-29, "0.000000" }, + { 1.234321234321234e-28, "0.000000" }, + { 1.234321234321234e-27, "0.000000" }, + { 1.234321234321234e-26, "0.000000" }, + { 1.234321234321234e-25, "0.000000" }, + { 1.234321234321234e-24, "0.000000" }, + { 1.234321234321234e-23, "0.000000" }, + { 1.234321234321234e-22, "0.000000" }, + { 1.234321234321234e-21, "0.000000" }, + { 1.234321234321234e-20, "0.000000" }, + { 1.234321234321234e-19, "0.000000" }, + { 1.234321234321234e-18, "0.000000" }, + { 1.234321234321234e-17, "0.000000" }, + { 1.234321234321234e-16, "0.000000" }, + { 1.234321234321234e-15, "0.000000" }, + { 1.234321234321234e-14, "0.000000" }, + { 1.234321234321234e-13, "0.000000" }, + { 1.234321234321234e-12, "0.000000" }, + { 1.234321234321234e-11, "0.000000" }, + { 1.234321234321234e-10, "0.000000" }, + { 1.234321234321234e-9, "0.000000" }, + { 1.234321234321234e-8, "0.000000" }, + { 1.234321234321234e-7, "0.000000" }, + { 1.234321234321234e-6, "0.000001" }, + { 1.234321234321234e-5, "0.000012" }, + { 1.234321234321234e-4, "0.000123" }, + { 1.234321234321234e-3, "0.001234" }, + { 1.234321234321234e-2, "0.012343" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.234321" }, + { 1.234321234321234e1, "12.343212" }, + { 1.234321234321234e2, "123.432123" }, + { 1.234321234321234e3, "1234.321234" }, + { 1.234321234321234e4, "12343.212343" }, + { 1.234321234321234e5, "123432.123432" }, + { 1.234321234321234e6, "1234321.234321" }, + { 1.234321234321234e7, "12343212.343212" }, + { 1.234321234321234e8, "123432123.432123" }, + { 1.234321234321234e9, "1234321234.321234" }, + { 1.234321234321234e10, "12343212343.2123**" }, + { 1.234321234321234e11, "123432123432.123***" }, + { 1.234321234321234e12, "1234321234321.23****" }, + { 1.234321234321234e13, "12343212343212.3*****" }, + { 1.234321234321234e14, "123432123432123.******" }, + { 1.234321234321234e15, "1234321234321234.000000" }, + { 1.234321234321234e16, "123432123432123**.000000" }, + { 1.234321234321234e17, "123432123432123***.000000" }, + { 1.234321234321234e18, "123432123432123****.000000" }, + { 1.234321234321234e19, "123432123432123*****.000000" }, + { 1.234321234321234e20, "123432123432123******.000000" }, + { 1.234321234321234e21, "123432123432123*******.000000" }, + { 1.234321234321234e22, "123432123432123********.000000" }, + { 1.234321234321234e23, "123432123432123*********.000000" }, + { 1.234321234321234e24, "123432123432123**********.000000" }, + { 1.234321234321234e25, "123432123432123***********.000000" }, + { 1.234321234321234e26, "123432123432123************.000000" }, + { 1.234321234321234e27, "123432123432123*************.000000" }, + { 1.234321234321234e28, "123432123432123**************.000000" }, + { 1.234321234321234e29, "123432123432123***************.000000" }, + { 1.234321234321234e30, "123432123432123****************.000000" }, + { 1.234321234321234e31, "123432123432123*****************.000000" }, + { 1.234321234321234e32, "123432123432123******************.000000" }, + { 1.234321234321234e33, "123432123432123*******************.000000" }, + { 1.234321234321234e34, "123432123432123********************.000000" }, + { 1.234321234321234e35, "123432123432123*********************.000000" }, + { 1.234321234321234e36, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - size_t length; - char *result = - my_asnprintf (NULL, &length, "%f", data[k].value); - ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); - ASSERT (length == strlen (result)); - free (result); + size_t length; + char *result = + my_asnprintf (NULL, &length, "%f", data[k].value); + ASSERT (result != NULL); + ASSERT (strmatch (data[k].string, result)); + ASSERT (length == strlen (result)); + free (result); } } @@ -1078,7 +1078,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%f %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1089,7 +1089,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1100,8 +1100,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1182,7 +1182,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1193,8 +1193,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%050f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1252,91 +1252,91 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "0.000000" }, - { 1.234321234321234e-36L, "0.000000" }, - { 1.234321234321234e-35L, "0.000000" }, - { 1.234321234321234e-34L, "0.000000" }, - { 1.234321234321234e-33L, "0.000000" }, - { 1.234321234321234e-32L, "0.000000" }, - { 1.234321234321234e-31L, "0.000000" }, - { 1.234321234321234e-30L, "0.000000" }, - { 1.234321234321234e-29L, "0.000000" }, - { 1.234321234321234e-28L, "0.000000" }, - { 1.234321234321234e-27L, "0.000000" }, - { 1.234321234321234e-26L, "0.000000" }, - { 1.234321234321234e-25L, "0.000000" }, - { 1.234321234321234e-24L, "0.000000" }, - { 1.234321234321234e-23L, "0.000000" }, - { 1.234321234321234e-22L, "0.000000" }, - { 1.234321234321234e-21L, "0.000000" }, - { 1.234321234321234e-20L, "0.000000" }, - { 1.234321234321234e-19L, "0.000000" }, - { 1.234321234321234e-18L, "0.000000" }, - { 1.234321234321234e-17L, "0.000000" }, - { 1.234321234321234e-16L, "0.000000" }, - { 1.234321234321234e-15L, "0.000000" }, - { 1.234321234321234e-14L, "0.000000" }, - { 1.234321234321234e-13L, "0.000000" }, - { 1.234321234321234e-12L, "0.000000" }, - { 1.234321234321234e-11L, "0.000000" }, - { 1.234321234321234e-10L, "0.000000" }, - { 1.234321234321234e-9L, "0.000000" }, - { 1.234321234321234e-8L, "0.000000" }, - { 1.234321234321234e-7L, "0.000000" }, - { 1.234321234321234e-6L, "0.000001" }, - { 1.234321234321234e-5L, "0.000012" }, - { 1.234321234321234e-4L, "0.000123" }, - { 1.234321234321234e-3L, "0.001234" }, - { 1.234321234321234e-2L, "0.012343" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.234321" }, - { 1.234321234321234e1L, "12.343212" }, - { 1.234321234321234e2L, "123.432123" }, - { 1.234321234321234e3L, "1234.321234" }, - { 1.234321234321234e4L, "12343.212343" }, - { 1.234321234321234e5L, "123432.123432" }, - { 1.234321234321234e6L, "1234321.234321" }, - { 1.234321234321234e7L, "12343212.343212" }, - { 1.234321234321234e8L, "123432123.432123" }, - { 1.234321234321234e9L, "1234321234.321234" }, - { 1.234321234321234e10L, "12343212343.2123**" }, - { 1.234321234321234e11L, "123432123432.123***" }, - { 1.234321234321234e12L, "1234321234321.23****" }, - { 1.234321234321234e13L, "12343212343212.3*****" }, - { 1.234321234321234e14L, "123432123432123.******" }, - { 1.234321234321234e15L, "1234321234321234.000000" }, - { 1.234321234321234e16L, "123432123432123**.000000" }, - { 1.234321234321234e17L, "123432123432123***.000000" }, - { 1.234321234321234e18L, "123432123432123****.000000" }, - { 1.234321234321234e19L, "123432123432123*****.000000" }, - { 1.234321234321234e20L, "123432123432123******.000000" }, - { 1.234321234321234e21L, "123432123432123*******.000000" }, - { 1.234321234321234e22L, "123432123432123********.000000" }, - { 1.234321234321234e23L, "123432123432123*********.000000" }, - { 1.234321234321234e24L, "123432123432123**********.000000" }, - { 1.234321234321234e25L, "123432123432123***********.000000" }, - { 1.234321234321234e26L, "123432123432123************.000000" }, - { 1.234321234321234e27L, "123432123432123*************.000000" }, - { 1.234321234321234e28L, "123432123432123**************.000000" }, - { 1.234321234321234e29L, "123432123432123***************.000000" }, - { 1.234321234321234e30L, "123432123432123****************.000000" }, - { 1.234321234321234e31L, "123432123432123*****************.000000" }, - { 1.234321234321234e32L, "123432123432123******************.000000" }, - { 1.234321234321234e33L, "123432123432123*******************.000000" }, - { 1.234321234321234e34L, "123432123432123********************.000000" }, - { 1.234321234321234e35L, "123432123432123*********************.000000" }, - { 1.234321234321234e36L, "123432123432123**********************.000000" } + { 1.234321234321234e-37L, "0.000000" }, + { 1.234321234321234e-36L, "0.000000" }, + { 1.234321234321234e-35L, "0.000000" }, + { 1.234321234321234e-34L, "0.000000" }, + { 1.234321234321234e-33L, "0.000000" }, + { 1.234321234321234e-32L, "0.000000" }, + { 1.234321234321234e-31L, "0.000000" }, + { 1.234321234321234e-30L, "0.000000" }, + { 1.234321234321234e-29L, "0.000000" }, + { 1.234321234321234e-28L, "0.000000" }, + { 1.234321234321234e-27L, "0.000000" }, + { 1.234321234321234e-26L, "0.000000" }, + { 1.234321234321234e-25L, "0.000000" }, + { 1.234321234321234e-24L, "0.000000" }, + { 1.234321234321234e-23L, "0.000000" }, + { 1.234321234321234e-22L, "0.000000" }, + { 1.234321234321234e-21L, "0.000000" }, + { 1.234321234321234e-20L, "0.000000" }, + { 1.234321234321234e-19L, "0.000000" }, + { 1.234321234321234e-18L, "0.000000" }, + { 1.234321234321234e-17L, "0.000000" }, + { 1.234321234321234e-16L, "0.000000" }, + { 1.234321234321234e-15L, "0.000000" }, + { 1.234321234321234e-14L, "0.000000" }, + { 1.234321234321234e-13L, "0.000000" }, + { 1.234321234321234e-12L, "0.000000" }, + { 1.234321234321234e-11L, "0.000000" }, + { 1.234321234321234e-10L, "0.000000" }, + { 1.234321234321234e-9L, "0.000000" }, + { 1.234321234321234e-8L, "0.000000" }, + { 1.234321234321234e-7L, "0.000000" }, + { 1.234321234321234e-6L, "0.000001" }, + { 1.234321234321234e-5L, "0.000012" }, + { 1.234321234321234e-4L, "0.000123" }, + { 1.234321234321234e-3L, "0.001234" }, + { 1.234321234321234e-2L, "0.012343" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.234321" }, + { 1.234321234321234e1L, "12.343212" }, + { 1.234321234321234e2L, "123.432123" }, + { 1.234321234321234e3L, "1234.321234" }, + { 1.234321234321234e4L, "12343.212343" }, + { 1.234321234321234e5L, "123432.123432" }, + { 1.234321234321234e6L, "1234321.234321" }, + { 1.234321234321234e7L, "12343212.343212" }, + { 1.234321234321234e8L, "123432123.432123" }, + { 1.234321234321234e9L, "1234321234.321234" }, + { 1.234321234321234e10L, "12343212343.2123**" }, + { 1.234321234321234e11L, "123432123432.123***" }, + { 1.234321234321234e12L, "1234321234321.23****" }, + { 1.234321234321234e13L, "12343212343212.3*****" }, + { 1.234321234321234e14L, "123432123432123.******" }, + { 1.234321234321234e15L, "1234321234321234.000000" }, + { 1.234321234321234e16L, "123432123432123**.000000" }, + { 1.234321234321234e17L, "123432123432123***.000000" }, + { 1.234321234321234e18L, "123432123432123****.000000" }, + { 1.234321234321234e19L, "123432123432123*****.000000" }, + { 1.234321234321234e20L, "123432123432123******.000000" }, + { 1.234321234321234e21L, "123432123432123*******.000000" }, + { 1.234321234321234e22L, "123432123432123********.000000" }, + { 1.234321234321234e23L, "123432123432123*********.000000" }, + { 1.234321234321234e24L, "123432123432123**********.000000" }, + { 1.234321234321234e25L, "123432123432123***********.000000" }, + { 1.234321234321234e26L, "123432123432123************.000000" }, + { 1.234321234321234e27L, "123432123432123*************.000000" }, + { 1.234321234321234e28L, "123432123432123**************.000000" }, + { 1.234321234321234e29L, "123432123432123***************.000000" }, + { 1.234321234321234e30L, "123432123432123****************.000000" }, + { 1.234321234321234e31L, "123432123432123*****************.000000" }, + { 1.234321234321234e32L, "123432123432123******************.000000" }, + { 1.234321234321234e33L, "123432123432123*******************.000000" }, + { 1.234321234321234e34L, "123432123432123********************.000000" }, + { 1.234321234321234e35L, "123432123432123*********************.000000" }, + { 1.234321234321234e36L, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - size_t length; - char *result = - my_asnprintf (NULL, &length, "%Lf", data[k].value); - ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); - ASSERT (length == strlen (result)); - free (result); + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lf", data[k].value); + ASSERT (result != NULL); + ASSERT (strmatch (data[k].string, result)); + ASSERT (length == strlen (result)); + free (result); } } @@ -1377,7 +1377,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1388,7 +1388,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1399,8 +1399,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1413,8 +1413,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1427,8 +1427,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1447,8 +1447,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1460,8 +1460,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1473,8 +1473,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1486,8 +1486,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1499,8 +1499,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1582,7 +1582,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1593,8 +1593,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1688,7 +1688,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%F %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1699,7 +1699,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1710,8 +1710,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%F %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1732,7 +1732,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1824,7 +1824,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%LF %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1835,7 +1835,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1846,8 +1846,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%LF %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1868,7 +1868,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1911,7 +1911,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", 12.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1922,7 +1922,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -1930,99 +1930,99 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.234321e-37" }, - { 1.234321234321234e-36, "1.234321e-36" }, - { 1.234321234321234e-35, "1.234321e-35" }, - { 1.234321234321234e-34, "1.234321e-34" }, - { 1.234321234321234e-33, "1.234321e-33" }, - { 1.234321234321234e-32, "1.234321e-32" }, - { 1.234321234321234e-31, "1.234321e-31" }, - { 1.234321234321234e-30, "1.234321e-30" }, - { 1.234321234321234e-29, "1.234321e-29" }, - { 1.234321234321234e-28, "1.234321e-28" }, - { 1.234321234321234e-27, "1.234321e-27" }, - { 1.234321234321234e-26, "1.234321e-26" }, - { 1.234321234321234e-25, "1.234321e-25" }, - { 1.234321234321234e-24, "1.234321e-24" }, - { 1.234321234321234e-23, "1.234321e-23" }, - { 1.234321234321234e-22, "1.234321e-22" }, - { 1.234321234321234e-21, "1.234321e-21" }, - { 1.234321234321234e-20, "1.234321e-20" }, - { 1.234321234321234e-19, "1.234321e-19" }, - { 1.234321234321234e-18, "1.234321e-18" }, - { 1.234321234321234e-17, "1.234321e-17" }, - { 1.234321234321234e-16, "1.234321e-16" }, - { 1.234321234321234e-15, "1.234321e-15" }, - { 1.234321234321234e-14, "1.234321e-14" }, - { 1.234321234321234e-13, "1.234321e-13" }, - { 1.234321234321234e-12, "1.234321e-12" }, - { 1.234321234321234e-11, "1.234321e-11" }, - { 1.234321234321234e-10, "1.234321e-10" }, - { 1.234321234321234e-9, "1.234321e-09" }, - { 1.234321234321234e-8, "1.234321e-08" }, - { 1.234321234321234e-7, "1.234321e-07" }, - { 1.234321234321234e-6, "1.234321e-06" }, - { 1.234321234321234e-5, "1.234321e-05" }, - { 1.234321234321234e-4, "1.234321e-04" }, - { 1.234321234321234e-3, "1.234321e-03" }, - { 1.234321234321234e-2, "1.234321e-02" }, - { 1.234321234321234e-1, "1.234321e-01" }, - { 1.234321234321234, "1.234321e+00" }, - { 1.234321234321234e1, "1.234321e+01" }, - { 1.234321234321234e2, "1.234321e+02" }, - { 1.234321234321234e3, "1.234321e+03" }, - { 1.234321234321234e4, "1.234321e+04" }, - { 1.234321234321234e5, "1.234321e+05" }, - { 1.234321234321234e6, "1.234321e+06" }, - { 1.234321234321234e7, "1.234321e+07" }, - { 1.234321234321234e8, "1.234321e+08" }, - { 1.234321234321234e9, "1.234321e+09" }, - { 1.234321234321234e10, "1.234321e+10" }, - { 1.234321234321234e11, "1.234321e+11" }, - { 1.234321234321234e12, "1.234321e+12" }, - { 1.234321234321234e13, "1.234321e+13" }, - { 1.234321234321234e14, "1.234321e+14" }, - { 1.234321234321234e15, "1.234321e+15" }, - { 1.234321234321234e16, "1.234321e+16" }, - { 1.234321234321234e17, "1.234321e+17" }, - { 1.234321234321234e18, "1.234321e+18" }, - { 1.234321234321234e19, "1.234321e+19" }, - { 1.234321234321234e20, "1.234321e+20" }, - { 1.234321234321234e21, "1.234321e+21" }, - { 1.234321234321234e22, "1.234321e+22" }, - { 1.234321234321234e23, "1.234321e+23" }, - { 1.234321234321234e24, "1.234321e+24" }, - { 1.234321234321234e25, "1.234321e+25" }, - { 1.234321234321234e26, "1.234321e+26" }, - { 1.234321234321234e27, "1.234321e+27" }, - { 1.234321234321234e28, "1.234321e+28" }, - { 1.234321234321234e29, "1.234321e+29" }, - { 1.234321234321234e30, "1.234321e+30" }, - { 1.234321234321234e31, "1.234321e+31" }, - { 1.234321234321234e32, "1.234321e+32" }, - { 1.234321234321234e33, "1.234321e+33" }, - { 1.234321234321234e34, "1.234321e+34" }, - { 1.234321234321234e35, "1.234321e+35" }, - { 1.234321234321234e36, "1.234321e+36" } + { 1.234321234321234e-37, "1.234321e-37" }, + { 1.234321234321234e-36, "1.234321e-36" }, + { 1.234321234321234e-35, "1.234321e-35" }, + { 1.234321234321234e-34, "1.234321e-34" }, + { 1.234321234321234e-33, "1.234321e-33" }, + { 1.234321234321234e-32, "1.234321e-32" }, + { 1.234321234321234e-31, "1.234321e-31" }, + { 1.234321234321234e-30, "1.234321e-30" }, + { 1.234321234321234e-29, "1.234321e-29" }, + { 1.234321234321234e-28, "1.234321e-28" }, + { 1.234321234321234e-27, "1.234321e-27" }, + { 1.234321234321234e-26, "1.234321e-26" }, + { 1.234321234321234e-25, "1.234321e-25" }, + { 1.234321234321234e-24, "1.234321e-24" }, + { 1.234321234321234e-23, "1.234321e-23" }, + { 1.234321234321234e-22, "1.234321e-22" }, + { 1.234321234321234e-21, "1.234321e-21" }, + { 1.234321234321234e-20, "1.234321e-20" }, + { 1.234321234321234e-19, "1.234321e-19" }, + { 1.234321234321234e-18, "1.234321e-18" }, + { 1.234321234321234e-17, "1.234321e-17" }, + { 1.234321234321234e-16, "1.234321e-16" }, + { 1.234321234321234e-15, "1.234321e-15" }, + { 1.234321234321234e-14, "1.234321e-14" }, + { 1.234321234321234e-13, "1.234321e-13" }, + { 1.234321234321234e-12, "1.234321e-12" }, + { 1.234321234321234e-11, "1.234321e-11" }, + { 1.234321234321234e-10, "1.234321e-10" }, + { 1.234321234321234e-9, "1.234321e-09" }, + { 1.234321234321234e-8, "1.234321e-08" }, + { 1.234321234321234e-7, "1.234321e-07" }, + { 1.234321234321234e-6, "1.234321e-06" }, + { 1.234321234321234e-5, "1.234321e-05" }, + { 1.234321234321234e-4, "1.234321e-04" }, + { 1.234321234321234e-3, "1.234321e-03" }, + { 1.234321234321234e-2, "1.234321e-02" }, + { 1.234321234321234e-1, "1.234321e-01" }, + { 1.234321234321234, "1.234321e+00" }, + { 1.234321234321234e1, "1.234321e+01" }, + { 1.234321234321234e2, "1.234321e+02" }, + { 1.234321234321234e3, "1.234321e+03" }, + { 1.234321234321234e4, "1.234321e+04" }, + { 1.234321234321234e5, "1.234321e+05" }, + { 1.234321234321234e6, "1.234321e+06" }, + { 1.234321234321234e7, "1.234321e+07" }, + { 1.234321234321234e8, "1.234321e+08" }, + { 1.234321234321234e9, "1.234321e+09" }, + { 1.234321234321234e10, "1.234321e+10" }, + { 1.234321234321234e11, "1.234321e+11" }, + { 1.234321234321234e12, "1.234321e+12" }, + { 1.234321234321234e13, "1.234321e+13" }, + { 1.234321234321234e14, "1.234321e+14" }, + { 1.234321234321234e15, "1.234321e+15" }, + { 1.234321234321234e16, "1.234321e+16" }, + { 1.234321234321234e17, "1.234321e+17" }, + { 1.234321234321234e18, "1.234321e+18" }, + { 1.234321234321234e19, "1.234321e+19" }, + { 1.234321234321234e20, "1.234321e+20" }, + { 1.234321234321234e21, "1.234321e+21" }, + { 1.234321234321234e22, "1.234321e+22" }, + { 1.234321234321234e23, "1.234321e+23" }, + { 1.234321234321234e24, "1.234321e+24" }, + { 1.234321234321234e25, "1.234321e+25" }, + { 1.234321234321234e26, "1.234321e+26" }, + { 1.234321234321234e27, "1.234321e+27" }, + { 1.234321234321234e28, "1.234321e+28" }, + { 1.234321234321234e29, "1.234321e+29" }, + { 1.234321234321234e30, "1.234321e+30" }, + { 1.234321234321234e31, "1.234321e+31" }, + { 1.234321234321234e32, "1.234321e+32" }, + { 1.234321234321234e33, "1.234321e+33" }, + { 1.234321234321234e34, "1.234321e+34" }, + { 1.234321234321234e35, "1.234321e+35" }, + { 1.234321234321234e36, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - size_t length; - char *result = - my_asnprintf (NULL, &length, "%e", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (length == strlen (result)); - free (result); + size_t length; + char *result = + my_asnprintf (NULL, &length, "%e", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (length == strlen (result)); + free (result); } } @@ -2032,7 +2032,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", -0.03125, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2043,7 +2043,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2055,7 +2055,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) ASSERT (result != NULL); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2066,7 +2066,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2077,7 +2077,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2088,8 +2088,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2100,7 +2100,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2111,7 +2111,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%-15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2122,7 +2122,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%+e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2133,7 +2133,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "% e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2144,7 +2144,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2155,7 +2155,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#.e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2166,7 +2166,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#.e %d", 9.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2177,7 +2177,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2188,7 +2188,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2199,8 +2199,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%050e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2211,7 +2211,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2222,7 +2222,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.4e %d", 999.951, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2233,7 +2233,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.4e %d", 999.996, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2244,7 +2244,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", 12.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2255,7 +2255,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", 1234567.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2263,99 +2263,99 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.234321e-37" }, - { 1.234321234321234e-36L, "1.234321e-36" }, - { 1.234321234321234e-35L, "1.234321e-35" }, - { 1.234321234321234e-34L, "1.234321e-34" }, - { 1.234321234321234e-33L, "1.234321e-33" }, - { 1.234321234321234e-32L, "1.234321e-32" }, - { 1.234321234321234e-31L, "1.234321e-31" }, - { 1.234321234321234e-30L, "1.234321e-30" }, - { 1.234321234321234e-29L, "1.234321e-29" }, - { 1.234321234321234e-28L, "1.234321e-28" }, - { 1.234321234321234e-27L, "1.234321e-27" }, - { 1.234321234321234e-26L, "1.234321e-26" }, - { 1.234321234321234e-25L, "1.234321e-25" }, - { 1.234321234321234e-24L, "1.234321e-24" }, - { 1.234321234321234e-23L, "1.234321e-23" }, - { 1.234321234321234e-22L, "1.234321e-22" }, - { 1.234321234321234e-21L, "1.234321e-21" }, - { 1.234321234321234e-20L, "1.234321e-20" }, - { 1.234321234321234e-19L, "1.234321e-19" }, - { 1.234321234321234e-18L, "1.234321e-18" }, - { 1.234321234321234e-17L, "1.234321e-17" }, - { 1.234321234321234e-16L, "1.234321e-16" }, - { 1.234321234321234e-15L, "1.234321e-15" }, - { 1.234321234321234e-14L, "1.234321e-14" }, - { 1.234321234321234e-13L, "1.234321e-13" }, - { 1.234321234321234e-12L, "1.234321e-12" }, - { 1.234321234321234e-11L, "1.234321e-11" }, - { 1.234321234321234e-10L, "1.234321e-10" }, - { 1.234321234321234e-9L, "1.234321e-09" }, - { 1.234321234321234e-8L, "1.234321e-08" }, - { 1.234321234321234e-7L, "1.234321e-07" }, - { 1.234321234321234e-6L, "1.234321e-06" }, - { 1.234321234321234e-5L, "1.234321e-05" }, - { 1.234321234321234e-4L, "1.234321e-04" }, - { 1.234321234321234e-3L, "1.234321e-03" }, - { 1.234321234321234e-2L, "1.234321e-02" }, - { 1.234321234321234e-1L, "1.234321e-01" }, - { 1.234321234321234L, "1.234321e+00" }, - { 1.234321234321234e1L, "1.234321e+01" }, - { 1.234321234321234e2L, "1.234321e+02" }, - { 1.234321234321234e3L, "1.234321e+03" }, - { 1.234321234321234e4L, "1.234321e+04" }, - { 1.234321234321234e5L, "1.234321e+05" }, - { 1.234321234321234e6L, "1.234321e+06" }, - { 1.234321234321234e7L, "1.234321e+07" }, - { 1.234321234321234e8L, "1.234321e+08" }, - { 1.234321234321234e9L, "1.234321e+09" }, - { 1.234321234321234e10L, "1.234321e+10" }, - { 1.234321234321234e11L, "1.234321e+11" }, - { 1.234321234321234e12L, "1.234321e+12" }, - { 1.234321234321234e13L, "1.234321e+13" }, - { 1.234321234321234e14L, "1.234321e+14" }, - { 1.234321234321234e15L, "1.234321e+15" }, - { 1.234321234321234e16L, "1.234321e+16" }, - { 1.234321234321234e17L, "1.234321e+17" }, - { 1.234321234321234e18L, "1.234321e+18" }, - { 1.234321234321234e19L, "1.234321e+19" }, - { 1.234321234321234e20L, "1.234321e+20" }, - { 1.234321234321234e21L, "1.234321e+21" }, - { 1.234321234321234e22L, "1.234321e+22" }, - { 1.234321234321234e23L, "1.234321e+23" }, - { 1.234321234321234e24L, "1.234321e+24" }, - { 1.234321234321234e25L, "1.234321e+25" }, - { 1.234321234321234e26L, "1.234321e+26" }, - { 1.234321234321234e27L, "1.234321e+27" }, - { 1.234321234321234e28L, "1.234321e+28" }, - { 1.234321234321234e29L, "1.234321e+29" }, - { 1.234321234321234e30L, "1.234321e+30" }, - { 1.234321234321234e31L, "1.234321e+31" }, - { 1.234321234321234e32L, "1.234321e+32" }, - { 1.234321234321234e33L, "1.234321e+33" }, - { 1.234321234321234e34L, "1.234321e+34" }, - { 1.234321234321234e35L, "1.234321e+35" }, - { 1.234321234321234e36L, "1.234321e+36" } + { 1.234321234321234e-37L, "1.234321e-37" }, + { 1.234321234321234e-36L, "1.234321e-36" }, + { 1.234321234321234e-35L, "1.234321e-35" }, + { 1.234321234321234e-34L, "1.234321e-34" }, + { 1.234321234321234e-33L, "1.234321e-33" }, + { 1.234321234321234e-32L, "1.234321e-32" }, + { 1.234321234321234e-31L, "1.234321e-31" }, + { 1.234321234321234e-30L, "1.234321e-30" }, + { 1.234321234321234e-29L, "1.234321e-29" }, + { 1.234321234321234e-28L, "1.234321e-28" }, + { 1.234321234321234e-27L, "1.234321e-27" }, + { 1.234321234321234e-26L, "1.234321e-26" }, + { 1.234321234321234e-25L, "1.234321e-25" }, + { 1.234321234321234e-24L, "1.234321e-24" }, + { 1.234321234321234e-23L, "1.234321e-23" }, + { 1.234321234321234e-22L, "1.234321e-22" }, + { 1.234321234321234e-21L, "1.234321e-21" }, + { 1.234321234321234e-20L, "1.234321e-20" }, + { 1.234321234321234e-19L, "1.234321e-19" }, + { 1.234321234321234e-18L, "1.234321e-18" }, + { 1.234321234321234e-17L, "1.234321e-17" }, + { 1.234321234321234e-16L, "1.234321e-16" }, + { 1.234321234321234e-15L, "1.234321e-15" }, + { 1.234321234321234e-14L, "1.234321e-14" }, + { 1.234321234321234e-13L, "1.234321e-13" }, + { 1.234321234321234e-12L, "1.234321e-12" }, + { 1.234321234321234e-11L, "1.234321e-11" }, + { 1.234321234321234e-10L, "1.234321e-10" }, + { 1.234321234321234e-9L, "1.234321e-09" }, + { 1.234321234321234e-8L, "1.234321e-08" }, + { 1.234321234321234e-7L, "1.234321e-07" }, + { 1.234321234321234e-6L, "1.234321e-06" }, + { 1.234321234321234e-5L, "1.234321e-05" }, + { 1.234321234321234e-4L, "1.234321e-04" }, + { 1.234321234321234e-3L, "1.234321e-03" }, + { 1.234321234321234e-2L, "1.234321e-02" }, + { 1.234321234321234e-1L, "1.234321e-01" }, + { 1.234321234321234L, "1.234321e+00" }, + { 1.234321234321234e1L, "1.234321e+01" }, + { 1.234321234321234e2L, "1.234321e+02" }, + { 1.234321234321234e3L, "1.234321e+03" }, + { 1.234321234321234e4L, "1.234321e+04" }, + { 1.234321234321234e5L, "1.234321e+05" }, + { 1.234321234321234e6L, "1.234321e+06" }, + { 1.234321234321234e7L, "1.234321e+07" }, + { 1.234321234321234e8L, "1.234321e+08" }, + { 1.234321234321234e9L, "1.234321e+09" }, + { 1.234321234321234e10L, "1.234321e+10" }, + { 1.234321234321234e11L, "1.234321e+11" }, + { 1.234321234321234e12L, "1.234321e+12" }, + { 1.234321234321234e13L, "1.234321e+13" }, + { 1.234321234321234e14L, "1.234321e+14" }, + { 1.234321234321234e15L, "1.234321e+15" }, + { 1.234321234321234e16L, "1.234321e+16" }, + { 1.234321234321234e17L, "1.234321e+17" }, + { 1.234321234321234e18L, "1.234321e+18" }, + { 1.234321234321234e19L, "1.234321e+19" }, + { 1.234321234321234e20L, "1.234321e+20" }, + { 1.234321234321234e21L, "1.234321e+21" }, + { 1.234321234321234e22L, "1.234321e+22" }, + { 1.234321234321234e23L, "1.234321e+23" }, + { 1.234321234321234e24L, "1.234321e+24" }, + { 1.234321234321234e25L, "1.234321e+25" }, + { 1.234321234321234e26L, "1.234321e+26" }, + { 1.234321234321234e27L, "1.234321e+27" }, + { 1.234321234321234e28L, "1.234321e+28" }, + { 1.234321234321234e29L, "1.234321e+29" }, + { 1.234321234321234e30L, "1.234321e+30" }, + { 1.234321234321234e31L, "1.234321e+31" }, + { 1.234321234321234e32L, "1.234321e+32" }, + { 1.234321234321234e33L, "1.234321e+33" }, + { 1.234321234321234e34L, "1.234321e+34" }, + { 1.234321234321234e35L, "1.234321e+35" }, + { 1.234321234321234e36L, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - size_t length; - char *result = - my_asnprintf (NULL, &length, "%Le", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (length == strlen (result)); - free (result); + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Le", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (length == strlen (result)); + free (result); } } @@ -2365,7 +2365,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", -0.03125L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2376,7 +2376,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2388,7 +2388,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) ASSERT (result != NULL); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2399,7 +2399,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2410,7 +2410,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2421,8 +2421,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2435,8 +2435,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2449,8 +2449,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2469,8 +2469,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2482,8 +2482,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2495,8 +2495,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2508,8 +2508,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2521,8 +2521,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2534,7 +2534,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%15Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2545,7 +2545,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%-15Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2556,7 +2556,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%+Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2567,7 +2567,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "% Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2578,7 +2578,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2589,7 +2589,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#.Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2600,7 +2600,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#.Le %d", 9.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2611,7 +2611,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015Le %d", 1234.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2622,7 +2622,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2633,8 +2633,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%050Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2645,7 +2645,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.Le %d", 1234.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2656,7 +2656,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.4Le %d", 999.951L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2667,7 +2667,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.4Le %d", 999.996L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2690,7 +2690,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%g %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2698,100 +2698,100 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.23432e-37" }, - { 1.234321234321234e-36, "1.23432e-36" }, - { 1.234321234321234e-35, "1.23432e-35" }, - { 1.234321234321234e-34, "1.23432e-34" }, - { 1.234321234321234e-33, "1.23432e-33" }, - { 1.234321234321234e-32, "1.23432e-32" }, - { 1.234321234321234e-31, "1.23432e-31" }, - { 1.234321234321234e-30, "1.23432e-30" }, - { 1.234321234321234e-29, "1.23432e-29" }, - { 1.234321234321234e-28, "1.23432e-28" }, - { 1.234321234321234e-27, "1.23432e-27" }, - { 1.234321234321234e-26, "1.23432e-26" }, - { 1.234321234321234e-25, "1.23432e-25" }, - { 1.234321234321234e-24, "1.23432e-24" }, - { 1.234321234321234e-23, "1.23432e-23" }, - { 1.234321234321234e-22, "1.23432e-22" }, - { 1.234321234321234e-21, "1.23432e-21" }, - { 1.234321234321234e-20, "1.23432e-20" }, - { 1.234321234321234e-19, "1.23432e-19" }, - { 1.234321234321234e-18, "1.23432e-18" }, - { 1.234321234321234e-17, "1.23432e-17" }, - { 1.234321234321234e-16, "1.23432e-16" }, - { 1.234321234321234e-15, "1.23432e-15" }, - { 1.234321234321234e-14, "1.23432e-14" }, - { 1.234321234321234e-13, "1.23432e-13" }, - { 1.234321234321234e-12, "1.23432e-12" }, - { 1.234321234321234e-11, "1.23432e-11" }, - { 1.234321234321234e-10, "1.23432e-10" }, - { 1.234321234321234e-9, "1.23432e-09" }, - { 1.234321234321234e-8, "1.23432e-08" }, - { 1.234321234321234e-7, "1.23432e-07" }, - { 1.234321234321234e-6, "1.23432e-06" }, - { 1.234321234321234e-5, "1.23432e-05" }, - { 1.234321234321234e-4, "0.000123432" }, - { 1.234321234321234e-3, "0.00123432" }, - { 1.234321234321234e-2, "0.0123432" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.23432" }, - { 1.234321234321234e1, "12.3432" }, - { 1.234321234321234e2, "123.432" }, - { 1.234321234321234e3, "1234.32" }, - { 1.234321234321234e4, "12343.2" }, - { 1.234321234321234e5, "123432" }, - { 1.234321234321234e6, "1.23432e+06" }, - { 1.234321234321234e7, "1.23432e+07" }, - { 1.234321234321234e8, "1.23432e+08" }, - { 1.234321234321234e9, "1.23432e+09" }, - { 1.234321234321234e10, "1.23432e+10" }, - { 1.234321234321234e11, "1.23432e+11" }, - { 1.234321234321234e12, "1.23432e+12" }, - { 1.234321234321234e13, "1.23432e+13" }, - { 1.234321234321234e14, "1.23432e+14" }, - { 1.234321234321234e15, "1.23432e+15" }, - { 1.234321234321234e16, "1.23432e+16" }, - { 1.234321234321234e17, "1.23432e+17" }, - { 1.234321234321234e18, "1.23432e+18" }, - { 1.234321234321234e19, "1.23432e+19" }, - { 1.234321234321234e20, "1.23432e+20" }, - { 1.234321234321234e21, "1.23432e+21" }, - { 1.234321234321234e22, "1.23432e+22" }, - { 1.234321234321234e23, "1.23432e+23" }, - { 1.234321234321234e24, "1.23432e+24" }, - { 1.234321234321234e25, "1.23432e+25" }, - { 1.234321234321234e26, "1.23432e+26" }, - { 1.234321234321234e27, "1.23432e+27" }, - { 1.234321234321234e28, "1.23432e+28" }, - { 1.234321234321234e29, "1.23432e+29" }, - { 1.234321234321234e30, "1.23432e+30" }, - { 1.234321234321234e31, "1.23432e+31" }, - { 1.234321234321234e32, "1.23432e+32" }, - { 1.234321234321234e33, "1.23432e+33" }, - { 1.234321234321234e34, "1.23432e+34" }, - { 1.234321234321234e35, "1.23432e+35" }, - { 1.234321234321234e36, "1.23432e+36" } + { 1.234321234321234e-37, "1.23432e-37" }, + { 1.234321234321234e-36, "1.23432e-36" }, + { 1.234321234321234e-35, "1.23432e-35" }, + { 1.234321234321234e-34, "1.23432e-34" }, + { 1.234321234321234e-33, "1.23432e-33" }, + { 1.234321234321234e-32, "1.23432e-32" }, + { 1.234321234321234e-31, "1.23432e-31" }, + { 1.234321234321234e-30, "1.23432e-30" }, + { 1.234321234321234e-29, "1.23432e-29" }, + { 1.234321234321234e-28, "1.23432e-28" }, + { 1.234321234321234e-27, "1.23432e-27" }, + { 1.234321234321234e-26, "1.23432e-26" }, + { 1.234321234321234e-25, "1.23432e-25" }, + { 1.234321234321234e-24, "1.23432e-24" }, + { 1.234321234321234e-23, "1.23432e-23" }, + { 1.234321234321234e-22, "1.23432e-22" }, + { 1.234321234321234e-21, "1.23432e-21" }, + { 1.234321234321234e-20, "1.23432e-20" }, + { 1.234321234321234e-19, "1.23432e-19" }, + { 1.234321234321234e-18, "1.23432e-18" }, + { 1.234321234321234e-17, "1.23432e-17" }, + { 1.234321234321234e-16, "1.23432e-16" }, + { 1.234321234321234e-15, "1.23432e-15" }, + { 1.234321234321234e-14, "1.23432e-14" }, + { 1.234321234321234e-13, "1.23432e-13" }, + { 1.234321234321234e-12, "1.23432e-12" }, + { 1.234321234321234e-11, "1.23432e-11" }, + { 1.234321234321234e-10, "1.23432e-10" }, + { 1.234321234321234e-9, "1.23432e-09" }, + { 1.234321234321234e-8, "1.23432e-08" }, + { 1.234321234321234e-7, "1.23432e-07" }, + { 1.234321234321234e-6, "1.23432e-06" }, + { 1.234321234321234e-5, "1.23432e-05" }, + { 1.234321234321234e-4, "0.000123432" }, + { 1.234321234321234e-3, "0.00123432" }, + { 1.234321234321234e-2, "0.0123432" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.23432" }, + { 1.234321234321234e1, "12.3432" }, + { 1.234321234321234e2, "123.432" }, + { 1.234321234321234e3, "1234.32" }, + { 1.234321234321234e4, "12343.2" }, + { 1.234321234321234e5, "123432" }, + { 1.234321234321234e6, "1.23432e+06" }, + { 1.234321234321234e7, "1.23432e+07" }, + { 1.234321234321234e8, "1.23432e+08" }, + { 1.234321234321234e9, "1.23432e+09" }, + { 1.234321234321234e10, "1.23432e+10" }, + { 1.234321234321234e11, "1.23432e+11" }, + { 1.234321234321234e12, "1.23432e+12" }, + { 1.234321234321234e13, "1.23432e+13" }, + { 1.234321234321234e14, "1.23432e+14" }, + { 1.234321234321234e15, "1.23432e+15" }, + { 1.234321234321234e16, "1.23432e+16" }, + { 1.234321234321234e17, "1.23432e+17" }, + { 1.234321234321234e18, "1.23432e+18" }, + { 1.234321234321234e19, "1.23432e+19" }, + { 1.234321234321234e20, "1.23432e+20" }, + { 1.234321234321234e21, "1.23432e+21" }, + { 1.234321234321234e22, "1.23432e+22" }, + { 1.234321234321234e23, "1.23432e+23" }, + { 1.234321234321234e24, "1.23432e+24" }, + { 1.234321234321234e25, "1.23432e+25" }, + { 1.234321234321234e26, "1.23432e+26" }, + { 1.234321234321234e27, "1.23432e+27" }, + { 1.234321234321234e28, "1.23432e+28" }, + { 1.234321234321234e29, "1.23432e+29" }, + { 1.234321234321234e30, "1.23432e+30" }, + { 1.234321234321234e31, "1.23432e+31" }, + { 1.234321234321234e32, "1.23432e+32" }, + { 1.234321234321234e33, "1.23432e+33" }, + { 1.234321234321234e34, "1.23432e+34" }, + { 1.234321234321234e35, "1.23432e+35" }, + { 1.234321234321234e36, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - size_t length; - char *result = - my_asnprintf (NULL, &length, "%g", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (length == strlen (result)); - free (result); + size_t length; + char *result = + my_asnprintf (NULL, &length, "%g", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (length == strlen (result)); + free (result); } } @@ -2832,7 +2832,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%g %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2843,7 +2843,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2854,8 +2854,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2926,7 +2926,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#.g %d", 9.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2947,7 +2947,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2958,8 +2958,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%050g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -2970,7 +2970,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.g %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3011,7 +3011,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", 1234567.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3019,100 +3019,100 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.23432e-37" }, - { 1.234321234321234e-36L, "1.23432e-36" }, - { 1.234321234321234e-35L, "1.23432e-35" }, - { 1.234321234321234e-34L, "1.23432e-34" }, - { 1.234321234321234e-33L, "1.23432e-33" }, - { 1.234321234321234e-32L, "1.23432e-32" }, - { 1.234321234321234e-31L, "1.23432e-31" }, - { 1.234321234321234e-30L, "1.23432e-30" }, - { 1.234321234321234e-29L, "1.23432e-29" }, - { 1.234321234321234e-28L, "1.23432e-28" }, - { 1.234321234321234e-27L, "1.23432e-27" }, - { 1.234321234321234e-26L, "1.23432e-26" }, - { 1.234321234321234e-25L, "1.23432e-25" }, - { 1.234321234321234e-24L, "1.23432e-24" }, - { 1.234321234321234e-23L, "1.23432e-23" }, - { 1.234321234321234e-22L, "1.23432e-22" }, - { 1.234321234321234e-21L, "1.23432e-21" }, - { 1.234321234321234e-20L, "1.23432e-20" }, - { 1.234321234321234e-19L, "1.23432e-19" }, - { 1.234321234321234e-18L, "1.23432e-18" }, - { 1.234321234321234e-17L, "1.23432e-17" }, - { 1.234321234321234e-16L, "1.23432e-16" }, - { 1.234321234321234e-15L, "1.23432e-15" }, - { 1.234321234321234e-14L, "1.23432e-14" }, - { 1.234321234321234e-13L, "1.23432e-13" }, - { 1.234321234321234e-12L, "1.23432e-12" }, - { 1.234321234321234e-11L, "1.23432e-11" }, - { 1.234321234321234e-10L, "1.23432e-10" }, - { 1.234321234321234e-9L, "1.23432e-09" }, - { 1.234321234321234e-8L, "1.23432e-08" }, - { 1.234321234321234e-7L, "1.23432e-07" }, - { 1.234321234321234e-6L, "1.23432e-06" }, - { 1.234321234321234e-5L, "1.23432e-05" }, - { 1.234321234321234e-4L, "0.000123432" }, - { 1.234321234321234e-3L, "0.00123432" }, - { 1.234321234321234e-2L, "0.0123432" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.23432" }, - { 1.234321234321234e1L, "12.3432" }, - { 1.234321234321234e2L, "123.432" }, - { 1.234321234321234e3L, "1234.32" }, - { 1.234321234321234e4L, "12343.2" }, - { 1.234321234321234e5L, "123432" }, - { 1.234321234321234e6L, "1.23432e+06" }, - { 1.234321234321234e7L, "1.23432e+07" }, - { 1.234321234321234e8L, "1.23432e+08" }, - { 1.234321234321234e9L, "1.23432e+09" }, - { 1.234321234321234e10L, "1.23432e+10" }, - { 1.234321234321234e11L, "1.23432e+11" }, - { 1.234321234321234e12L, "1.23432e+12" }, - { 1.234321234321234e13L, "1.23432e+13" }, - { 1.234321234321234e14L, "1.23432e+14" }, - { 1.234321234321234e15L, "1.23432e+15" }, - { 1.234321234321234e16L, "1.23432e+16" }, - { 1.234321234321234e17L, "1.23432e+17" }, - { 1.234321234321234e18L, "1.23432e+18" }, - { 1.234321234321234e19L, "1.23432e+19" }, - { 1.234321234321234e20L, "1.23432e+20" }, - { 1.234321234321234e21L, "1.23432e+21" }, - { 1.234321234321234e22L, "1.23432e+22" }, - { 1.234321234321234e23L, "1.23432e+23" }, - { 1.234321234321234e24L, "1.23432e+24" }, - { 1.234321234321234e25L, "1.23432e+25" }, - { 1.234321234321234e26L, "1.23432e+26" }, - { 1.234321234321234e27L, "1.23432e+27" }, - { 1.234321234321234e28L, "1.23432e+28" }, - { 1.234321234321234e29L, "1.23432e+29" }, - { 1.234321234321234e30L, "1.23432e+30" }, - { 1.234321234321234e31L, "1.23432e+31" }, - { 1.234321234321234e32L, "1.23432e+32" }, - { 1.234321234321234e33L, "1.23432e+33" }, - { 1.234321234321234e34L, "1.23432e+34" }, - { 1.234321234321234e35L, "1.23432e+35" }, - { 1.234321234321234e36L, "1.23432e+36" } + { 1.234321234321234e-37L, "1.23432e-37" }, + { 1.234321234321234e-36L, "1.23432e-36" }, + { 1.234321234321234e-35L, "1.23432e-35" }, + { 1.234321234321234e-34L, "1.23432e-34" }, + { 1.234321234321234e-33L, "1.23432e-33" }, + { 1.234321234321234e-32L, "1.23432e-32" }, + { 1.234321234321234e-31L, "1.23432e-31" }, + { 1.234321234321234e-30L, "1.23432e-30" }, + { 1.234321234321234e-29L, "1.23432e-29" }, + { 1.234321234321234e-28L, "1.23432e-28" }, + { 1.234321234321234e-27L, "1.23432e-27" }, + { 1.234321234321234e-26L, "1.23432e-26" }, + { 1.234321234321234e-25L, "1.23432e-25" }, + { 1.234321234321234e-24L, "1.23432e-24" }, + { 1.234321234321234e-23L, "1.23432e-23" }, + { 1.234321234321234e-22L, "1.23432e-22" }, + { 1.234321234321234e-21L, "1.23432e-21" }, + { 1.234321234321234e-20L, "1.23432e-20" }, + { 1.234321234321234e-19L, "1.23432e-19" }, + { 1.234321234321234e-18L, "1.23432e-18" }, + { 1.234321234321234e-17L, "1.23432e-17" }, + { 1.234321234321234e-16L, "1.23432e-16" }, + { 1.234321234321234e-15L, "1.23432e-15" }, + { 1.234321234321234e-14L, "1.23432e-14" }, + { 1.234321234321234e-13L, "1.23432e-13" }, + { 1.234321234321234e-12L, "1.23432e-12" }, + { 1.234321234321234e-11L, "1.23432e-11" }, + { 1.234321234321234e-10L, "1.23432e-10" }, + { 1.234321234321234e-9L, "1.23432e-09" }, + { 1.234321234321234e-8L, "1.23432e-08" }, + { 1.234321234321234e-7L, "1.23432e-07" }, + { 1.234321234321234e-6L, "1.23432e-06" }, + { 1.234321234321234e-5L, "1.23432e-05" }, + { 1.234321234321234e-4L, "0.000123432" }, + { 1.234321234321234e-3L, "0.00123432" }, + { 1.234321234321234e-2L, "0.0123432" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.23432" }, + { 1.234321234321234e1L, "12.3432" }, + { 1.234321234321234e2L, "123.432" }, + { 1.234321234321234e3L, "1234.32" }, + { 1.234321234321234e4L, "12343.2" }, + { 1.234321234321234e5L, "123432" }, + { 1.234321234321234e6L, "1.23432e+06" }, + { 1.234321234321234e7L, "1.23432e+07" }, + { 1.234321234321234e8L, "1.23432e+08" }, + { 1.234321234321234e9L, "1.23432e+09" }, + { 1.234321234321234e10L, "1.23432e+10" }, + { 1.234321234321234e11L, "1.23432e+11" }, + { 1.234321234321234e12L, "1.23432e+12" }, + { 1.234321234321234e13L, "1.23432e+13" }, + { 1.234321234321234e14L, "1.23432e+14" }, + { 1.234321234321234e15L, "1.23432e+15" }, + { 1.234321234321234e16L, "1.23432e+16" }, + { 1.234321234321234e17L, "1.23432e+17" }, + { 1.234321234321234e18L, "1.23432e+18" }, + { 1.234321234321234e19L, "1.23432e+19" }, + { 1.234321234321234e20L, "1.23432e+20" }, + { 1.234321234321234e21L, "1.23432e+21" }, + { 1.234321234321234e22L, "1.23432e+22" }, + { 1.234321234321234e23L, "1.23432e+23" }, + { 1.234321234321234e24L, "1.23432e+24" }, + { 1.234321234321234e25L, "1.23432e+25" }, + { 1.234321234321234e26L, "1.23432e+26" }, + { 1.234321234321234e27L, "1.23432e+27" }, + { 1.234321234321234e28L, "1.23432e+28" }, + { 1.234321234321234e29L, "1.23432e+29" }, + { 1.234321234321234e30L, "1.23432e+30" }, + { 1.234321234321234e31L, "1.23432e+31" }, + { 1.234321234321234e32L, "1.23432e+32" }, + { 1.234321234321234e33L, "1.23432e+33" }, + { 1.234321234321234e34L, "1.23432e+34" }, + { 1.234321234321234e35L, "1.23432e+35" }, + { 1.234321234321234e36L, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - size_t length; - char *result = - my_asnprintf (NULL, &length, "%Lg", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (length == strlen (result)); - free (result); + size_t length; + char *result = + my_asnprintf (NULL, &length, "%Lg", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (length == strlen (result)); + free (result); } } @@ -3153,7 +3153,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3164,7 +3164,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3175,8 +3175,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3189,8 +3189,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3203,8 +3203,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3223,8 +3223,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3236,8 +3236,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3249,8 +3249,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3262,8 +3262,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3275,8 +3275,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3348,7 +3348,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%#.Lg %d", 9.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3369,7 +3369,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%015Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3380,8 +3380,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3392,7 +3392,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) my_asnprintf (NULL, &length, "%.Lg %d", 1234.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -3610,19 +3610,19 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) for (i = 1; i <= 8; i++) { - char *block; - size_t length; - char *result; - - block = (char *) malloc (i); - memcpy (block, "abcdefgh", i); - result = my_asnprintf (NULL, &length, "%.*s", (int) i, block); - ASSERT (result != NULL); - ASSERT (memcmp (result, block, i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (length == strlen (result)); - free (result); - free (block); + char *block; + size_t length; + char *result; + + block = (char *) malloc (i); + memcpy (block, "abcdefgh", i); + result = my_asnprintf (NULL, &length, "%.*s", (int) i, block); + ASSERT (result != NULL); + ASSERT (memcmp (result, block, i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (length == strlen (result)); + free (result); + free (block); } } #if HAVE_WCHAR_T @@ -3631,21 +3631,21 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) for (i = 1; i <= 8; i++) { - wchar_t *block; - size_t j; - size_t length; - char *result; - - block = (wchar_t *) malloc (i * sizeof (wchar_t)); - for (j = 0; j < i; j++) - block[j] = "abcdefgh"[j]; - result = my_asnprintf (NULL, &length, "%.*ls", (int) i, block); - ASSERT (result != NULL); - ASSERT (memcmp (result, "abcdefgh", i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (length == strlen (result)); - free (result); - free (block); + wchar_t *block; + size_t j; + size_t length; + char *result; + + block = (wchar_t *) malloc (i * sizeof (wchar_t)); + for (j = 0; j < i; j++) + block[j] = "abcdefgh"[j]; + result = my_asnprintf (NULL, &length, "%.*ls", (int) i, block); + ASSERT (result != NULL); + ASSERT (memcmp (result, "abcdefgh", i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (length == strlen (result)); + free (result); + free (block); } } #endif diff --git a/tests/test-vasnprintf-posix2.c b/tests/test-vasnprintf-posix2.c index e8acf01f0..c2b5f437f 100644 --- a/tests/test-vasnprintf-posix2.c +++ b/tests/test-vasnprintf-posix2.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -50,9 +50,9 @@ main (int argc, char *argv[]) char *result = asnprintf (NULL, &length, "%.1a", 1.0); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1,0p+0") == 0 - || strcmp (result, "0x2,0p-1") == 0 - || strcmp (result, "0x4,0p-2") == 0 - || strcmp (result, "0x8,0p-3") == 0); + || strcmp (result, "0x2,0p-1") == 0 + || strcmp (result, "0x4,0p-2") == 0 + || strcmp (result, "0x8,0p-3") == 0); ASSERT (length == strlen (result)); free (result); } @@ -63,9 +63,9 @@ main (int argc, char *argv[]) char *result = asnprintf (NULL, &length, "%.1La", 1.0L); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1,0p+0") == 0 - || strcmp (result, "0x2,0p-1") == 0 - || strcmp (result, "0x4,0p-2") == 0 - || strcmp (result, "0x8,0p-3") == 0); + || strcmp (result, "0x2,0p-1") == 0 + || strcmp (result, "0x4,0p-2") == 0 + || strcmp (result, "0x8,0p-3") == 0); ASSERT (length == strlen (result)); free (result); } diff --git a/tests/test-vasnprintf.c b/tests/test-vasnprintf.c index 2f3f8900d..280e1f47f 100644 --- a/tests/test-vasnprintf.c +++ b/tests/test-vasnprintf.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static char * @@ -77,10 +77,10 @@ test_vasnprintf () ASSERT (strcmp (result, "12345") == 0); ASSERT (length == 5); if (size < 6) - ASSERT (result != buf); + ASSERT (result != buf); ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); if (result != buf) - free (result); + free (result); } } @@ -112,10 +112,10 @@ test_asnprintf () ASSERT (strcmp (result, "12345") == 0); ASSERT (length == 5); if (size < 6) - ASSERT (result != buf); + ASSERT (result != buf); ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); if (result != buf) - free (result); + free (result); } } diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index ee3e75859..9f3c4b568 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* The SGI MIPS floating-point format does not distinguish 0.0 and -0.0. */ @@ -103,15 +103,15 @@ strisnan (const char *string, size_t start_index, size_t end_index, int uppercas if (start_index < end_index) { if (string[start_index] == '-') - start_index++; + start_index++; if (start_index + 3 <= end_index - && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) - { - start_index += 3; - if (start_index == end_index - || (string[start_index] == '(' && string[end_index - 1] == ')')) - return 1; - } + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } } return 0; } @@ -184,9 +184,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%a %d", 3.1416015625, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -197,9 +197,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%A %d", -3.1416015625, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -251,8 +251,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%a %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -263,9 +263,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.0a %d", 1.5, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -276,9 +276,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.0a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -289,9 +289,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.1a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -302,9 +302,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.2a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -315,9 +315,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.3a %d", 1.51, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -328,9 +328,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.3a %d", 1.49999, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -342,9 +342,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.1a %d", 1.999, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -355,9 +355,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -368,9 +368,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -381,9 +381,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.50a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -394,9 +394,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%-10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -407,9 +407,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%+a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -420,9 +420,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "% a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -433,9 +433,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -446,9 +446,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#a %d", 1.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -459,9 +459,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%010a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -486,8 +486,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -498,9 +498,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", 3.1416015625L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -511,9 +511,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%LA %d", -3.1416015625L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -565,8 +565,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -579,8 +579,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -593,8 +593,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -613,8 +613,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -626,8 +626,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -639,8 +639,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -652,8 +652,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -665,8 +665,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%La %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -678,9 +678,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.0La %d", 1.5L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -691,9 +691,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.0La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -704,9 +704,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.1La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.8p+0 33") == 0 - || strcmp (result, "0x3.0p-1 33") == 0 - || strcmp (result, "0x6.1p-2 33") == 0 - || strcmp (result, "0xc.1p-3 33") == 0); + || strcmp (result, "0x3.0p-1 33") == 0 + || strcmp (result, "0x6.1p-2 33") == 0 + || strcmp (result, "0xc.1p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -717,9 +717,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.2La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -730,9 +730,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.3La %d", 1.51L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.829p+0 33") == 0 - || strcmp (result, "0x3.052p-1 33") == 0 - || strcmp (result, "0x6.0a4p-2 33") == 0 - || strcmp (result, "0xc.148p-3 33") == 0); + || strcmp (result, "0x3.052p-1 33") == 0 + || strcmp (result, "0x6.0a4p-2 33") == 0 + || strcmp (result, "0xc.148p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -743,9 +743,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.3La %d", 1.49999L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.800p+0 33") == 0 - || strcmp (result, "0x3.000p-1 33") == 0 - || strcmp (result, "0x6.000p-2 33") == 0 - || strcmp (result, "0xc.000p-3 33") == 0); + || strcmp (result, "0x3.000p-1 33") == 0 + || strcmp (result, "0x6.000p-2 33") == 0 + || strcmp (result, "0xc.000p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -758,9 +758,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.1La %d", 1.999L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.0p+1 33") == 0 - || strcmp (result, "0x2.0p+0 33") == 0 - || strcmp (result, "0x4.0p-1 33") == 0 - || strcmp (result, "0x8.0p-2 33") == 0); + || strcmp (result, "0x2.0p+0 33") == 0 + || strcmp (result, "0x4.0p-1 33") == 0 + || strcmp (result, "0x8.0p-2 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -771,9 +771,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -784,9 +784,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -797,9 +797,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.50La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -810,9 +810,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%-10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7p-2 33") == 0 - || strcmp (result, "0xep-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7p-2 33") == 0 + || strcmp (result, "0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -823,9 +823,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%+La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+0x1.cp+0 33") == 0 - || strcmp (result, "+0x3.8p-1 33") == 0 - || strcmp (result, "+0x7p-2 33") == 0 - || strcmp (result, "+0xep-3 33") == 0); + || strcmp (result, "+0x3.8p-1 33") == 0 + || strcmp (result, "+0x7p-2 33") == 0 + || strcmp (result, "+0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -836,9 +836,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "% La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -849,9 +849,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.cp+0 33") == 0 - || strcmp (result, "0x3.8p-1 33") == 0 - || strcmp (result, "0x7.p-2 33") == 0 - || strcmp (result, "0xe.p-3 33") == 0); + || strcmp (result, "0x3.8p-1 33") == 0 + || strcmp (result, "0x7.p-2 33") == 0 + || strcmp (result, "0xe.p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -862,9 +862,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#La %d", 1.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.p+0 33") == 0 - || strcmp (result, "0x2.p-1 33") == 0 - || strcmp (result, "0x4.p-2 33") == 0 - || strcmp (result, "0x8.p-3 33") == 0); + || strcmp (result, "0x2.p-1 33") == 0 + || strcmp (result, "0x4.p-2 33") == 0 + || strcmp (result, "0x8.p-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -875,9 +875,9 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%010La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x001.cp+0 33") == 0 - || strcmp (result, "0x003.8p-1 33") == 0 - || strcmp (result, "0x00007p-2 33") == 0 - || strcmp (result, "0x0000ep-3 33") == 0); + || strcmp (result, "0x003.8p-1 33") == 0 + || strcmp (result, "0x00007p-2 33") == 0 + || strcmp (result, "0x0000ep-3 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -902,8 +902,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) /* "0000000nan 33" is not a valid result; see */ ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -933,91 +933,91 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "0.000000" }, - { 1.234321234321234e-36, "0.000000" }, - { 1.234321234321234e-35, "0.000000" }, - { 1.234321234321234e-34, "0.000000" }, - { 1.234321234321234e-33, "0.000000" }, - { 1.234321234321234e-32, "0.000000" }, - { 1.234321234321234e-31, "0.000000" }, - { 1.234321234321234e-30, "0.000000" }, - { 1.234321234321234e-29, "0.000000" }, - { 1.234321234321234e-28, "0.000000" }, - { 1.234321234321234e-27, "0.000000" }, - { 1.234321234321234e-26, "0.000000" }, - { 1.234321234321234e-25, "0.000000" }, - { 1.234321234321234e-24, "0.000000" }, - { 1.234321234321234e-23, "0.000000" }, - { 1.234321234321234e-22, "0.000000" }, - { 1.234321234321234e-21, "0.000000" }, - { 1.234321234321234e-20, "0.000000" }, - { 1.234321234321234e-19, "0.000000" }, - { 1.234321234321234e-18, "0.000000" }, - { 1.234321234321234e-17, "0.000000" }, - { 1.234321234321234e-16, "0.000000" }, - { 1.234321234321234e-15, "0.000000" }, - { 1.234321234321234e-14, "0.000000" }, - { 1.234321234321234e-13, "0.000000" }, - { 1.234321234321234e-12, "0.000000" }, - { 1.234321234321234e-11, "0.000000" }, - { 1.234321234321234e-10, "0.000000" }, - { 1.234321234321234e-9, "0.000000" }, - { 1.234321234321234e-8, "0.000000" }, - { 1.234321234321234e-7, "0.000000" }, - { 1.234321234321234e-6, "0.000001" }, - { 1.234321234321234e-5, "0.000012" }, - { 1.234321234321234e-4, "0.000123" }, - { 1.234321234321234e-3, "0.001234" }, - { 1.234321234321234e-2, "0.012343" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.234321" }, - { 1.234321234321234e1, "12.343212" }, - { 1.234321234321234e2, "123.432123" }, - { 1.234321234321234e3, "1234.321234" }, - { 1.234321234321234e4, "12343.212343" }, - { 1.234321234321234e5, "123432.123432" }, - { 1.234321234321234e6, "1234321.234321" }, - { 1.234321234321234e7, "12343212.343212" }, - { 1.234321234321234e8, "123432123.432123" }, - { 1.234321234321234e9, "1234321234.321234" }, - { 1.234321234321234e10, "12343212343.2123**" }, - { 1.234321234321234e11, "123432123432.123***" }, - { 1.234321234321234e12, "1234321234321.23****" }, - { 1.234321234321234e13, "12343212343212.3*****" }, - { 1.234321234321234e14, "123432123432123.******" }, - { 1.234321234321234e15, "1234321234321234.000000" }, - { 1.234321234321234e16, "123432123432123**.000000" }, - { 1.234321234321234e17, "123432123432123***.000000" }, - { 1.234321234321234e18, "123432123432123****.000000" }, - { 1.234321234321234e19, "123432123432123*****.000000" }, - { 1.234321234321234e20, "123432123432123******.000000" }, - { 1.234321234321234e21, "123432123432123*******.000000" }, - { 1.234321234321234e22, "123432123432123********.000000" }, - { 1.234321234321234e23, "123432123432123*********.000000" }, - { 1.234321234321234e24, "123432123432123**********.000000" }, - { 1.234321234321234e25, "123432123432123***********.000000" }, - { 1.234321234321234e26, "123432123432123************.000000" }, - { 1.234321234321234e27, "123432123432123*************.000000" }, - { 1.234321234321234e28, "123432123432123**************.000000" }, - { 1.234321234321234e29, "123432123432123***************.000000" }, - { 1.234321234321234e30, "123432123432123****************.000000" }, - { 1.234321234321234e31, "123432123432123*****************.000000" }, - { 1.234321234321234e32, "123432123432123******************.000000" }, - { 1.234321234321234e33, "123432123432123*******************.000000" }, - { 1.234321234321234e34, "123432123432123********************.000000" }, - { 1.234321234321234e35, "123432123432123*********************.000000" }, - { 1.234321234321234e36, "123432123432123**********************.000000" } + { 1.234321234321234e-37, "0.000000" }, + { 1.234321234321234e-36, "0.000000" }, + { 1.234321234321234e-35, "0.000000" }, + { 1.234321234321234e-34, "0.000000" }, + { 1.234321234321234e-33, "0.000000" }, + { 1.234321234321234e-32, "0.000000" }, + { 1.234321234321234e-31, "0.000000" }, + { 1.234321234321234e-30, "0.000000" }, + { 1.234321234321234e-29, "0.000000" }, + { 1.234321234321234e-28, "0.000000" }, + { 1.234321234321234e-27, "0.000000" }, + { 1.234321234321234e-26, "0.000000" }, + { 1.234321234321234e-25, "0.000000" }, + { 1.234321234321234e-24, "0.000000" }, + { 1.234321234321234e-23, "0.000000" }, + { 1.234321234321234e-22, "0.000000" }, + { 1.234321234321234e-21, "0.000000" }, + { 1.234321234321234e-20, "0.000000" }, + { 1.234321234321234e-19, "0.000000" }, + { 1.234321234321234e-18, "0.000000" }, + { 1.234321234321234e-17, "0.000000" }, + { 1.234321234321234e-16, "0.000000" }, + { 1.234321234321234e-15, "0.000000" }, + { 1.234321234321234e-14, "0.000000" }, + { 1.234321234321234e-13, "0.000000" }, + { 1.234321234321234e-12, "0.000000" }, + { 1.234321234321234e-11, "0.000000" }, + { 1.234321234321234e-10, "0.000000" }, + { 1.234321234321234e-9, "0.000000" }, + { 1.234321234321234e-8, "0.000000" }, + { 1.234321234321234e-7, "0.000000" }, + { 1.234321234321234e-6, "0.000001" }, + { 1.234321234321234e-5, "0.000012" }, + { 1.234321234321234e-4, "0.000123" }, + { 1.234321234321234e-3, "0.001234" }, + { 1.234321234321234e-2, "0.012343" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.234321" }, + { 1.234321234321234e1, "12.343212" }, + { 1.234321234321234e2, "123.432123" }, + { 1.234321234321234e3, "1234.321234" }, + { 1.234321234321234e4, "12343.212343" }, + { 1.234321234321234e5, "123432.123432" }, + { 1.234321234321234e6, "1234321.234321" }, + { 1.234321234321234e7, "12343212.343212" }, + { 1.234321234321234e8, "123432123.432123" }, + { 1.234321234321234e9, "1234321234.321234" }, + { 1.234321234321234e10, "12343212343.2123**" }, + { 1.234321234321234e11, "123432123432.123***" }, + { 1.234321234321234e12, "1234321234321.23****" }, + { 1.234321234321234e13, "12343212343212.3*****" }, + { 1.234321234321234e14, "123432123432123.******" }, + { 1.234321234321234e15, "1234321234321234.000000" }, + { 1.234321234321234e16, "123432123432123**.000000" }, + { 1.234321234321234e17, "123432123432123***.000000" }, + { 1.234321234321234e18, "123432123432123****.000000" }, + { 1.234321234321234e19, "123432123432123*****.000000" }, + { 1.234321234321234e20, "123432123432123******.000000" }, + { 1.234321234321234e21, "123432123432123*******.000000" }, + { 1.234321234321234e22, "123432123432123********.000000" }, + { 1.234321234321234e23, "123432123432123*********.000000" }, + { 1.234321234321234e24, "123432123432123**********.000000" }, + { 1.234321234321234e25, "123432123432123***********.000000" }, + { 1.234321234321234e26, "123432123432123************.000000" }, + { 1.234321234321234e27, "123432123432123*************.000000" }, + { 1.234321234321234e28, "123432123432123**************.000000" }, + { 1.234321234321234e29, "123432123432123***************.000000" }, + { 1.234321234321234e30, "123432123432123****************.000000" }, + { 1.234321234321234e31, "123432123432123*****************.000000" }, + { 1.234321234321234e32, "123432123432123******************.000000" }, + { 1.234321234321234e33, "123432123432123*******************.000000" }, + { 1.234321234321234e34, "123432123432123********************.000000" }, + { 1.234321234321234e35, "123432123432123*********************.000000" }, + { 1.234321234321234e36, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char *result; - int retval = - my_asprintf (&result, "%f", data[k].value); - ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); - ASSERT (retval == strlen (result)); - free (result); + char *result; + int retval = + my_asprintf (&result, "%f", data[k].value); + ASSERT (result != NULL); + ASSERT (strmatch (data[k].string, result)); + ASSERT (retval == strlen (result)); + free (result); } } @@ -1058,7 +1058,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%f %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1069,7 +1069,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1080,8 +1080,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1162,7 +1162,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015f %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1173,8 +1173,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%050f %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1232,91 +1232,91 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "0.000000" }, - { 1.234321234321234e-36L, "0.000000" }, - { 1.234321234321234e-35L, "0.000000" }, - { 1.234321234321234e-34L, "0.000000" }, - { 1.234321234321234e-33L, "0.000000" }, - { 1.234321234321234e-32L, "0.000000" }, - { 1.234321234321234e-31L, "0.000000" }, - { 1.234321234321234e-30L, "0.000000" }, - { 1.234321234321234e-29L, "0.000000" }, - { 1.234321234321234e-28L, "0.000000" }, - { 1.234321234321234e-27L, "0.000000" }, - { 1.234321234321234e-26L, "0.000000" }, - { 1.234321234321234e-25L, "0.000000" }, - { 1.234321234321234e-24L, "0.000000" }, - { 1.234321234321234e-23L, "0.000000" }, - { 1.234321234321234e-22L, "0.000000" }, - { 1.234321234321234e-21L, "0.000000" }, - { 1.234321234321234e-20L, "0.000000" }, - { 1.234321234321234e-19L, "0.000000" }, - { 1.234321234321234e-18L, "0.000000" }, - { 1.234321234321234e-17L, "0.000000" }, - { 1.234321234321234e-16L, "0.000000" }, - { 1.234321234321234e-15L, "0.000000" }, - { 1.234321234321234e-14L, "0.000000" }, - { 1.234321234321234e-13L, "0.000000" }, - { 1.234321234321234e-12L, "0.000000" }, - { 1.234321234321234e-11L, "0.000000" }, - { 1.234321234321234e-10L, "0.000000" }, - { 1.234321234321234e-9L, "0.000000" }, - { 1.234321234321234e-8L, "0.000000" }, - { 1.234321234321234e-7L, "0.000000" }, - { 1.234321234321234e-6L, "0.000001" }, - { 1.234321234321234e-5L, "0.000012" }, - { 1.234321234321234e-4L, "0.000123" }, - { 1.234321234321234e-3L, "0.001234" }, - { 1.234321234321234e-2L, "0.012343" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.234321" }, - { 1.234321234321234e1L, "12.343212" }, - { 1.234321234321234e2L, "123.432123" }, - { 1.234321234321234e3L, "1234.321234" }, - { 1.234321234321234e4L, "12343.212343" }, - { 1.234321234321234e5L, "123432.123432" }, - { 1.234321234321234e6L, "1234321.234321" }, - { 1.234321234321234e7L, "12343212.343212" }, - { 1.234321234321234e8L, "123432123.432123" }, - { 1.234321234321234e9L, "1234321234.321234" }, - { 1.234321234321234e10L, "12343212343.2123**" }, - { 1.234321234321234e11L, "123432123432.123***" }, - { 1.234321234321234e12L, "1234321234321.23****" }, - { 1.234321234321234e13L, "12343212343212.3*****" }, - { 1.234321234321234e14L, "123432123432123.******" }, - { 1.234321234321234e15L, "1234321234321234.000000" }, - { 1.234321234321234e16L, "123432123432123**.000000" }, - { 1.234321234321234e17L, "123432123432123***.000000" }, - { 1.234321234321234e18L, "123432123432123****.000000" }, - { 1.234321234321234e19L, "123432123432123*****.000000" }, - { 1.234321234321234e20L, "123432123432123******.000000" }, - { 1.234321234321234e21L, "123432123432123*******.000000" }, - { 1.234321234321234e22L, "123432123432123********.000000" }, - { 1.234321234321234e23L, "123432123432123*********.000000" }, - { 1.234321234321234e24L, "123432123432123**********.000000" }, - { 1.234321234321234e25L, "123432123432123***********.000000" }, - { 1.234321234321234e26L, "123432123432123************.000000" }, - { 1.234321234321234e27L, "123432123432123*************.000000" }, - { 1.234321234321234e28L, "123432123432123**************.000000" }, - { 1.234321234321234e29L, "123432123432123***************.000000" }, - { 1.234321234321234e30L, "123432123432123****************.000000" }, - { 1.234321234321234e31L, "123432123432123*****************.000000" }, - { 1.234321234321234e32L, "123432123432123******************.000000" }, - { 1.234321234321234e33L, "123432123432123*******************.000000" }, - { 1.234321234321234e34L, "123432123432123********************.000000" }, - { 1.234321234321234e35L, "123432123432123*********************.000000" }, - { 1.234321234321234e36L, "123432123432123**********************.000000" } + { 1.234321234321234e-37L, "0.000000" }, + { 1.234321234321234e-36L, "0.000000" }, + { 1.234321234321234e-35L, "0.000000" }, + { 1.234321234321234e-34L, "0.000000" }, + { 1.234321234321234e-33L, "0.000000" }, + { 1.234321234321234e-32L, "0.000000" }, + { 1.234321234321234e-31L, "0.000000" }, + { 1.234321234321234e-30L, "0.000000" }, + { 1.234321234321234e-29L, "0.000000" }, + { 1.234321234321234e-28L, "0.000000" }, + { 1.234321234321234e-27L, "0.000000" }, + { 1.234321234321234e-26L, "0.000000" }, + { 1.234321234321234e-25L, "0.000000" }, + { 1.234321234321234e-24L, "0.000000" }, + { 1.234321234321234e-23L, "0.000000" }, + { 1.234321234321234e-22L, "0.000000" }, + { 1.234321234321234e-21L, "0.000000" }, + { 1.234321234321234e-20L, "0.000000" }, + { 1.234321234321234e-19L, "0.000000" }, + { 1.234321234321234e-18L, "0.000000" }, + { 1.234321234321234e-17L, "0.000000" }, + { 1.234321234321234e-16L, "0.000000" }, + { 1.234321234321234e-15L, "0.000000" }, + { 1.234321234321234e-14L, "0.000000" }, + { 1.234321234321234e-13L, "0.000000" }, + { 1.234321234321234e-12L, "0.000000" }, + { 1.234321234321234e-11L, "0.000000" }, + { 1.234321234321234e-10L, "0.000000" }, + { 1.234321234321234e-9L, "0.000000" }, + { 1.234321234321234e-8L, "0.000000" }, + { 1.234321234321234e-7L, "0.000000" }, + { 1.234321234321234e-6L, "0.000001" }, + { 1.234321234321234e-5L, "0.000012" }, + { 1.234321234321234e-4L, "0.000123" }, + { 1.234321234321234e-3L, "0.001234" }, + { 1.234321234321234e-2L, "0.012343" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.234321" }, + { 1.234321234321234e1L, "12.343212" }, + { 1.234321234321234e2L, "123.432123" }, + { 1.234321234321234e3L, "1234.321234" }, + { 1.234321234321234e4L, "12343.212343" }, + { 1.234321234321234e5L, "123432.123432" }, + { 1.234321234321234e6L, "1234321.234321" }, + { 1.234321234321234e7L, "12343212.343212" }, + { 1.234321234321234e8L, "123432123.432123" }, + { 1.234321234321234e9L, "1234321234.321234" }, + { 1.234321234321234e10L, "12343212343.2123**" }, + { 1.234321234321234e11L, "123432123432.123***" }, + { 1.234321234321234e12L, "1234321234321.23****" }, + { 1.234321234321234e13L, "12343212343212.3*****" }, + { 1.234321234321234e14L, "123432123432123.******" }, + { 1.234321234321234e15L, "1234321234321234.000000" }, + { 1.234321234321234e16L, "123432123432123**.000000" }, + { 1.234321234321234e17L, "123432123432123***.000000" }, + { 1.234321234321234e18L, "123432123432123****.000000" }, + { 1.234321234321234e19L, "123432123432123*****.000000" }, + { 1.234321234321234e20L, "123432123432123******.000000" }, + { 1.234321234321234e21L, "123432123432123*******.000000" }, + { 1.234321234321234e22L, "123432123432123********.000000" }, + { 1.234321234321234e23L, "123432123432123*********.000000" }, + { 1.234321234321234e24L, "123432123432123**********.000000" }, + { 1.234321234321234e25L, "123432123432123***********.000000" }, + { 1.234321234321234e26L, "123432123432123************.000000" }, + { 1.234321234321234e27L, "123432123432123*************.000000" }, + { 1.234321234321234e28L, "123432123432123**************.000000" }, + { 1.234321234321234e29L, "123432123432123***************.000000" }, + { 1.234321234321234e30L, "123432123432123****************.000000" }, + { 1.234321234321234e31L, "123432123432123*****************.000000" }, + { 1.234321234321234e32L, "123432123432123******************.000000" }, + { 1.234321234321234e33L, "123432123432123*******************.000000" }, + { 1.234321234321234e34L, "123432123432123********************.000000" }, + { 1.234321234321234e35L, "123432123432123*********************.000000" }, + { 1.234321234321234e36L, "123432123432123**********************.000000" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char *result; - int retval = - my_asprintf (&result, "%Lf", data[k].value); - ASSERT (result != NULL); - ASSERT (strmatch (data[k].string, result)); - ASSERT (retval == strlen (result)); - free (result); + char *result; + int retval = + my_asprintf (&result, "%Lf", data[k].value); + ASSERT (result != NULL); + ASSERT (strmatch (data[k].string, result)); + ASSERT (retval == strlen (result)); + free (result); } } @@ -1357,7 +1357,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1368,7 +1368,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1379,8 +1379,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1393,8 +1393,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1407,8 +1407,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1427,8 +1427,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1440,8 +1440,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1453,8 +1453,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1466,8 +1466,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1479,8 +1479,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lf %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1562,7 +1562,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015Lf %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1573,8 +1573,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%050Lf %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1668,7 +1668,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%F %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1679,7 +1679,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1690,8 +1690,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%F %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1712,7 +1712,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015F %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1804,7 +1804,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%LF %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "INF 33") == 0 - || strcmp (result, "INFINITY 33") == 0); + || strcmp (result, "INFINITY 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1815,7 +1815,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-INF 33") == 0 - || strcmp (result, "-INFINITY 33") == 0); + || strcmp (result, "-INFINITY 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1826,8 +1826,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%LF %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 1) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 1) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1848,7 +1848,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015LF %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -INF 33") == 0 - || strcmp (result, " -INFINITY 33") == 0); + || strcmp (result, " -INFINITY 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1891,7 +1891,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", 12.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1902,7 +1902,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -1910,99 +1910,99 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.234321e-37" }, - { 1.234321234321234e-36, "1.234321e-36" }, - { 1.234321234321234e-35, "1.234321e-35" }, - { 1.234321234321234e-34, "1.234321e-34" }, - { 1.234321234321234e-33, "1.234321e-33" }, - { 1.234321234321234e-32, "1.234321e-32" }, - { 1.234321234321234e-31, "1.234321e-31" }, - { 1.234321234321234e-30, "1.234321e-30" }, - { 1.234321234321234e-29, "1.234321e-29" }, - { 1.234321234321234e-28, "1.234321e-28" }, - { 1.234321234321234e-27, "1.234321e-27" }, - { 1.234321234321234e-26, "1.234321e-26" }, - { 1.234321234321234e-25, "1.234321e-25" }, - { 1.234321234321234e-24, "1.234321e-24" }, - { 1.234321234321234e-23, "1.234321e-23" }, - { 1.234321234321234e-22, "1.234321e-22" }, - { 1.234321234321234e-21, "1.234321e-21" }, - { 1.234321234321234e-20, "1.234321e-20" }, - { 1.234321234321234e-19, "1.234321e-19" }, - { 1.234321234321234e-18, "1.234321e-18" }, - { 1.234321234321234e-17, "1.234321e-17" }, - { 1.234321234321234e-16, "1.234321e-16" }, - { 1.234321234321234e-15, "1.234321e-15" }, - { 1.234321234321234e-14, "1.234321e-14" }, - { 1.234321234321234e-13, "1.234321e-13" }, - { 1.234321234321234e-12, "1.234321e-12" }, - { 1.234321234321234e-11, "1.234321e-11" }, - { 1.234321234321234e-10, "1.234321e-10" }, - { 1.234321234321234e-9, "1.234321e-09" }, - { 1.234321234321234e-8, "1.234321e-08" }, - { 1.234321234321234e-7, "1.234321e-07" }, - { 1.234321234321234e-6, "1.234321e-06" }, - { 1.234321234321234e-5, "1.234321e-05" }, - { 1.234321234321234e-4, "1.234321e-04" }, - { 1.234321234321234e-3, "1.234321e-03" }, - { 1.234321234321234e-2, "1.234321e-02" }, - { 1.234321234321234e-1, "1.234321e-01" }, - { 1.234321234321234, "1.234321e+00" }, - { 1.234321234321234e1, "1.234321e+01" }, - { 1.234321234321234e2, "1.234321e+02" }, - { 1.234321234321234e3, "1.234321e+03" }, - { 1.234321234321234e4, "1.234321e+04" }, - { 1.234321234321234e5, "1.234321e+05" }, - { 1.234321234321234e6, "1.234321e+06" }, - { 1.234321234321234e7, "1.234321e+07" }, - { 1.234321234321234e8, "1.234321e+08" }, - { 1.234321234321234e9, "1.234321e+09" }, - { 1.234321234321234e10, "1.234321e+10" }, - { 1.234321234321234e11, "1.234321e+11" }, - { 1.234321234321234e12, "1.234321e+12" }, - { 1.234321234321234e13, "1.234321e+13" }, - { 1.234321234321234e14, "1.234321e+14" }, - { 1.234321234321234e15, "1.234321e+15" }, - { 1.234321234321234e16, "1.234321e+16" }, - { 1.234321234321234e17, "1.234321e+17" }, - { 1.234321234321234e18, "1.234321e+18" }, - { 1.234321234321234e19, "1.234321e+19" }, - { 1.234321234321234e20, "1.234321e+20" }, - { 1.234321234321234e21, "1.234321e+21" }, - { 1.234321234321234e22, "1.234321e+22" }, - { 1.234321234321234e23, "1.234321e+23" }, - { 1.234321234321234e24, "1.234321e+24" }, - { 1.234321234321234e25, "1.234321e+25" }, - { 1.234321234321234e26, "1.234321e+26" }, - { 1.234321234321234e27, "1.234321e+27" }, - { 1.234321234321234e28, "1.234321e+28" }, - { 1.234321234321234e29, "1.234321e+29" }, - { 1.234321234321234e30, "1.234321e+30" }, - { 1.234321234321234e31, "1.234321e+31" }, - { 1.234321234321234e32, "1.234321e+32" }, - { 1.234321234321234e33, "1.234321e+33" }, - { 1.234321234321234e34, "1.234321e+34" }, - { 1.234321234321234e35, "1.234321e+35" }, - { 1.234321234321234e36, "1.234321e+36" } + { 1.234321234321234e-37, "1.234321e-37" }, + { 1.234321234321234e-36, "1.234321e-36" }, + { 1.234321234321234e-35, "1.234321e-35" }, + { 1.234321234321234e-34, "1.234321e-34" }, + { 1.234321234321234e-33, "1.234321e-33" }, + { 1.234321234321234e-32, "1.234321e-32" }, + { 1.234321234321234e-31, "1.234321e-31" }, + { 1.234321234321234e-30, "1.234321e-30" }, + { 1.234321234321234e-29, "1.234321e-29" }, + { 1.234321234321234e-28, "1.234321e-28" }, + { 1.234321234321234e-27, "1.234321e-27" }, + { 1.234321234321234e-26, "1.234321e-26" }, + { 1.234321234321234e-25, "1.234321e-25" }, + { 1.234321234321234e-24, "1.234321e-24" }, + { 1.234321234321234e-23, "1.234321e-23" }, + { 1.234321234321234e-22, "1.234321e-22" }, + { 1.234321234321234e-21, "1.234321e-21" }, + { 1.234321234321234e-20, "1.234321e-20" }, + { 1.234321234321234e-19, "1.234321e-19" }, + { 1.234321234321234e-18, "1.234321e-18" }, + { 1.234321234321234e-17, "1.234321e-17" }, + { 1.234321234321234e-16, "1.234321e-16" }, + { 1.234321234321234e-15, "1.234321e-15" }, + { 1.234321234321234e-14, "1.234321e-14" }, + { 1.234321234321234e-13, "1.234321e-13" }, + { 1.234321234321234e-12, "1.234321e-12" }, + { 1.234321234321234e-11, "1.234321e-11" }, + { 1.234321234321234e-10, "1.234321e-10" }, + { 1.234321234321234e-9, "1.234321e-09" }, + { 1.234321234321234e-8, "1.234321e-08" }, + { 1.234321234321234e-7, "1.234321e-07" }, + { 1.234321234321234e-6, "1.234321e-06" }, + { 1.234321234321234e-5, "1.234321e-05" }, + { 1.234321234321234e-4, "1.234321e-04" }, + { 1.234321234321234e-3, "1.234321e-03" }, + { 1.234321234321234e-2, "1.234321e-02" }, + { 1.234321234321234e-1, "1.234321e-01" }, + { 1.234321234321234, "1.234321e+00" }, + { 1.234321234321234e1, "1.234321e+01" }, + { 1.234321234321234e2, "1.234321e+02" }, + { 1.234321234321234e3, "1.234321e+03" }, + { 1.234321234321234e4, "1.234321e+04" }, + { 1.234321234321234e5, "1.234321e+05" }, + { 1.234321234321234e6, "1.234321e+06" }, + { 1.234321234321234e7, "1.234321e+07" }, + { 1.234321234321234e8, "1.234321e+08" }, + { 1.234321234321234e9, "1.234321e+09" }, + { 1.234321234321234e10, "1.234321e+10" }, + { 1.234321234321234e11, "1.234321e+11" }, + { 1.234321234321234e12, "1.234321e+12" }, + { 1.234321234321234e13, "1.234321e+13" }, + { 1.234321234321234e14, "1.234321e+14" }, + { 1.234321234321234e15, "1.234321e+15" }, + { 1.234321234321234e16, "1.234321e+16" }, + { 1.234321234321234e17, "1.234321e+17" }, + { 1.234321234321234e18, "1.234321e+18" }, + { 1.234321234321234e19, "1.234321e+19" }, + { 1.234321234321234e20, "1.234321e+20" }, + { 1.234321234321234e21, "1.234321e+21" }, + { 1.234321234321234e22, "1.234321e+22" }, + { 1.234321234321234e23, "1.234321e+23" }, + { 1.234321234321234e24, "1.234321e+24" }, + { 1.234321234321234e25, "1.234321e+25" }, + { 1.234321234321234e26, "1.234321e+26" }, + { 1.234321234321234e27, "1.234321e+27" }, + { 1.234321234321234e28, "1.234321e+28" }, + { 1.234321234321234e29, "1.234321e+29" }, + { 1.234321234321234e30, "1.234321e+30" }, + { 1.234321234321234e31, "1.234321e+31" }, + { 1.234321234321234e32, "1.234321e+32" }, + { 1.234321234321234e33, "1.234321e+33" }, + { 1.234321234321234e34, "1.234321e+34" }, + { 1.234321234321234e35, "1.234321e+35" }, + { 1.234321234321234e36, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char *result; - int retval = - my_asprintf (&result, "%e", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); - free (result); + char *result; + int retval = + my_asprintf (&result, "%e", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); + free (result); } } @@ -2012,7 +2012,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", -0.03125, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2023,7 +2023,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2035,7 +2035,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) ASSERT (result != NULL); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2046,7 +2046,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2057,7 +2057,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2068,8 +2068,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2080,7 +2080,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2091,7 +2091,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%-15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2102,7 +2102,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%+e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2113,7 +2113,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "% e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2124,7 +2124,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2135,7 +2135,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#.e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2146,7 +2146,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#.e %d", 9.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2157,7 +2157,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2168,7 +2168,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015e %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2179,8 +2179,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%050e %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2191,7 +2191,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2202,7 +2202,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.4e %d", 999.951, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2213,7 +2213,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.4e %d", 999.996, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2224,7 +2224,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", 12.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2235,7 +2235,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", 1234567.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.234567e+06 33") == 0 - || strcmp (result, "1.234567e+006 33") == 0); + || strcmp (result, "1.234567e+006 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2243,99 +2243,99 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.234321e-37" }, - { 1.234321234321234e-36L, "1.234321e-36" }, - { 1.234321234321234e-35L, "1.234321e-35" }, - { 1.234321234321234e-34L, "1.234321e-34" }, - { 1.234321234321234e-33L, "1.234321e-33" }, - { 1.234321234321234e-32L, "1.234321e-32" }, - { 1.234321234321234e-31L, "1.234321e-31" }, - { 1.234321234321234e-30L, "1.234321e-30" }, - { 1.234321234321234e-29L, "1.234321e-29" }, - { 1.234321234321234e-28L, "1.234321e-28" }, - { 1.234321234321234e-27L, "1.234321e-27" }, - { 1.234321234321234e-26L, "1.234321e-26" }, - { 1.234321234321234e-25L, "1.234321e-25" }, - { 1.234321234321234e-24L, "1.234321e-24" }, - { 1.234321234321234e-23L, "1.234321e-23" }, - { 1.234321234321234e-22L, "1.234321e-22" }, - { 1.234321234321234e-21L, "1.234321e-21" }, - { 1.234321234321234e-20L, "1.234321e-20" }, - { 1.234321234321234e-19L, "1.234321e-19" }, - { 1.234321234321234e-18L, "1.234321e-18" }, - { 1.234321234321234e-17L, "1.234321e-17" }, - { 1.234321234321234e-16L, "1.234321e-16" }, - { 1.234321234321234e-15L, "1.234321e-15" }, - { 1.234321234321234e-14L, "1.234321e-14" }, - { 1.234321234321234e-13L, "1.234321e-13" }, - { 1.234321234321234e-12L, "1.234321e-12" }, - { 1.234321234321234e-11L, "1.234321e-11" }, - { 1.234321234321234e-10L, "1.234321e-10" }, - { 1.234321234321234e-9L, "1.234321e-09" }, - { 1.234321234321234e-8L, "1.234321e-08" }, - { 1.234321234321234e-7L, "1.234321e-07" }, - { 1.234321234321234e-6L, "1.234321e-06" }, - { 1.234321234321234e-5L, "1.234321e-05" }, - { 1.234321234321234e-4L, "1.234321e-04" }, - { 1.234321234321234e-3L, "1.234321e-03" }, - { 1.234321234321234e-2L, "1.234321e-02" }, - { 1.234321234321234e-1L, "1.234321e-01" }, - { 1.234321234321234L, "1.234321e+00" }, - { 1.234321234321234e1L, "1.234321e+01" }, - { 1.234321234321234e2L, "1.234321e+02" }, - { 1.234321234321234e3L, "1.234321e+03" }, - { 1.234321234321234e4L, "1.234321e+04" }, - { 1.234321234321234e5L, "1.234321e+05" }, - { 1.234321234321234e6L, "1.234321e+06" }, - { 1.234321234321234e7L, "1.234321e+07" }, - { 1.234321234321234e8L, "1.234321e+08" }, - { 1.234321234321234e9L, "1.234321e+09" }, - { 1.234321234321234e10L, "1.234321e+10" }, - { 1.234321234321234e11L, "1.234321e+11" }, - { 1.234321234321234e12L, "1.234321e+12" }, - { 1.234321234321234e13L, "1.234321e+13" }, - { 1.234321234321234e14L, "1.234321e+14" }, - { 1.234321234321234e15L, "1.234321e+15" }, - { 1.234321234321234e16L, "1.234321e+16" }, - { 1.234321234321234e17L, "1.234321e+17" }, - { 1.234321234321234e18L, "1.234321e+18" }, - { 1.234321234321234e19L, "1.234321e+19" }, - { 1.234321234321234e20L, "1.234321e+20" }, - { 1.234321234321234e21L, "1.234321e+21" }, - { 1.234321234321234e22L, "1.234321e+22" }, - { 1.234321234321234e23L, "1.234321e+23" }, - { 1.234321234321234e24L, "1.234321e+24" }, - { 1.234321234321234e25L, "1.234321e+25" }, - { 1.234321234321234e26L, "1.234321e+26" }, - { 1.234321234321234e27L, "1.234321e+27" }, - { 1.234321234321234e28L, "1.234321e+28" }, - { 1.234321234321234e29L, "1.234321e+29" }, - { 1.234321234321234e30L, "1.234321e+30" }, - { 1.234321234321234e31L, "1.234321e+31" }, - { 1.234321234321234e32L, "1.234321e+32" }, - { 1.234321234321234e33L, "1.234321e+33" }, - { 1.234321234321234e34L, "1.234321e+34" }, - { 1.234321234321234e35L, "1.234321e+35" }, - { 1.234321234321234e36L, "1.234321e+36" } + { 1.234321234321234e-37L, "1.234321e-37" }, + { 1.234321234321234e-36L, "1.234321e-36" }, + { 1.234321234321234e-35L, "1.234321e-35" }, + { 1.234321234321234e-34L, "1.234321e-34" }, + { 1.234321234321234e-33L, "1.234321e-33" }, + { 1.234321234321234e-32L, "1.234321e-32" }, + { 1.234321234321234e-31L, "1.234321e-31" }, + { 1.234321234321234e-30L, "1.234321e-30" }, + { 1.234321234321234e-29L, "1.234321e-29" }, + { 1.234321234321234e-28L, "1.234321e-28" }, + { 1.234321234321234e-27L, "1.234321e-27" }, + { 1.234321234321234e-26L, "1.234321e-26" }, + { 1.234321234321234e-25L, "1.234321e-25" }, + { 1.234321234321234e-24L, "1.234321e-24" }, + { 1.234321234321234e-23L, "1.234321e-23" }, + { 1.234321234321234e-22L, "1.234321e-22" }, + { 1.234321234321234e-21L, "1.234321e-21" }, + { 1.234321234321234e-20L, "1.234321e-20" }, + { 1.234321234321234e-19L, "1.234321e-19" }, + { 1.234321234321234e-18L, "1.234321e-18" }, + { 1.234321234321234e-17L, "1.234321e-17" }, + { 1.234321234321234e-16L, "1.234321e-16" }, + { 1.234321234321234e-15L, "1.234321e-15" }, + { 1.234321234321234e-14L, "1.234321e-14" }, + { 1.234321234321234e-13L, "1.234321e-13" }, + { 1.234321234321234e-12L, "1.234321e-12" }, + { 1.234321234321234e-11L, "1.234321e-11" }, + { 1.234321234321234e-10L, "1.234321e-10" }, + { 1.234321234321234e-9L, "1.234321e-09" }, + { 1.234321234321234e-8L, "1.234321e-08" }, + { 1.234321234321234e-7L, "1.234321e-07" }, + { 1.234321234321234e-6L, "1.234321e-06" }, + { 1.234321234321234e-5L, "1.234321e-05" }, + { 1.234321234321234e-4L, "1.234321e-04" }, + { 1.234321234321234e-3L, "1.234321e-03" }, + { 1.234321234321234e-2L, "1.234321e-02" }, + { 1.234321234321234e-1L, "1.234321e-01" }, + { 1.234321234321234L, "1.234321e+00" }, + { 1.234321234321234e1L, "1.234321e+01" }, + { 1.234321234321234e2L, "1.234321e+02" }, + { 1.234321234321234e3L, "1.234321e+03" }, + { 1.234321234321234e4L, "1.234321e+04" }, + { 1.234321234321234e5L, "1.234321e+05" }, + { 1.234321234321234e6L, "1.234321e+06" }, + { 1.234321234321234e7L, "1.234321e+07" }, + { 1.234321234321234e8L, "1.234321e+08" }, + { 1.234321234321234e9L, "1.234321e+09" }, + { 1.234321234321234e10L, "1.234321e+10" }, + { 1.234321234321234e11L, "1.234321e+11" }, + { 1.234321234321234e12L, "1.234321e+12" }, + { 1.234321234321234e13L, "1.234321e+13" }, + { 1.234321234321234e14L, "1.234321e+14" }, + { 1.234321234321234e15L, "1.234321e+15" }, + { 1.234321234321234e16L, "1.234321e+16" }, + { 1.234321234321234e17L, "1.234321e+17" }, + { 1.234321234321234e18L, "1.234321e+18" }, + { 1.234321234321234e19L, "1.234321e+19" }, + { 1.234321234321234e20L, "1.234321e+20" }, + { 1.234321234321234e21L, "1.234321e+21" }, + { 1.234321234321234e22L, "1.234321e+22" }, + { 1.234321234321234e23L, "1.234321e+23" }, + { 1.234321234321234e24L, "1.234321e+24" }, + { 1.234321234321234e25L, "1.234321e+25" }, + { 1.234321234321234e26L, "1.234321e+26" }, + { 1.234321234321234e27L, "1.234321e+27" }, + { 1.234321234321234e28L, "1.234321e+28" }, + { 1.234321234321234e29L, "1.234321e+29" }, + { 1.234321234321234e30L, "1.234321e+30" }, + { 1.234321234321234e31L, "1.234321e+31" }, + { 1.234321234321234e32L, "1.234321e+32" }, + { 1.234321234321234e33L, "1.234321e+33" }, + { 1.234321234321234e34L, "1.234321e+34" }, + { 1.234321234321234e35L, "1.234321e+35" }, + { 1.234321234321234e36L, "1.234321e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char *result; - int retval = - my_asprintf (&result, "%Le", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); - free (result); + char *result; + int retval = + my_asprintf (&result, "%Le", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); + free (result); } } @@ -2345,7 +2345,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", -0.03125L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-3.125000e-02 33") == 0 - || strcmp (result, "-3.125000e-002 33") == 0); + || strcmp (result, "-3.125000e-002 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2356,7 +2356,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0.000000e+00 33") == 0 - || strcmp (result, "0.000000e+000 33") == 0); + || strcmp (result, "0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2368,7 +2368,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) ASSERT (result != NULL); if (have_minus_zero ()) ASSERT (strcmp (result, "-0.000000e+00 33") == 0 - || strcmp (result, "-0.000000e+000 33") == 0); + || strcmp (result, "-0.000000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2379,7 +2379,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2390,7 +2390,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2401,8 +2401,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2415,8 +2415,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2429,8 +2429,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2449,8 +2449,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2462,8 +2462,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2475,8 +2475,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2488,8 +2488,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2501,8 +2501,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Le %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2514,7 +2514,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%15Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2525,7 +2525,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%-15Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2536,7 +2536,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%+Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "+1.750000e+00 33") == 0 - || strcmp (result, "+1.750000e+000 33") == 0); + || strcmp (result, "+1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2547,7 +2547,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "% Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2558,7 +2558,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.750000e+00 33") == 0 - || strcmp (result, "1.750000e+000 33") == 0); + || strcmp (result, "1.750000e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2569,7 +2569,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#.Le %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "2.e+00 33") == 0 - || strcmp (result, "2.e+000 33") == 0); + || strcmp (result, "2.e+000 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2580,7 +2580,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#.Le %d", 9.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2591,7 +2591,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015Le %d", 1234.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0001.234000e+03 33") == 0 - || strcmp (result, "001.234000e+003 33") == 0); + || strcmp (result, "001.234000e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2602,7 +2602,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015Le %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2613,8 +2613,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%050Le %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2625,7 +2625,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.Le %d", 1234.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2636,7 +2636,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.4Le %d", 999.951L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "9.9995e+02 33") == 0 - || strcmp (result, "9.9995e+002 33") == 0); + || strcmp (result, "9.9995e+002 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2647,7 +2647,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.4Le %d", 999.996L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.0000e+03 33") == 0 - || strcmp (result, "1.0000e+003 33") == 0); + || strcmp (result, "1.0000e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2670,7 +2670,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%g %d", 1234567.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2678,100 +2678,100 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* Small and large positive numbers. */ static struct { double value; const char *string; } data[] = { - { 1.234321234321234e-37, "1.23432e-37" }, - { 1.234321234321234e-36, "1.23432e-36" }, - { 1.234321234321234e-35, "1.23432e-35" }, - { 1.234321234321234e-34, "1.23432e-34" }, - { 1.234321234321234e-33, "1.23432e-33" }, - { 1.234321234321234e-32, "1.23432e-32" }, - { 1.234321234321234e-31, "1.23432e-31" }, - { 1.234321234321234e-30, "1.23432e-30" }, - { 1.234321234321234e-29, "1.23432e-29" }, - { 1.234321234321234e-28, "1.23432e-28" }, - { 1.234321234321234e-27, "1.23432e-27" }, - { 1.234321234321234e-26, "1.23432e-26" }, - { 1.234321234321234e-25, "1.23432e-25" }, - { 1.234321234321234e-24, "1.23432e-24" }, - { 1.234321234321234e-23, "1.23432e-23" }, - { 1.234321234321234e-22, "1.23432e-22" }, - { 1.234321234321234e-21, "1.23432e-21" }, - { 1.234321234321234e-20, "1.23432e-20" }, - { 1.234321234321234e-19, "1.23432e-19" }, - { 1.234321234321234e-18, "1.23432e-18" }, - { 1.234321234321234e-17, "1.23432e-17" }, - { 1.234321234321234e-16, "1.23432e-16" }, - { 1.234321234321234e-15, "1.23432e-15" }, - { 1.234321234321234e-14, "1.23432e-14" }, - { 1.234321234321234e-13, "1.23432e-13" }, - { 1.234321234321234e-12, "1.23432e-12" }, - { 1.234321234321234e-11, "1.23432e-11" }, - { 1.234321234321234e-10, "1.23432e-10" }, - { 1.234321234321234e-9, "1.23432e-09" }, - { 1.234321234321234e-8, "1.23432e-08" }, - { 1.234321234321234e-7, "1.23432e-07" }, - { 1.234321234321234e-6, "1.23432e-06" }, - { 1.234321234321234e-5, "1.23432e-05" }, - { 1.234321234321234e-4, "0.000123432" }, - { 1.234321234321234e-3, "0.00123432" }, - { 1.234321234321234e-2, "0.0123432" }, - { 1.234321234321234e-1, "0.123432" }, - { 1.234321234321234, "1.23432" }, - { 1.234321234321234e1, "12.3432" }, - { 1.234321234321234e2, "123.432" }, - { 1.234321234321234e3, "1234.32" }, - { 1.234321234321234e4, "12343.2" }, - { 1.234321234321234e5, "123432" }, - { 1.234321234321234e6, "1.23432e+06" }, - { 1.234321234321234e7, "1.23432e+07" }, - { 1.234321234321234e8, "1.23432e+08" }, - { 1.234321234321234e9, "1.23432e+09" }, - { 1.234321234321234e10, "1.23432e+10" }, - { 1.234321234321234e11, "1.23432e+11" }, - { 1.234321234321234e12, "1.23432e+12" }, - { 1.234321234321234e13, "1.23432e+13" }, - { 1.234321234321234e14, "1.23432e+14" }, - { 1.234321234321234e15, "1.23432e+15" }, - { 1.234321234321234e16, "1.23432e+16" }, - { 1.234321234321234e17, "1.23432e+17" }, - { 1.234321234321234e18, "1.23432e+18" }, - { 1.234321234321234e19, "1.23432e+19" }, - { 1.234321234321234e20, "1.23432e+20" }, - { 1.234321234321234e21, "1.23432e+21" }, - { 1.234321234321234e22, "1.23432e+22" }, - { 1.234321234321234e23, "1.23432e+23" }, - { 1.234321234321234e24, "1.23432e+24" }, - { 1.234321234321234e25, "1.23432e+25" }, - { 1.234321234321234e26, "1.23432e+26" }, - { 1.234321234321234e27, "1.23432e+27" }, - { 1.234321234321234e28, "1.23432e+28" }, - { 1.234321234321234e29, "1.23432e+29" }, - { 1.234321234321234e30, "1.23432e+30" }, - { 1.234321234321234e31, "1.23432e+31" }, - { 1.234321234321234e32, "1.23432e+32" }, - { 1.234321234321234e33, "1.23432e+33" }, - { 1.234321234321234e34, "1.23432e+34" }, - { 1.234321234321234e35, "1.23432e+35" }, - { 1.234321234321234e36, "1.23432e+36" } + { 1.234321234321234e-37, "1.23432e-37" }, + { 1.234321234321234e-36, "1.23432e-36" }, + { 1.234321234321234e-35, "1.23432e-35" }, + { 1.234321234321234e-34, "1.23432e-34" }, + { 1.234321234321234e-33, "1.23432e-33" }, + { 1.234321234321234e-32, "1.23432e-32" }, + { 1.234321234321234e-31, "1.23432e-31" }, + { 1.234321234321234e-30, "1.23432e-30" }, + { 1.234321234321234e-29, "1.23432e-29" }, + { 1.234321234321234e-28, "1.23432e-28" }, + { 1.234321234321234e-27, "1.23432e-27" }, + { 1.234321234321234e-26, "1.23432e-26" }, + { 1.234321234321234e-25, "1.23432e-25" }, + { 1.234321234321234e-24, "1.23432e-24" }, + { 1.234321234321234e-23, "1.23432e-23" }, + { 1.234321234321234e-22, "1.23432e-22" }, + { 1.234321234321234e-21, "1.23432e-21" }, + { 1.234321234321234e-20, "1.23432e-20" }, + { 1.234321234321234e-19, "1.23432e-19" }, + { 1.234321234321234e-18, "1.23432e-18" }, + { 1.234321234321234e-17, "1.23432e-17" }, + { 1.234321234321234e-16, "1.23432e-16" }, + { 1.234321234321234e-15, "1.23432e-15" }, + { 1.234321234321234e-14, "1.23432e-14" }, + { 1.234321234321234e-13, "1.23432e-13" }, + { 1.234321234321234e-12, "1.23432e-12" }, + { 1.234321234321234e-11, "1.23432e-11" }, + { 1.234321234321234e-10, "1.23432e-10" }, + { 1.234321234321234e-9, "1.23432e-09" }, + { 1.234321234321234e-8, "1.23432e-08" }, + { 1.234321234321234e-7, "1.23432e-07" }, + { 1.234321234321234e-6, "1.23432e-06" }, + { 1.234321234321234e-5, "1.23432e-05" }, + { 1.234321234321234e-4, "0.000123432" }, + { 1.234321234321234e-3, "0.00123432" }, + { 1.234321234321234e-2, "0.0123432" }, + { 1.234321234321234e-1, "0.123432" }, + { 1.234321234321234, "1.23432" }, + { 1.234321234321234e1, "12.3432" }, + { 1.234321234321234e2, "123.432" }, + { 1.234321234321234e3, "1234.32" }, + { 1.234321234321234e4, "12343.2" }, + { 1.234321234321234e5, "123432" }, + { 1.234321234321234e6, "1.23432e+06" }, + { 1.234321234321234e7, "1.23432e+07" }, + { 1.234321234321234e8, "1.23432e+08" }, + { 1.234321234321234e9, "1.23432e+09" }, + { 1.234321234321234e10, "1.23432e+10" }, + { 1.234321234321234e11, "1.23432e+11" }, + { 1.234321234321234e12, "1.23432e+12" }, + { 1.234321234321234e13, "1.23432e+13" }, + { 1.234321234321234e14, "1.23432e+14" }, + { 1.234321234321234e15, "1.23432e+15" }, + { 1.234321234321234e16, "1.23432e+16" }, + { 1.234321234321234e17, "1.23432e+17" }, + { 1.234321234321234e18, "1.23432e+18" }, + { 1.234321234321234e19, "1.23432e+19" }, + { 1.234321234321234e20, "1.23432e+20" }, + { 1.234321234321234e21, "1.23432e+21" }, + { 1.234321234321234e22, "1.23432e+22" }, + { 1.234321234321234e23, "1.23432e+23" }, + { 1.234321234321234e24, "1.23432e+24" }, + { 1.234321234321234e25, "1.23432e+25" }, + { 1.234321234321234e26, "1.23432e+26" }, + { 1.234321234321234e27, "1.23432e+27" }, + { 1.234321234321234e28, "1.23432e+28" }, + { 1.234321234321234e29, "1.23432e+29" }, + { 1.234321234321234e30, "1.23432e+30" }, + { 1.234321234321234e31, "1.23432e+31" }, + { 1.234321234321234e32, "1.23432e+32" }, + { 1.234321234321234e33, "1.23432e+33" }, + { 1.234321234321234e34, "1.23432e+34" }, + { 1.234321234321234e35, "1.23432e+35" }, + { 1.234321234321234e36, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char *result; - int retval = - my_asprintf (&result, "%g", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); - free (result); + char *result; + int retval = + my_asprintf (&result, "%g", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); + free (result); } } @@ -2812,7 +2812,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%g %d", 1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2823,7 +2823,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2834,8 +2834,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2906,7 +2906,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#.g %d", 9.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2927,7 +2927,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015g %d", -1.0 / 0.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2938,8 +2938,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%050g %d", NaNd (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2950,7 +2950,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.g %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2991,7 +2991,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", 1234567.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.23457e+06 33") == 0 - || strcmp (result, "1.23457e+006 33") == 0); + || strcmp (result, "1.23457e+006 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -2999,100 +2999,100 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) { /* Small and large positive numbers. */ static struct { long double value; const char *string; } data[] = { - { 1.234321234321234e-37L, "1.23432e-37" }, - { 1.234321234321234e-36L, "1.23432e-36" }, - { 1.234321234321234e-35L, "1.23432e-35" }, - { 1.234321234321234e-34L, "1.23432e-34" }, - { 1.234321234321234e-33L, "1.23432e-33" }, - { 1.234321234321234e-32L, "1.23432e-32" }, - { 1.234321234321234e-31L, "1.23432e-31" }, - { 1.234321234321234e-30L, "1.23432e-30" }, - { 1.234321234321234e-29L, "1.23432e-29" }, - { 1.234321234321234e-28L, "1.23432e-28" }, - { 1.234321234321234e-27L, "1.23432e-27" }, - { 1.234321234321234e-26L, "1.23432e-26" }, - { 1.234321234321234e-25L, "1.23432e-25" }, - { 1.234321234321234e-24L, "1.23432e-24" }, - { 1.234321234321234e-23L, "1.23432e-23" }, - { 1.234321234321234e-22L, "1.23432e-22" }, - { 1.234321234321234e-21L, "1.23432e-21" }, - { 1.234321234321234e-20L, "1.23432e-20" }, - { 1.234321234321234e-19L, "1.23432e-19" }, - { 1.234321234321234e-18L, "1.23432e-18" }, - { 1.234321234321234e-17L, "1.23432e-17" }, - { 1.234321234321234e-16L, "1.23432e-16" }, - { 1.234321234321234e-15L, "1.23432e-15" }, - { 1.234321234321234e-14L, "1.23432e-14" }, - { 1.234321234321234e-13L, "1.23432e-13" }, - { 1.234321234321234e-12L, "1.23432e-12" }, - { 1.234321234321234e-11L, "1.23432e-11" }, - { 1.234321234321234e-10L, "1.23432e-10" }, - { 1.234321234321234e-9L, "1.23432e-09" }, - { 1.234321234321234e-8L, "1.23432e-08" }, - { 1.234321234321234e-7L, "1.23432e-07" }, - { 1.234321234321234e-6L, "1.23432e-06" }, - { 1.234321234321234e-5L, "1.23432e-05" }, - { 1.234321234321234e-4L, "0.000123432" }, - { 1.234321234321234e-3L, "0.00123432" }, - { 1.234321234321234e-2L, "0.0123432" }, - { 1.234321234321234e-1L, "0.123432" }, - { 1.234321234321234L, "1.23432" }, - { 1.234321234321234e1L, "12.3432" }, - { 1.234321234321234e2L, "123.432" }, - { 1.234321234321234e3L, "1234.32" }, - { 1.234321234321234e4L, "12343.2" }, - { 1.234321234321234e5L, "123432" }, - { 1.234321234321234e6L, "1.23432e+06" }, - { 1.234321234321234e7L, "1.23432e+07" }, - { 1.234321234321234e8L, "1.23432e+08" }, - { 1.234321234321234e9L, "1.23432e+09" }, - { 1.234321234321234e10L, "1.23432e+10" }, - { 1.234321234321234e11L, "1.23432e+11" }, - { 1.234321234321234e12L, "1.23432e+12" }, - { 1.234321234321234e13L, "1.23432e+13" }, - { 1.234321234321234e14L, "1.23432e+14" }, - { 1.234321234321234e15L, "1.23432e+15" }, - { 1.234321234321234e16L, "1.23432e+16" }, - { 1.234321234321234e17L, "1.23432e+17" }, - { 1.234321234321234e18L, "1.23432e+18" }, - { 1.234321234321234e19L, "1.23432e+19" }, - { 1.234321234321234e20L, "1.23432e+20" }, - { 1.234321234321234e21L, "1.23432e+21" }, - { 1.234321234321234e22L, "1.23432e+22" }, - { 1.234321234321234e23L, "1.23432e+23" }, - { 1.234321234321234e24L, "1.23432e+24" }, - { 1.234321234321234e25L, "1.23432e+25" }, - { 1.234321234321234e26L, "1.23432e+26" }, - { 1.234321234321234e27L, "1.23432e+27" }, - { 1.234321234321234e28L, "1.23432e+28" }, - { 1.234321234321234e29L, "1.23432e+29" }, - { 1.234321234321234e30L, "1.23432e+30" }, - { 1.234321234321234e31L, "1.23432e+31" }, - { 1.234321234321234e32L, "1.23432e+32" }, - { 1.234321234321234e33L, "1.23432e+33" }, - { 1.234321234321234e34L, "1.23432e+34" }, - { 1.234321234321234e35L, "1.23432e+35" }, - { 1.234321234321234e36L, "1.23432e+36" } + { 1.234321234321234e-37L, "1.23432e-37" }, + { 1.234321234321234e-36L, "1.23432e-36" }, + { 1.234321234321234e-35L, "1.23432e-35" }, + { 1.234321234321234e-34L, "1.23432e-34" }, + { 1.234321234321234e-33L, "1.23432e-33" }, + { 1.234321234321234e-32L, "1.23432e-32" }, + { 1.234321234321234e-31L, "1.23432e-31" }, + { 1.234321234321234e-30L, "1.23432e-30" }, + { 1.234321234321234e-29L, "1.23432e-29" }, + { 1.234321234321234e-28L, "1.23432e-28" }, + { 1.234321234321234e-27L, "1.23432e-27" }, + { 1.234321234321234e-26L, "1.23432e-26" }, + { 1.234321234321234e-25L, "1.23432e-25" }, + { 1.234321234321234e-24L, "1.23432e-24" }, + { 1.234321234321234e-23L, "1.23432e-23" }, + { 1.234321234321234e-22L, "1.23432e-22" }, + { 1.234321234321234e-21L, "1.23432e-21" }, + { 1.234321234321234e-20L, "1.23432e-20" }, + { 1.234321234321234e-19L, "1.23432e-19" }, + { 1.234321234321234e-18L, "1.23432e-18" }, + { 1.234321234321234e-17L, "1.23432e-17" }, + { 1.234321234321234e-16L, "1.23432e-16" }, + { 1.234321234321234e-15L, "1.23432e-15" }, + { 1.234321234321234e-14L, "1.23432e-14" }, + { 1.234321234321234e-13L, "1.23432e-13" }, + { 1.234321234321234e-12L, "1.23432e-12" }, + { 1.234321234321234e-11L, "1.23432e-11" }, + { 1.234321234321234e-10L, "1.23432e-10" }, + { 1.234321234321234e-9L, "1.23432e-09" }, + { 1.234321234321234e-8L, "1.23432e-08" }, + { 1.234321234321234e-7L, "1.23432e-07" }, + { 1.234321234321234e-6L, "1.23432e-06" }, + { 1.234321234321234e-5L, "1.23432e-05" }, + { 1.234321234321234e-4L, "0.000123432" }, + { 1.234321234321234e-3L, "0.00123432" }, + { 1.234321234321234e-2L, "0.0123432" }, + { 1.234321234321234e-1L, "0.123432" }, + { 1.234321234321234L, "1.23432" }, + { 1.234321234321234e1L, "12.3432" }, + { 1.234321234321234e2L, "123.432" }, + { 1.234321234321234e3L, "1234.32" }, + { 1.234321234321234e4L, "12343.2" }, + { 1.234321234321234e5L, "123432" }, + { 1.234321234321234e6L, "1.23432e+06" }, + { 1.234321234321234e7L, "1.23432e+07" }, + { 1.234321234321234e8L, "1.23432e+08" }, + { 1.234321234321234e9L, "1.23432e+09" }, + { 1.234321234321234e10L, "1.23432e+10" }, + { 1.234321234321234e11L, "1.23432e+11" }, + { 1.234321234321234e12L, "1.23432e+12" }, + { 1.234321234321234e13L, "1.23432e+13" }, + { 1.234321234321234e14L, "1.23432e+14" }, + { 1.234321234321234e15L, "1.23432e+15" }, + { 1.234321234321234e16L, "1.23432e+16" }, + { 1.234321234321234e17L, "1.23432e+17" }, + { 1.234321234321234e18L, "1.23432e+18" }, + { 1.234321234321234e19L, "1.23432e+19" }, + { 1.234321234321234e20L, "1.23432e+20" }, + { 1.234321234321234e21L, "1.23432e+21" }, + { 1.234321234321234e22L, "1.23432e+22" }, + { 1.234321234321234e23L, "1.23432e+23" }, + { 1.234321234321234e24L, "1.23432e+24" }, + { 1.234321234321234e25L, "1.23432e+25" }, + { 1.234321234321234e26L, "1.23432e+26" }, + { 1.234321234321234e27L, "1.23432e+27" }, + { 1.234321234321234e28L, "1.23432e+28" }, + { 1.234321234321234e29L, "1.23432e+29" }, + { 1.234321234321234e30L, "1.23432e+30" }, + { 1.234321234321234e31L, "1.23432e+31" }, + { 1.234321234321234e32L, "1.23432e+32" }, + { 1.234321234321234e33L, "1.23432e+33" }, + { 1.234321234321234e34L, "1.23432e+34" }, + { 1.234321234321234e35L, "1.23432e+35" }, + { 1.234321234321234e36L, "1.23432e+36" } }; size_t k; for (k = 0; k < SIZEOF (data); k++) { - char *result; - int retval = - my_asprintf (&result, "%Lg", data[k].value); - const char *expected = data[k].string; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - /* Some implementations produce exponents with 3 digits. */ - || (expected[strlen (expected) - 4] == 'e' - && strlen (result) == strlen (expected) + 1 - && memcmp (result, expected, strlen (expected) - 2) == 0 - && result[strlen (expected) - 2] == '0' - && strcmp (result + strlen (expected) - 1, - expected + strlen (expected) - 2) - == 0)); - ASSERT (retval == strlen (result)); - free (result); + char *result; + int retval = + my_asprintf (&result, "%Lg", data[k].value); + const char *expected = data[k].string; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + /* Some implementations produce exponents with 3 digits. */ + || (expected[strlen (expected) - 4] == 'e' + && strlen (result) == strlen (expected) + 1 + && memcmp (result, expected, strlen (expected) - 2) == 0 + && result[strlen (expected) - 2] == '0' + && strcmp (result + strlen (expected) - 1, + expected + strlen (expected) - 2) + == 0)); + ASSERT (retval == strlen (result)); + free (result); } } @@ -3133,7 +3133,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", 1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); + || strcmp (result, "infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3144,7 +3144,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "-inf 33") == 0 - || strcmp (result, "-infinity 33") == 0); + || strcmp (result, "-infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3155,8 +3155,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3169,8 +3169,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3183,8 +3183,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3203,8 +3203,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3216,8 +3216,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3229,8 +3229,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3242,8 +3242,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3255,8 +3255,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%Lg %d", x.value, 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3328,7 +3328,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%#.Lg %d", 9.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.e+01 33") == 0 - || strcmp (result, "1.e+001 33") == 0); + || strcmp (result, "1.e+001 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3349,7 +3349,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%015Lg %d", -1.0L / 0.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " -inf 33") == 0 - || strcmp (result, " -infinity 33") == 0); + || strcmp (result, " -infinity 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3360,8 +3360,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%050Lg %d", NaNl (), 33, 44, 55); ASSERT (result != NULL); ASSERT (strlen (result) == 50 + 3 - && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); + && strisnan (result, strspn (result, " "), strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3372,7 +3372,7 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) my_asprintf (&result, "%.Lg %d", 1234.0L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); ASSERT (retval == strlen (result)); free (result); } @@ -3590,19 +3590,19 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) for (i = 1; i <= 8; i++) { - char *block; - char *result; - int retval; - - block = (char *) malloc (i); - memcpy (block, "abcdefgh", i); - retval = my_asprintf (&result, "%.*s", (int) i, block); - ASSERT (result != NULL); - ASSERT (memcmp (result, block, i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (retval == strlen (result)); - free (result); - free (block); + char *block; + char *result; + int retval; + + block = (char *) malloc (i); + memcpy (block, "abcdefgh", i); + retval = my_asprintf (&result, "%.*s", (int) i, block); + ASSERT (result != NULL); + ASSERT (memcmp (result, block, i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (retval == strlen (result)); + free (result); + free (block); } } #if HAVE_WCHAR_T @@ -3611,21 +3611,21 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) for (i = 1; i <= 8; i++) { - wchar_t *block; - size_t j; - char *result; - int retval; - - block = (wchar_t *) malloc (i * sizeof (wchar_t)); - for (j = 0; j < i; j++) - block[j] = "abcdefgh"[j]; - retval = my_asprintf (&result, "%.*ls", (int) i, block); - ASSERT (result != NULL); - ASSERT (memcmp (result, "abcdefgh", i) == 0); - ASSERT (result[i] == '\0'); - ASSERT (retval == strlen (result)); - free (result); - free (block); + wchar_t *block; + size_t j; + char *result; + int retval; + + block = (wchar_t *) malloc (i * sizeof (wchar_t)); + for (j = 0; j < i; j++) + block[j] = "abcdefgh"[j]; + retval = my_asprintf (&result, "%.*ls", (int) i, block); + ASSERT (result != NULL); + ASSERT (memcmp (result, "abcdefgh", i) == 0); + ASSERT (result[i] == '\0'); + ASSERT (retval == strlen (result)); + free (result); + free (block); } } #endif diff --git a/tests/test-vasprintf.c b/tests/test-vasprintf.c index 7c4a728b0..a85ff8ec4 100644 --- a/tests/test-vasprintf.c +++ b/tests/test-vasprintf.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int diff --git a/tests/test-vdprintf-posix.c b/tests/test-vdprintf-posix.c index 175046f84..949665e0c 100644 --- a/tests/test-vdprintf-posix.c +++ b/tests/test-vdprintf-posix.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-fprintf-posix.h" diff --git a/tests/test-vfprintf-posix.c b/tests/test-vfprintf-posix.c index deb3e3748..ae94fa7b9 100644 --- a/tests/test-vfprintf-posix.c +++ b/tests/test-vfprintf-posix.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-fprintf-posix.h" diff --git a/tests/test-vprintf-posix.c b/tests/test-vprintf-posix.c index 766749fee..85222831c 100644 --- a/tests/test-vprintf-posix.c +++ b/tests/test-vprintf-posix.c @@ -27,15 +27,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-printf-posix.h" diff --git a/tests/test-vsnprintf-posix.c b/tests/test-vsnprintf-posix.c index 23f3be2d0..7e152c2e8 100644 --- a/tests/test-vsnprintf-posix.c +++ b/tests/test-vsnprintf-posix.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-snprintf-posix.h" diff --git a/tests/test-vsnprintf.c b/tests/test-vsnprintf.c index 9c1be8d11..f0d08edbe 100644 --- a/tests/test-vsnprintf.c +++ b/tests/test-vsnprintf.c @@ -25,15 +25,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -60,25 +60,25 @@ main (int argc, char *argv[]) memcpy (buf, "DEADBEEF", 8); retval = my_snprintf (buf, size, "%d", 12345); if (size < 6) - { + { #if CHECK_VSNPRINTF_POSIX - ASSERT (retval < 0 || retval >= size); + ASSERT (retval < 0 || retval >= size); #endif - if (size > 0) - { - ASSERT (memcmp (buf, "12345", size - 1) == 0); - ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size); - } + if (size > 0) + { + ASSERT (memcmp (buf, "12345", size - 1) == 0); + ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size); + } #if !CHECK_VSNPRINTF_POSIX - if (size > 0) + if (size > 0) #endif - ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); - } + ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); + } else - { - ASSERT (retval == 5); - ASSERT (memcmp (buf, "12345\0EF", 8) == 0); - } + { + ASSERT (retval == 5); + ASSERT (memcmp (buf, "12345\0EF", 8) == 0); + } } return 0; diff --git a/tests/test-vsprintf-posix.c b/tests/test-vsprintf-posix.c index 959412f5e..3bb457fb5 100644 --- a/tests/test-vsprintf-posix.c +++ b/tests/test-vsprintf-posix.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-sprintf-posix.h" diff --git a/tests/test-wcrtomb.c b/tests/test-wcrtomb.c index 5ad6edca8..4fe972b46 100644 --- a/tests/test-wcrtomb.c +++ b/tests/test-wcrtomb.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Check the multibyte character s[0..n-1]. */ @@ -83,79 +83,79 @@ main (int argc, char *argv[]) for (c = 0; c < 0x100; c++) switch (c) - { - case '\t': case '\v': case '\f': - 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 '~': - /* c is in the ISO C "basic character set". */ - ret = wcrtomb (buf, btowc (c), NULL); - ASSERT (ret == 1); - ASSERT (buf[0] == (char) c); - break; - } + { + case '\t': case '\v': case '\f': + 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 '~': + /* c is in the ISO C "basic character set". */ + ret = wcrtomb (buf, btowc (c), NULL); + ASSERT (ret == 1); + ASSERT (buf[0] == (char) c); + break; + } } if (argc > 1) switch (argv[1][0]) { case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - { - const char input[] = "B\374\337er"; /* "Büßer" */ + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + const char input[] = "B\374\337er"; /* "Büßer" */ - check_character (input + 1, 1); - check_character (input + 2, 1); - } - return 0; + check_character (input + 1, 1); + check_character (input + 2, 1); + } + return 0; case '2': - /* Locale encoding is UTF-8. */ - { - const char input[] = "B\303\274\303\237er"; /* "Büßer" */ + /* Locale encoding is UTF-8. */ + { + const char input[] = "B\303\274\303\237er"; /* "Büßer" */ - check_character (input + 1, 2); - check_character (input + 3, 2); - } - return 0; + check_character (input + 1, 2); + check_character (input + 3, 2); + } + return 0; case '3': - /* Locale encoding is EUC-JP. */ - { - const char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ + /* Locale encoding is EUC-JP. */ + { + const char input[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ - check_character (input + 1, 2); - check_character (input + 3, 2); - check_character (input + 5, 2); - } - return 0; + check_character (input + 1, 2); + check_character (input + 3, 2); + check_character (input + 5, 2); + } + return 0; case '4': - /* Locale encoding is GB18030. */ - { - const char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ - - check_character (input + 1, 2); - check_character (input + 3, 4); - } - return 0; + /* Locale encoding is GB18030. */ + { + const char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + + check_character (input + 1, 2); + check_character (input + 3, 4); + } + return 0; } return 1; diff --git a/tests/test-wcsnrtombs.c b/tests/test-wcsnrtombs.c index 20529948e..38c0441b4 100644 --- a/tests/test-wcsnrtombs.c +++ b/tests/test-wcsnrtombs.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -54,153 +54,153 @@ main (int argc, char *argv[]) size_t ret; { - size_t i; - for (i = 0; i < BUFSIZE; i++) - buf[i] = '_'; + size_t i; + for (i = 0; i < BUFSIZE; i++) + buf[i] = '_'; } switch (argv[1][0]) - { - case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - { - const char original[] = "B\374\337er"; /* "Büßer" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsnrtombs (NULL, &src, 6, n, NULL); - ASSERT (ret == 5); - ASSERT (src == input); - - src = input; - ret = wcsnrtombs (buf, &src, 6, n, NULL); - ASSERT (ret == (n <= 5 ? n : 5)); - ASSERT (src == (n <= 5 ? input + n : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - case '2': - /* Locale encoding is UTF-8. */ - { - const char original[] = "B\303\274\303\237er"; /* "Büßer" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsnrtombs (NULL, &src, 6, n, NULL); - ASSERT (ret == 7); - ASSERT (src == input); - - src = input; - ret = wcsnrtombs (buf, &src, 6, n, NULL); - ASSERT (ret == (n < 1 ? n : - n < 3 ? 1 : - n < 5 ? 3 : - n <= 7 ? n : 7)); - ASSERT (src == (n < 1 ? input + n : - n < 3 ? input + 1 : - n < 5 ? input + 2 : - n <= 7 ? input + (n - 2) : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - case '3': - /* Locale encoding is EUC-JP. */ - { - const char original[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsnrtombs (NULL, &src, 6, n, NULL); - ASSERT (ret == 8); - ASSERT (src == input); - - src = input; - ret = wcsnrtombs (buf, &src, 6, n, NULL); - ASSERT (ret == (n < 1 ? n : - n < 3 ? 1 : - n < 5 ? 3 : - n < 7 ? 5 : - n <= 8 ? n : 8)); - ASSERT (src == (n < 1 ? input + n : - n < 3 ? input + 1 : - n < 5 ? input + 2 : - n < 7 ? input + 3 : - n <= 8 ? input + (n - 3) : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - - case '4': - /* Locale encoding is GB18030. */ - { - const char original[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsnrtombs (NULL, &src, 6, n, NULL); - ASSERT (ret == 9); - ASSERT (src == input); - - src = input; - ret = wcsnrtombs (buf, &src, 6, n, NULL); - ASSERT (ret == (n < 1 ? n : - n < 3 ? 1 : - n < 7 ? 3 : - n <= 9 ? n : 9)); - ASSERT (src == (n < 1 ? input + n : - n < 3 ? input + 1 : - n < 7 ? input + 2 : - n <= 9 ? input + (n - 4) : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - default: - return 1; - } + { + case '1': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + const char original[] = "B\374\337er"; /* "Büßer" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsnrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret == 5); + ASSERT (src == input); + + src = input; + ret = wcsnrtombs (buf, &src, 6, n, NULL); + ASSERT (ret == (n <= 5 ? n : 5)); + ASSERT (src == (n <= 5 ? input + n : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + case '2': + /* Locale encoding is UTF-8. */ + { + const char original[] = "B\303\274\303\237er"; /* "Büßer" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsnrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret == 7); + ASSERT (src == input); + + src = input; + ret = wcsnrtombs (buf, &src, 6, n, NULL); + ASSERT (ret == (n < 1 ? n : + n < 3 ? 1 : + n < 5 ? 3 : + n <= 7 ? n : 7)); + ASSERT (src == (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 5 ? input + 2 : + n <= 7 ? input + (n - 2) : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + case '3': + /* Locale encoding is EUC-JP. */ + { + const char original[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsnrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret == 8); + ASSERT (src == input); + + src = input; + ret = wcsnrtombs (buf, &src, 6, n, NULL); + ASSERT (ret == (n < 1 ? n : + n < 3 ? 1 : + n < 5 ? 3 : + n < 7 ? 5 : + n <= 8 ? n : 8)); + ASSERT (src == (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 5 ? input + 2 : + n < 7 ? input + 3 : + n <= 8 ? input + (n - 3) : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + + case '4': + /* Locale encoding is GB18030. */ + { + const char original[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsnrtombs (NULL, &src, 6, n, NULL); + ASSERT (ret == 9); + ASSERT (src == input); + + src = input; + ret = wcsnrtombs (buf, &src, 6, n, NULL); + ASSERT (ret == (n < 1 ? n : + n < 3 ? 1 : + n < 7 ? 3 : + n <= 9 ? n : 9)); + ASSERT (src == (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 7 ? input + 2 : + n <= 9 ? input + (n - 4) : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + default: + return 1; + } return 0; } diff --git a/tests/test-wcsrtombs.c b/tests/test-wcsrtombs.c index 0d147ca96..3ceb7c0f6 100644 --- a/tests/test-wcsrtombs.c +++ b/tests/test-wcsrtombs.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -54,153 +54,153 @@ main (int argc, char *argv[]) size_t ret; { - size_t i; - for (i = 0; i < BUFSIZE; i++) - buf[i] = '_'; + size_t i; + for (i = 0; i < BUFSIZE; i++) + buf[i] = '_'; } switch (argv[1][0]) - { - case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - { - const char original[] = "B\374\337er"; /* "Büßer" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsrtombs (NULL, &src, n, NULL); - ASSERT (ret == 5); - ASSERT (src == input); - - src = input; - ret = wcsrtombs (buf, &src, n, NULL); - ASSERT (ret == (n <= 5 ? n : 5)); - ASSERT (src == (n <= 5 ? input + n : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - case '2': - /* Locale encoding is UTF-8. */ - { - const char original[] = "B\303\274\303\237er"; /* "Büßer" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsrtombs (NULL, &src, n, NULL); - ASSERT (ret == 7); - ASSERT (src == input); - - src = input; - ret = wcsrtombs (buf, &src, n, NULL); - ASSERT (ret == (n < 1 ? n : - n < 3 ? 1 : - n < 5 ? 3 : - n <= 7 ? n : 7)); - ASSERT (src == (n < 1 ? input + n : - n < 3 ? input + 1 : - n < 5 ? input + 2 : - n <= 7 ? input + (n - 2) : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - case '3': - /* Locale encoding is EUC-JP. */ - { - const char original[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsrtombs (NULL, &src, n, NULL); - ASSERT (ret == 8); - ASSERT (src == input); - - src = input; - ret = wcsrtombs (buf, &src, n, NULL); - ASSERT (ret == (n < 1 ? n : - n < 3 ? 1 : - n < 5 ? 3 : - n < 7 ? 5 : - n <= 8 ? n : 8)); - ASSERT (src == (n < 1 ? input + n : - n < 3 ? input + 1 : - n < 5 ? input + 2 : - n < 7 ? input + 3 : - n <= 8 ? input + (n - 3) : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - - case '4': - /* Locale encoding is GB18030. */ - { - const char original[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ - - ret = mbstowcs (input, original, 10); - ASSERT (ret == 5); - - for (n = 0; n < 10; n++) - { - src = input; - ret = wcsrtombs (NULL, &src, n, NULL); - ASSERT (ret == 9); - ASSERT (src == input); - - src = input; - ret = wcsrtombs (buf, &src, n, NULL); - ASSERT (ret == (n < 1 ? n : - n < 3 ? 1 : - n < 7 ? 3 : - n <= 9 ? n : 9)); - ASSERT (src == (n < 1 ? input + n : - n < 3 ? input + 1 : - n < 7 ? input + 2 : - n <= 9 ? input + (n - 4) : NULL)); - ASSERT (memcmp (buf, original, ret) == 0); - if (src == NULL) - ASSERT (buf[ret] == '\0'); - ASSERT (buf[ret + (src == NULL) + 0] == '_'); - ASSERT (buf[ret + (src == NULL) + 1] == '_'); - ASSERT (buf[ret + (src == NULL) + 2] == '_'); - } - } - break; - - default: - return 1; - } + { + case '1': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + const char original[] = "B\374\337er"; /* "Büßer" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsrtombs (NULL, &src, n, NULL); + ASSERT (ret == 5); + ASSERT (src == input); + + src = input; + ret = wcsrtombs (buf, &src, n, NULL); + ASSERT (ret == (n <= 5 ? n : 5)); + ASSERT (src == (n <= 5 ? input + n : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + case '2': + /* Locale encoding is UTF-8. */ + { + const char original[] = "B\303\274\303\237er"; /* "Büßer" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsrtombs (NULL, &src, n, NULL); + ASSERT (ret == 7); + ASSERT (src == input); + + src = input; + ret = wcsrtombs (buf, &src, n, NULL); + ASSERT (ret == (n < 1 ? n : + n < 3 ? 1 : + n < 5 ? 3 : + n <= 7 ? n : 7)); + ASSERT (src == (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 5 ? input + 2 : + n <= 7 ? input + (n - 2) : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + case '3': + /* Locale encoding is EUC-JP. */ + { + const char original[] = "<\306\374\313\334\270\354>"; /* "<日本語>" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsrtombs (NULL, &src, n, NULL); + ASSERT (ret == 8); + ASSERT (src == input); + + src = input; + ret = wcsrtombs (buf, &src, n, NULL); + ASSERT (ret == (n < 1 ? n : + n < 3 ? 1 : + n < 5 ? 3 : + n < 7 ? 5 : + n <= 8 ? n : 8)); + ASSERT (src == (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 5 ? input + 2 : + n < 7 ? input + 3 : + n <= 8 ? input + (n - 3) : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + + case '4': + /* Locale encoding is GB18030. */ + { + const char original[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ + + ret = mbstowcs (input, original, 10); + ASSERT (ret == 5); + + for (n = 0; n < 10; n++) + { + src = input; + ret = wcsrtombs (NULL, &src, n, NULL); + ASSERT (ret == 9); + ASSERT (src == input); + + src = input; + ret = wcsrtombs (buf, &src, n, NULL); + ASSERT (ret == (n < 1 ? n : + n < 3 ? 1 : + n < 7 ? 3 : + n <= 9 ? n : 9)); + ASSERT (src == (n < 1 ? input + n : + n < 3 ? input + 1 : + n < 7 ? input + 2 : + n <= 9 ? input + (n - 4) : NULL)); + ASSERT (memcmp (buf, original, ret) == 0); + if (src == NULL) + ASSERT (buf[ret] == '\0'); + ASSERT (buf[ret + (src == NULL) + 0] == '_'); + ASSERT (buf[ret + (src == NULL) + 1] == '_'); + ASSERT (buf[ret + (src == NULL) + 2] == '_'); + } + } + break; + + default: + return 1; + } return 0; } diff --git a/tests/test-wctype.c b/tests/test-wctype.c index a39514a74..bc28b157f 100644 --- a/tests/test-wctype.c +++ b/tests/test-wctype.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Check that the type wint_t is defined. */ diff --git a/tests/test-wcwidth.c b/tests/test-wcwidth.c index 582a8aa2e..5087b088d 100644 --- a/tests/test-wcwidth.c +++ b/tests/test-wcwidth.c @@ -28,15 +28,15 @@ #include "localcharset.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -51,15 +51,15 @@ main () /* Switch to an UTF-8 locale. */ if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL /* Check whether it's really an UTF-8 locale. - On OpenBSD 4.0, the setlocale call succeeds only for the LC_CTYPE - category and therefore returns "C/fr_FR.UTF-8/C/C/C/C", but the - LC_CTYPE category is effectively set to an ASCII LC_CTYPE category; - in particular, locale_charset() returns "ASCII". */ + On OpenBSD 4.0, the setlocale call succeeds only for the LC_CTYPE + category and therefore returns "C/fr_FR.UTF-8/C/C/C/C", but the + LC_CTYPE category is effectively set to an ASCII LC_CTYPE category; + in particular, locale_charset() returns "ASCII". */ && strcmp (locale_charset (), "UTF-8") == 0) { /* Test width of ASCII characters. */ for (wc = 0x20; wc < 0x7F; wc++) - ASSERT (wcwidth (wc) == 1); + ASSERT (wcwidth (wc) == 1); /* Test width of some non-spacing characters. */ ASSERT (wcwidth (0x0301) == 0); diff --git a/tests/test-xfprintf-posix.c b/tests/test-xfprintf-posix.c index b001f0426..70fb93adb 100644 --- a/tests/test-xfprintf-posix.c +++ b/tests/test-xfprintf-posix.c @@ -30,15 +30,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-fprintf-posix.h" diff --git a/tests/test-xmemdup0.c b/tests/test-xmemdup0.c index efefd94a2..2c2e9d27c 100644 --- a/tests/test-xmemdup0.c +++ b/tests/test-xmemdup0.c @@ -28,22 +28,22 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int main (int argc, char **argv) { char buffer[10] = { 'a', 'b', 'c', 'd', '\0', - 'f', 'g', 'h', 'i', 'j' }; + 'f', 'g', 'h', 'i', 'j' }; set_program_name (argv[0]); diff --git a/tests/test-xprintf-posix.c b/tests/test-xprintf-posix.c index a5ab7266e..baba0422e 100644 --- a/tests/test-xprintf-posix.c +++ b/tests/test-xprintf-posix.c @@ -29,15 +29,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-printf-posix.h" diff --git a/tests/test-xstrtol.c b/tests/test-xstrtol.c index 6aa5e895c..9db4b7f91 100644 --- a/tests/test-xstrtol.c +++ b/tests/test-xstrtol.c @@ -54,13 +54,13 @@ main (int argc, char **argv) s_err = __xstrtol (argv[i], &p, 0, &val, "bckMw0"); if (s_err == LONGINT_OK) - { - printf ("%s->%" __spec " (%s)\n", argv[i], val, p); - } + { + printf ("%s->%" __spec " (%s)\n", argv[i], val, p); + } else - { - xstrtol_fatal (s_err, -2, 'X', NULL, argv[i]); - } + { + xstrtol_fatal (s_err, -2, 'X', NULL, argv[i]); + } } exit (0); } diff --git a/tests/test-xvasprintf.c b/tests/test-xvasprintf.c index cc7070987..a18994e23 100644 --- a/tests/test-xvasprintf.c +++ b/tests/test-xvasprintf.c @@ -28,15 +28,15 @@ #include "progname.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static char * diff --git a/tests/unicase/test-casecmp.h b/tests/unicase/test-casecmp.h index d057f898e..7f2746930 100644 --- a/tests/unicase/test-casecmp.h +++ b/tests/unicase/test-casecmp.h @@ -18,7 +18,7 @@ static void test_ascii (int (*my_casecmp) (const UNIT *, size_t, const UNIT *, size_t, const char *, uninorm_t, int *), - uninorm_t nf) + uninorm_t nf) { /* Empty string. */ { diff --git a/tests/unicase/test-locale-language.c b/tests/unicase/test-locale-language.c index e8fe18157..d6a820d8b 100644 --- a/tests/unicase/test-locale-language.c +++ b/tests/unicase/test-locale-language.c @@ -26,15 +26,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unicase/test-mapping-part1.h b/tests/unicase/test-mapping-part1.h index 4b7ac8ecb..ce546e0f6 100644 --- a/tests/unicase/test-mapping-part1.h +++ b/tests/unicase/test-mapping-part1.h @@ -23,16 +23,16 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed for c = 0x%04X\n", \ - __FILE__, __LINE__, c); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed for c = 0x%04X\n", \ + __FILE__, __LINE__, c); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) diff --git a/tests/unicase/test-mapping-part2.h b/tests/unicase/test-mapping-part2.h index ef43cddea..43da716b0 100644 --- a/tests/unicase/test-mapping-part2.h +++ b/tests/unicase/test-mapping-part2.h @@ -26,7 +26,7 @@ main () for (i = 0; i < SIZEOF (mapping); i++) { for (; c < mapping[i].ch; c++) - ASSERT (MAP (c) == c); + ASSERT (MAP (c) == c); ASSERT (MAP (c) == mapping[i].value); c++; } diff --git a/tests/unicase/test-predicate-part1.h b/tests/unicase/test-predicate-part1.h index 76d804e18..1be7960b0 100644 --- a/tests/unicase/test-predicate-part1.h +++ b/tests/unicase/test-predicate-part1.h @@ -23,16 +23,16 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed for c = 0x%04X\n", \ - __FILE__, __LINE__, c); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed for c = 0x%04X\n", \ + __FILE__, __LINE__, c); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) diff --git a/tests/unicase/test-predicate-part2.h b/tests/unicase/test-predicate-part2.h index 60b7c2467..eeeb934b4 100644 --- a/tests/unicase/test-predicate-part2.h +++ b/tests/unicase/test-predicate-part2.h @@ -26,9 +26,9 @@ main () for (i = 0; i < SIZEOF (set); i++) { for (; c < set[i].start; c++) - ASSERT (!PREDICATE (c)); + ASSERT (!PREDICATE (c)); for (; c <= set[i].end; c++) - ASSERT (PREDICATE (c)); + ASSERT (PREDICATE (c)); } for (; c < 0x110000; c++) ASSERT (!PREDICATE (c)); diff --git a/tests/unicase/test-u16-casecmp.c b/tests/unicase/test-u16-casecmp.c index f079bbf84..e758b9920 100644 --- a/tests/unicase/test-u16-casecmp.c +++ b/tests/unicase/test-u16-casecmp.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint16_t @@ -127,27 +127,27 @@ test_nonascii (int (*my_casecmp) (const uint16_t *, size_t, const uint16_t *, si { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input1[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t input2[] = { 'g', 'r', 0x00FC, 0x0073, 0x0073, ' ', 'g', 'o', 't', 't', '.', ' ', - 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t input3[] = { 'G', 'R', 0x00DC, 0x0053, 0x0053, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, - 0x0419, 0x0422, 0x0415, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, - '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, + 0x0419, 0x0422, 0x0415, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, + '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; int cmp; @@ -277,21 +277,21 @@ test_nonascii (int (*my_casecmp) (const uint16_t *, size_t, const uint16_t *, si { /* "περισσότερες πληροφορίες" */ static const uint16_t input1[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint16_t input2[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 }; static const uint16_t input3[] = { - 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, - 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, - 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 + 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, + 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, + 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 }; int cmp; diff --git a/tests/unicase/test-u16-casecoll.c b/tests/unicase/test-u16-casecoll.c index 5428cf046..d5691c6ca 100644 --- a/tests/unicase/test-u16-casecoll.c +++ b/tests/unicase/test-u16-casecoll.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint16_t diff --git a/tests/unicase/test-u16-casefold.c b/tests/unicase/test-u16-casefold.c index 3f4f633a9..d378b5696 100644 --- a/tests/unicase/test-u16-casefold.c +++ b/tests/unicase/test-u16-casefold.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_casefold (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t casefolded[] = { 'g', 'r', 0x00FC, 0x0073, 0x0073, ' ', 'g', 'o', 't', 't', '.', ' ', - 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casefolded, SIZEOF (casefolded)) == 0); } @@ -186,15 +186,15 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint16_t input[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint16_t casefolded[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casefolded, SIZEOF (casefolded)) == 0); } diff --git a/tests/unicase/test-u16-is-cased.c b/tests/unicase/test-u16-is-cased.c index a4b9dc395..722765b04 100644 --- a/tests/unicase/test-u16-is-cased.c +++ b/tests/unicase/test-u16-is-cased.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint16_t diff --git a/tests/unicase/test-u16-is-casefolded.c b/tests/unicase/test-u16-is-casefolded.c index 8c0122da8..77920e956 100644 --- a/tests/unicase/test-u16-is-casefolded.c +++ b/tests/unicase/test-u16-is-casefolded.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint16_t diff --git a/tests/unicase/test-u16-is-lowercase.c b/tests/unicase/test-u16-is-lowercase.c index f7bea495d..7d36094b6 100644 --- a/tests/unicase/test-u16-is-lowercase.c +++ b/tests/unicase/test-u16-is-lowercase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint16_t diff --git a/tests/unicase/test-u16-is-titlecase.c b/tests/unicase/test-u16-is-titlecase.c index 6b1c6d109..161295413 100644 --- a/tests/unicase/test-u16-is-titlecase.c +++ b/tests/unicase/test-u16-is-titlecase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint16_t diff --git a/tests/unicase/test-u16-is-uppercase.c b/tests/unicase/test-u16-is-uppercase.c index 1acf7055f..76dcf6c36 100644 --- a/tests/unicase/test-u16-is-uppercase.c +++ b/tests/unicase/test-u16-is-uppercase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint16_t diff --git a/tests/unicase/test-u16-tolower.c b/tests/unicase/test-u16-tolower.c index 5ec764c4a..97dba74ca 100644 --- a/tests/unicase/test-u16-tolower.c +++ b/tests/unicase/test-u16-tolower.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_tolower (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t casemapped[] = { 'g', 'r', 0x00FC, 0x00DF, ' ', 'g', 'o', 't', 't', '.', ' ', - 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -173,15 +173,15 @@ main () { /* "ΠΕΡΙΣΣΌΤΕΡΕΣ ΠΛΗΡΟΦΟΡΊΕΣ" */ static const uint16_t input[] = { - 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, - 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, - 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 + 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, + 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, + 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 }; static const uint16_t casemapped[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u16-totitle.c b/tests/unicase/test-u16-totitle.c index 3839c9079..ae03d3b60 100644 --- a/tests/unicase/test-u16-totitle.c +++ b/tests/unicase/test-u16-totitle.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_totitle (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "GRÜß GOTT. ЗДРАВСТВУЙТЕ! X=(-B±SQRT(B²-4AC))/(2A) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'R', 0x00DC, 0x00DF, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, - 0x0419, 0x0422, 0x0415, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, - '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, + 0x0419, 0x0422, 0x0415, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, + '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t casemapped[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'q', 'r', 't', '(', 'B', 0x00B2, - '-', '4', 'A', 'c', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'q', 'r', 't', '(', 'B', 0x00B2, + '-', '4', 'A', 'c', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -185,15 +185,15 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint16_t input[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint16_t casemapped[] = { - 0x03A0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03A0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03A0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03A0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u16-toupper.c b/tests/unicase/test-u16-toupper.c index ed9fd6b17..083136578 100644 --- a/tests/unicase/test-u16-toupper.c +++ b/tests/unicase/test-u16-toupper.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_toupper (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t casemapped[] = { 'G', 'R', 0x00DC, 0x0053, 0x0053, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, - 0x0419, 0x0422, 0x0415, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, - '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, + 0x0419, 0x0422, 0x0415, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, + '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -185,15 +185,15 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint16_t input[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint16_t casemapped[] = { - 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, - 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, - 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 + 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, + 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, + 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u32-casecmp.c b/tests/unicase/test-u32-casecmp.c index 8d58bc762..4f7204b6f 100644 --- a/tests/unicase/test-u32-casecmp.c +++ b/tests/unicase/test-u32-casecmp.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint32_t @@ -127,27 +127,27 @@ test_nonascii (int (*my_casecmp) (const uint32_t *, size_t, const uint32_t *, si { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input1[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t input2[] = { 'g', 'r', 0x00FC, 0x0073, 0x0073, ' ', 'g', 'o', 't', 't', '.', ' ', - 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t input3[] = { 'G', 'R', 0x00DC, 0x0053, 0x0053, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, - 0x0419, 0x0422, 0x0415, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, - '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, + 0x0419, 0x0422, 0x0415, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, + '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; int cmp; @@ -277,21 +277,21 @@ test_nonascii (int (*my_casecmp) (const uint32_t *, size_t, const uint32_t *, si { /* "περισσότερες πληροφορίες" */ static const uint32_t input1[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint32_t input2[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 }; static const uint32_t input3[] = { - 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, - 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, - 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 + 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, + 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, + 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 }; int cmp; diff --git a/tests/unicase/test-u32-casecoll.c b/tests/unicase/test-u32-casecoll.c index 23edfbdf5..97a4e0565 100644 --- a/tests/unicase/test-u32-casecoll.c +++ b/tests/unicase/test-u32-casecoll.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint32_t diff --git a/tests/unicase/test-u32-casefold.c b/tests/unicase/test-u32-casefold.c index d48e8dc88..a1ff4a204 100644 --- a/tests/unicase/test-u32-casefold.c +++ b/tests/unicase/test-u32-casefold.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_casefold (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t casefolded[] = { 'g', 'r', 0x00FC, 0x0073, 0x0073, ' ', 'g', 'o', 't', 't', '.', ' ', - 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casefolded, SIZEOF (casefolded)) == 0); } @@ -186,15 +186,15 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint32_t input[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint32_t casefolded[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C3, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C3 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casefolded, SIZEOF (casefolded)) == 0); } diff --git a/tests/unicase/test-u32-is-cased.c b/tests/unicase/test-u32-is-cased.c index d8353fc40..020a7a2df 100644 --- a/tests/unicase/test-u32-is-cased.c +++ b/tests/unicase/test-u32-is-cased.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint32_t diff --git a/tests/unicase/test-u32-is-casefolded.c b/tests/unicase/test-u32-is-casefolded.c index d79241d7a..acfaf255f 100644 --- a/tests/unicase/test-u32-is-casefolded.c +++ b/tests/unicase/test-u32-is-casefolded.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint32_t diff --git a/tests/unicase/test-u32-is-lowercase.c b/tests/unicase/test-u32-is-lowercase.c index 2cff39255..ee41ac005 100644 --- a/tests/unicase/test-u32-is-lowercase.c +++ b/tests/unicase/test-u32-is-lowercase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint32_t diff --git a/tests/unicase/test-u32-is-titlecase.c b/tests/unicase/test-u32-is-titlecase.c index 2c287e983..b56418245 100644 --- a/tests/unicase/test-u32-is-titlecase.c +++ b/tests/unicase/test-u32-is-titlecase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint32_t diff --git a/tests/unicase/test-u32-is-uppercase.c b/tests/unicase/test-u32-is-uppercase.c index 0044ec1d8..b67703b74 100644 --- a/tests/unicase/test-u32-is-uppercase.c +++ b/tests/unicase/test-u32-is-uppercase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint32_t diff --git a/tests/unicase/test-u32-tolower.c b/tests/unicase/test-u32-tolower.c index 7f348da48..cbe1a2b13 100644 --- a/tests/unicase/test-u32-tolower.c +++ b/tests/unicase/test-u32-tolower.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_tolower (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t casemapped[] = { 'g', 'r', 0x00FC, 0x00DF, ' ', 'g', 'o', 't', 't', '.', ' ', - 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0437, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -173,15 +173,15 @@ main () { /* "ΠΕΡΙΣΣΌΤΕΡΕΣ ΠΛΗΡΟΦΟΡΊΕΣ" */ static const uint32_t input[] = { - 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, - 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, - 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 + 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, + 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, + 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 }; static const uint32_t casemapped[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u32-totitle.c b/tests/unicase/test-u32-totitle.c index 82c4b0f19..ea7ab9a81 100644 --- a/tests/unicase/test-u32-totitle.c +++ b/tests/unicase/test-u32-totitle.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_totitle (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "GRÜß GOTT. ЗДРАВСТВУЙТЕ! X=(-B±SQRT(B²-4AC))/(2A) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'R', 0x00DC, 0x00DF, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, - 0x0419, 0x0422, 0x0415, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, - '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, + 0x0419, 0x0422, 0x0415, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, + '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t casemapped[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'q', 'r', 't', '(', 'B', 0x00B2, - '-', '4', 'A', 'c', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'q', 'r', 't', '(', 'B', 0x00B2, + '-', '4', 'A', 'c', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -185,15 +185,15 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint32_t input[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint32_t casemapped[] = { - 0x03A0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03A0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03A0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03A0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u32-toupper.c b/tests/unicase/test-u32-toupper.c index dbc1619bc..c431b3d52 100644 --- a/tests/unicase/test-u32-toupper.c +++ b/tests/unicase/test-u32-toupper.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_toupper (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,19 +110,19 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t casemapped[] = { 'G', 'R', 0x00DC, 0x0053, 0x0053, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, - 0x0419, 0x0422, 0x0415, '!', ' ', - 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, - '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0414, 0x0420, 0x0410, 0x0412, 0x0421, 0x0422, 0x0412, 0x0423, + 0x0419, 0x0422, 0x0415, '!', ' ', + 'X', '=', '(', '-', 'B', 0x00B1, 'S', 'Q', 'R', 'T', '(', 'B', 0x00B2, + '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -185,15 +185,15 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint32_t input[] = { - 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, - 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, - 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 + 0x03C0, 0x03B5, 0x03C1, 0x03B9, 0x03C3, 0x03C3, 0x03CC, 0x03C4, + 0x03B5, 0x03C1, 0x03B5, 0x03C2, 0x0020, 0x03C0, 0x03BB, 0x03B7, + 0x03C1, 0x03BF, 0x03C6, 0x03BF, 0x03C1, 0x03AF, 0x03B5, 0x03C2 }; static const uint32_t casemapped[] = { - 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, - 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, - 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 + 0x03A0, 0x0395, 0x03A1, 0x0399, 0x03A3, 0x03A3, 0x038C, 0x03A4, + 0x0395, 0x03A1, 0x0395, 0x03A3, 0x0020, 0x03A0, 0x039B, 0x0397, + 0x03A1, 0x039F, 0x03A6, 0x039F, 0x03A1, 0x038A, 0x0395, 0x03A3 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u8-casecmp.c b/tests/unicase/test-u8-casecmp.c index dbcc9d766..c1f374615 100644 --- a/tests/unicase/test-u8-casecmp.c +++ b/tests/unicase/test-u8-casecmp.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint8_t @@ -127,33 +127,33 @@ test_nonascii (int (*my_casecmp) (const uint8_t *, size_t, const uint8_t *, size { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input1[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', ' ', - 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t input2[] = { 'g', 'r', 0xC3, 0xBC, 0x73, 0x73, ' ', 'g', 'o', 't', 't', '.', ' ', - 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t input3[] = { 'G', 'R', 0xC3, 0x9C, 0x53, 0x53, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, - 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, - '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', - 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, + 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, + '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', + 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; int cmp; @@ -283,24 +283,24 @@ test_nonascii (int (*my_casecmp) (const uint8_t *, size_t, const uint8_t *, size { /* "περισσότερες πληροφορίες" */ static const uint8_t input1[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; static const uint8_t input2[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 }; static const uint8_t input3[] = { - 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, - 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, - ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, - 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 + 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, + 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, + ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, + 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 }; int cmp; diff --git a/tests/unicase/test-u8-casecoll.c b/tests/unicase/test-u8-casecoll.c index e1b0c57cd..5e4d69eae 100644 --- a/tests/unicase/test-u8-casecoll.c +++ b/tests/unicase/test-u8-casecoll.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint8_t diff --git a/tests/unicase/test-u8-casefold.c b/tests/unicase/test-u8-casefold.c index 225b9979d..5bf87bc84 100644 --- a/tests/unicase/test-u8-casefold.c +++ b/tests/unicase/test-u8-casefold.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_casefold (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,23 +110,23 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', ' ', - 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t casefolded[] = { 'g', 'r', 0xC3, 0xBC, 0x73, 0x73, ' ', 'g', 'o', 't', 't', '.', ' ', - 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casefolded, SIZEOF (casefolded)) == 0); } @@ -190,17 +190,17 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint8_t input[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; static const uint8_t casefolded[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casefolded, SIZEOF (casefolded)) == 0); } diff --git a/tests/unicase/test-u8-is-cased.c b/tests/unicase/test-u8-is-cased.c index 984f81b60..202eeea1c 100644 --- a/tests/unicase/test-u8-is-cased.c +++ b/tests/unicase/test-u8-is-cased.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint8_t diff --git a/tests/unicase/test-u8-is-casefolded.c b/tests/unicase/test-u8-is-casefolded.c index b727f6bbf..a17626ca9 100644 --- a/tests/unicase/test-u8-is-casefolded.c +++ b/tests/unicase/test-u8-is-casefolded.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint8_t diff --git a/tests/unicase/test-u8-is-lowercase.c b/tests/unicase/test-u8-is-lowercase.c index 230e77cf3..7c3491db6 100644 --- a/tests/unicase/test-u8-is-lowercase.c +++ b/tests/unicase/test-u8-is-lowercase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint8_t diff --git a/tests/unicase/test-u8-is-titlecase.c b/tests/unicase/test-u8-is-titlecase.c index fb803ea81..05bb644f0 100644 --- a/tests/unicase/test-u8-is-titlecase.c +++ b/tests/unicase/test-u8-is-titlecase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint8_t diff --git a/tests/unicase/test-u8-is-uppercase.c b/tests/unicase/test-u8-is-uppercase.c index c66bf393c..77d37032f 100644 --- a/tests/unicase/test-u8-is-uppercase.c +++ b/tests/unicase/test-u8-is-uppercase.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT uint8_t diff --git a/tests/unicase/test-u8-tolower.c b/tests/unicase/test-u8-tolower.c index 6c0a5df61..bd07aceb6 100644 --- a/tests/unicase/test-u8-tolower.c +++ b/tests/unicase/test-u8-tolower.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_tolower (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,23 +110,23 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', ' ', - 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t casemapped[] = { 'g', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'g', 'o', 't', 't', '.', ' ', - 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -177,17 +177,17 @@ main () { /* "ΠΕΡΙΣΣΌΤΕΡΕΣ ΠΛΗΡΟΦΟΡΊΕΣ" */ static const uint8_t input[] = { - 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, - 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, - ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, - 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 + 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, + 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, + ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, + 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 }; static const uint8_t casemapped[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u8-totitle.c b/tests/unicase/test-u8-totitle.c index c2506ac55..ddf1bea18 100644 --- a/tests/unicase/test-u8-totitle.c +++ b/tests/unicase/test-u8-totitle.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_totitle (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,23 +110,23 @@ main () { /* "GRÜß GOTT. ЗДРАВСТВУЙТЕ! X=(-B±SQRT(B²-4AC))/(2A) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'R', 0xC3, 0x9C, 0xC3, 0x9F, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, - 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, - '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', - 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, + 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, + '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', + 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t casemapped[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', ' ', - 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'q', 'r', 't', '(', - 'B', 0xC2, 0xB2, '-', '4', 'A', 'c', ')', ')', '/', '(', '2', 'A', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'q', 'r', 't', '(', + 'B', 0xC2, 0xB2, '-', '4', 'A', 'c', ')', ')', '/', '(', '2', 'A', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -189,17 +189,17 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint8_t input[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; static const uint8_t casemapped[] = { - 0xCE, 0xA0, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCE, 0xA0, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCE, 0xA0, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCE, 0xA0, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-u8-toupper.c b/tests/unicase/test-u8-toupper.c index 41e536bd0..605fd737c 100644 --- a/tests/unicase/test-u8-toupper.c +++ b/tests/unicase/test-u8-toupper.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -66,13 +66,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_toupper (input, input_length, iso639_language, nf, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -110,23 +110,23 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', ' ', - 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t casemapped[] = { 'G', 'R', 0xC3, 0x9C, 0x53, 0x53, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, - 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, - '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', - 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, + 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, + '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', + 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } @@ -189,17 +189,17 @@ main () { /* "περισσότερες πληροφορίες" */ static const uint8_t input[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; static const uint8_t casemapped[] = { - 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, - 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, - ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, - 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 + 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, + 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, + ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, + 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 }; ASSERT (check (input, SIZEOF (input), NULL, NULL, casemapped, SIZEOF (casemapped)) == 0); } diff --git a/tests/unicase/test-ulc-casecmp.c b/tests/unicase/test-ulc-casecmp.c index 5450ef31f..f1400ef38 100644 --- a/tests/unicase/test-ulc-casecmp.c +++ b/tests/unicase/test-ulc-casecmp.c @@ -26,15 +26,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT char @@ -173,33 +173,33 @@ test_utf_8 (int (*my_casecmp) (const char *, size_t, const char *, size_t, const { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const char input1[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', ' ', - 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const char input2[] = { 'g', 'r', 0xC3, 0xBC, 0x73, 0x73, ' ', 'g', 'o', 't', 't', '.', ' ', - 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, - 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, - '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', - 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0xB7, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, 0x81, + 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5, + '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, 's', 'q', 'r', 't', '(', + 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; static const char input3[] = { 'G', 'R', 0xC3, 0x9C, 0x53, 0x53, ' ', 'G', 'O', 'T', 'T', '.', ' ', - 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, - 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, - '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', - 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', - ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', - 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' + 0xD0, 0x97, 0xD0, 0x94, 0xD0, 0xA0, 0xD0, 0x90, 0xD0, 0x92, 0xD0, 0xA1, + 0xD0, 0xA2, 0xD0, 0x92, 0xD0, 0xA3, 0xD0, 0x99, 0xD0, 0xA2, 0xD0, 0x95, + '!', ' ', 'X', '=', '(', '-', 'B', 0xC2, 0xB1, 'S', 'Q', 'R', 'T', '(', + 'B', 0xC2, 0xB2, '-', '4', 'A', 'C', ')', ')', '/', '(', '2', 'A', ')', + ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, ',', + 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, 0xEA, 0xB8, 0x80, '\n' }; int cmp; @@ -329,24 +329,24 @@ test_utf_8 (int (*my_casecmp) (const char *, size_t, const char *, size_t, const { /* "περισσότερες πληροφορίες" */ static const char input1[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x82, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x82 }; static const char input2[] = { - 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, - 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, - ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, - 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 + 0xCF, 0x80, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB9, 0xCF, 0x83, 0xCF, 0x83, + 0xCF, 0x8C, 0xCF, 0x84, 0xCE, 0xB5, 0xCF, 0x81, 0xCE, 0xB5, 0xCF, 0x83, + ' ', 0xCF, 0x80, 0xCE, 0xBB, 0xCE, 0xB7, 0xCF, 0x81, 0xCE, 0xBF, + 0xCF, 0x86, 0xCE, 0xBF, 0xCF, 0x81, 0xCE, 0xAF, 0xCE, 0xB5, 0xCF, 0x83 }; static const char input3[] = { - 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, - 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, - ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, - 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 + 0xCE, 0xA0, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x99, 0xCE, 0xA3, 0xCE, 0xA3, + 0xCE, 0x8C, 0xCE, 0xA4, 0xCE, 0x95, 0xCE, 0xA1, 0xCE, 0x95, 0xCE, 0xA3, + ' ', 0xCE, 0xA0, 0xCE, 0x9B, 0xCE, 0x97, 0xCE, 0xA1, 0xCE, 0x9F, + 0xCE, 0xA6, 0xCE, 0x9F, 0xCE, 0xA1, 0xCE, 0x8A, 0xCE, 0x95, 0xCE, 0xA3 }; int cmp; @@ -394,14 +394,14 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case '1': - /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ - test_iso_8859_1 (ulc_casecmp); - return 0; + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + test_iso_8859_1 (ulc_casecmp); + return 0; case '2': - /* Locale encoding is UTF-8. */ - test_utf_8 (ulc_casecmp); - return 0; + /* Locale encoding is UTF-8. */ + test_utf_8 (ulc_casecmp); + return 0; } return 1; diff --git a/tests/unicase/test-ulc-casecoll.c b/tests/unicase/test-ulc-casecoll.c index a0875f44c..d669fde2c 100644 --- a/tests/unicase/test-ulc-casecoll.c +++ b/tests/unicase/test-ulc-casecoll.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define UNIT char diff --git a/tests/uniconv/test-u16-conv-from-enc.c b/tests/uniconv/test-u16-conv-from-enc.c index 1d1594eba..e4ec6a639 100644 --- a/tests/uniconv/test-u16-conv-from-enc.c +++ b/tests/uniconv/test-u16-conv-from-enc.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -69,31 +69,31 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const uint16_t expected[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint16_t *result = u16_conv_from_encoding ("ISO-8859-1", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint16_t *result = u16_conv_from_encoding ("ISO-8859-1", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from ISO-8859-2 to UTF-16 with no errors. */ @@ -102,30 +102,30 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ static const uint16_t expected[] = - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i' - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i' + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint16_t *result = u16_conv_from_encoding ("ISO-8859-2", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint16_t *result = u16_conv_from_encoding ("ISO-8859-2", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } } /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ @@ -136,93 +136,93 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ static const uint16_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ static const uint16_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ static const uint16_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i == 0 ? 0 : - i == 5 ? 1 : - i == 7 ? 2 : - i == 9 ? 3 : - i == 11 ? 4 : - i == 13 ? 5 : - (size_t)(-1))); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint16_t *result = u16_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u16_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i == 0 ? 0 : + i == 5 ? 1 : + i == 7 ? 2 : + i == 9 ? 3 : + i == 11 ? 4 : + i == 13 ? 5 : + (size_t)(-1))); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } } # endif diff --git a/tests/uniconv/test-u16-conv-to-enc.c b/tests/uniconv/test-u16-conv-to-enc.c index a2dc3c686..2bdf1b1e3 100644 --- a/tests/uniconv/test-u16-conv-to-enc.c +++ b/tests/uniconv/test-u16-conv-to-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -67,32 +67,32 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint16_t input[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF + }; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); - size_t length; - char *result = u16_conv_to_encoding ("ISO-8859-1", handler, - input, SIZEOF (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); + size_t length; + char *result = u16_conv_to_encoding ("ISO-8859-1", handler, + input, SIZEOF (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-16 to ISO-8859-1 with EILSEQ. */ @@ -100,61 +100,61 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint16_t input[] = /* Rafał Maszkowski */ - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i' - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i' + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); - size_t length = 0xdead; - char *result = u16_conv_to_encoding ("ISO-8859-1", handler, - input, SIZEOF (input), - offsets, - NULL, &length); - switch (handler) - { - case iconveh_error: - ASSERT (result == NULL); - ASSERT (errno == EILSEQ); - ASSERT (length == 0xdead); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - static const char expected_translit[] = "Rafal Maszkowski"; - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0 - || memcmp (result, expected_translit, length) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i < 5 ? i : i + 5)); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); + size_t length = 0xdead; + char *result = u16_conv_to_encoding ("ISO-8859-1", handler, + input, SIZEOF (input), + offsets, + NULL, &length); + switch (handler) + { + case iconveh_error: + ASSERT (result == NULL); + ASSERT (errno == EILSEQ); + ASSERT (length == 0xdead); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + static const char expected_translit[] = "Rafal Maszkowski"; + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0 + || memcmp (result, expected_translit, length) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i < 5 ? i : i + 5)); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from UTF-16 to ISO-8859-1 with EINVAL. */ @@ -163,23 +163,23 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const uint16_t input[] = { 0xD845 }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); - size_t length; - char *result = u16_conv_to_encoding ("ISO-8859-1", handler, - input, SIZEOF (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == strlen ("")); - if (o) - { - ASSERT (offsets[0] == 0); - ASSERT (offsets[1] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); + size_t length; + char *result = u16_conv_to_encoding ("ISO-8859-1", handler, + input, SIZEOF (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == strlen ("")); + if (o) + { + ASSERT (offsets[0] == 0); + ASSERT (offsets[1] == MAGIC); + free (offsets); + } + free (result); + } } #endif diff --git a/tests/uniconv/test-u16-strconv-from-enc.c b/tests/uniconv/test-u16-strconv-from-enc.c index 492898d01..da2bc87ad 100644 --- a/tests/uniconv/test-u16-strconv-from-enc.c +++ b/tests/uniconv/test-u16-strconv-from-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -55,11 +55,11 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const uint16_t expected[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 + }; uint16_t *result = u16_strconv_from_encoding (input, "ISO-8859-1", handler); ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -72,10 +72,10 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ static const uint16_t expected[] = - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; uint16_t *result = u16_strconv_from_encoding (input, "ISO-8859-2", handler); ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -90,9 +90,9 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ static const uint16_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 + }; uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler); ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -103,9 +103,9 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ static const uint16_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 + }; uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler); ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -116,9 +116,9 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ static const uint16_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 + }; uint16_t *result = u16_strconv_from_encoding (input, "autodetect_jp", handler); ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); diff --git a/tests/uniconv/test-u16-strconv-to-enc.c b/tests/uniconv/test-u16-strconv-to-enc.c index 95a72065b..512b16ced 100644 --- a/tests/uniconv/test-u16-strconv-to-enc.c +++ b/tests/uniconv/test-u16-strconv-to-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -54,11 +54,11 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint16_t input[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 + }; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; char *result = u16_strconv_to_encoding (input, "ISO-8859-1", handler); ASSERT (result != NULL); @@ -71,35 +71,35 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint16_t input[] = /* Rafał Maszkowski */ - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; char *result = u16_strconv_to_encoding (input, "ISO-8859-1", handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - static const char expected_translit[] = "Rafal Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - || strcmp (result, expected_translit) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + static const char expected_translit[] = "Rafal Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + || strcmp (result, expected_translit) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } # if 0 diff --git a/tests/uniconv/test-u32-conv-from-enc.c b/tests/uniconv/test-u32-conv-from-enc.c index 346408413..1b6215936 100644 --- a/tests/uniconv/test-u32-conv-from-enc.c +++ b/tests/uniconv/test-u32-conv-from-enc.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -69,31 +69,31 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const uint32_t expected[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint32_t *result = u32_conv_from_encoding ("ISO-8859-1", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint32_t *result = u32_conv_from_encoding ("ISO-8859-1", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from ISO-8859-2 to UTF-16 with no errors. */ @@ -102,30 +102,30 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ static const uint32_t expected[] = - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i' - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i' + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint32_t *result = u32_conv_from_encoding ("ISO-8859-2", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint32_t *result = u32_conv_from_encoding ("ISO-8859-2", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } } /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ @@ -136,93 +136,93 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ static const uint32_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ static const uint32_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? i / 2 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ static const uint32_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == SIZEOF (expected)); - ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i == 0 ? 0 : - i == 5 ? 1 : - i == 7 ? 2 : - i == 9 ? 3 : - i == 11 ? 4 : - i == 13 ? 5 : - (size_t)(-1))); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint32_t *result = u32_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == SIZEOF (expected)); + ASSERT (u32_cmp (result, expected, SIZEOF (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i == 0 ? 0 : + i == 5 ? 1 : + i == 7 ? 2 : + i == 9 ? 3 : + i == 11 ? 4 : + i == 13 ? 5 : + (size_t)(-1))); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } } # endif diff --git a/tests/uniconv/test-u32-conv-to-enc.c b/tests/uniconv/test-u32-conv-to-enc.c index 585b737c7..603d92015 100644 --- a/tests/uniconv/test-u32-conv-to-enc.c +++ b/tests/uniconv/test-u32-conv-to-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -67,32 +67,32 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint32_t input[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF + }; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); - size_t length; - char *result = u32_conv_to_encoding ("ISO-8859-1", handler, - input, SIZEOF (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); + size_t length; + char *result = u32_conv_to_encoding ("ISO-8859-1", handler, + input, SIZEOF (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-32 to ISO-8859-1 with EILSEQ. */ @@ -100,61 +100,61 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint32_t input[] = /* Rafał Maszkowski */ - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i' - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i' + }; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); - size_t length = 0xdead; - char *result = u32_conv_to_encoding ("ISO-8859-1", handler, - input, SIZEOF (input), - offsets, - NULL, &length); - switch (handler) - { - case iconveh_error: - ASSERT (result == NULL); - ASSERT (errno == EILSEQ); - ASSERT (length == 0xdead); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - static const char expected_translit[] = "Rafal Maszkowski"; - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0 - || memcmp (result, expected_translit, length) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == i); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i < 5 ? i : i + 5)); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (SIZEOF (input)) : NULL); + size_t length = 0xdead; + char *result = u32_conv_to_encoding ("ISO-8859-1", handler, + input, SIZEOF (input), + offsets, + NULL, &length); + switch (handler) + { + case iconveh_error: + ASSERT (result == NULL); + ASSERT (errno == EILSEQ); + ASSERT (length == 0xdead); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + static const char expected_translit[] = "Rafal Maszkowski"; + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0 + || memcmp (result, expected_translit, length) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == i); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i < 5 ? i : i + 5)); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } #endif diff --git a/tests/uniconv/test-u32-strconv-from-enc.c b/tests/uniconv/test-u32-strconv-from-enc.c index 2c0e04bf2..3203c4f14 100644 --- a/tests/uniconv/test-u32-strconv-from-enc.c +++ b/tests/uniconv/test-u32-strconv-from-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -55,11 +55,11 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const uint32_t expected[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 + }; uint32_t *result = u32_strconv_from_encoding (input, "ISO-8859-1", handler); ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -72,10 +72,10 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ static const uint32_t expected[] = - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; uint32_t *result = u32_strconv_from_encoding (input, "ISO-8859-2", handler); ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -90,9 +90,9 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ static const uint32_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 + }; uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler); ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -103,9 +103,9 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ static const uint32_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 + }; uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler); ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -116,9 +116,9 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ static const uint32_t expected[] = /* こんにちは */ - { - 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 - }; + { + 0x3053, 0x3093, 0x306B, 0x3061, 0x306F, 0 + }; uint32_t *result = u32_strconv_from_encoding (input, "autodetect_jp", handler); ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); diff --git a/tests/uniconv/test-u32-strconv-to-enc.c b/tests/uniconv/test-u32-strconv-to-enc.c index eef3d04d9..ce4537af3 100644 --- a/tests/uniconv/test-u32-strconv-to-enc.c +++ b/tests/uniconv/test-u32-strconv-to-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -54,11 +54,11 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint32_t input[] = /* Ärger mit bösen Bübchen ohne Augenmaß */ - { - 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', - 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', - 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 - }; + { + 0xC4, 'r', 'g', 'e', 'r', ' ', 'm', 'i', 't', ' ', 'b', 0xF6, 's', + 'e', 'n', ' ', 'B', 0xFC, 'b', 'c', 'h', 'e', 'n', ' ', 'o', 'h', + 'n', 'e', ' ', 'A', 'u', 'g', 'e', 'n', 'm', 'a', 0xDF, 0 + }; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; char *result = u32_strconv_to_encoding (input, "ISO-8859-1", handler); ASSERT (result != NULL); @@ -71,35 +71,35 @@ main () { enum iconv_ilseq_handler handler = handlers[h]; static const uint32_t input[] = /* Rafał Maszkowski */ - { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 - }; + { + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 + }; char *result = u32_strconv_to_encoding (input, "ISO-8859-1", handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - static const char expected_translit[] = "Rafal Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - || strcmp (result, expected_translit) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + static const char expected_translit[] = "Rafal Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + || strcmp (result, expected_translit) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } #endif diff --git a/tests/uniconv/test-u8-conv-from-enc.c b/tests/uniconv/test-u8-conv-from-enc.c index ec8703cc0..29722a185 100644 --- a/tests/uniconv/test-u8-conv-from-enc.c +++ b/tests/uniconv/test-u8-conv-from-enc.c @@ -28,15 +28,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -70,28 +70,28 @@ main () static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; static const uint8_t expected[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint8_t *result = u8_conv_from_encoding ("ISO-8859-1", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == u8_strlen (expected)); - ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 37; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i < 12 ? i + 1 : - i < 18 ? i + 2 : - i + 3)); - ASSERT (offsets[37] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint8_t *result = u8_conv_from_encoding ("ISO-8859-1", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == u8_strlen (expected)); + ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 37; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i < 12 ? i + 1 : + i < 18 ? i + 2 : + i + 3)); + ASSERT (offsets[37] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from ISO-8859-2 to UTF-8 with no errors. */ @@ -101,26 +101,26 @@ main () static const char input[] = "Rafa\263 Maszkowski"; /* Rafał Maszkowski */ static const uint8_t expected[] = "Rafa\305\202 Maszkowski"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint8_t *result = u8_conv_from_encoding ("ISO-8859-2", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == u8_strlen (expected)); - ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i + 1)); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint8_t *result = u8_conv_from_encoding ("ISO-8859-2", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == u8_strlen (expected)); + ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i + 1)); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } } /* autodetect_jp is only supported when iconv() support ISO-2022-JP-2. */ @@ -132,25 +132,25 @@ main () static const char input[] = "\244\263\244\363\244\313\244\301\244\317"; /* こんにちは in EUC-JP */ static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == u8_strlen (expected)); - ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == u8_strlen (expected)); + ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { @@ -158,25 +158,25 @@ main () static const char input[] = "\202\261\202\361\202\311\202\277\202\315"; /* こんにちは in Shift_JIS */ static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == u8_strlen (expected)); - ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 10; i++) - ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); - ASSERT (offsets[10] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == u8_strlen (expected)); + ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 10; i++) + ASSERT (offsets[i] == ((i % 2) == 0 ? (i / 2) * 3 : (size_t)(-1))); + ASSERT (offsets[10] == MAGIC); + free (offsets); + } + free (result); + } } for (h = 0; h < SIZEOF (handlers); h++) { @@ -184,31 +184,31 @@ main () static const char input[] = "\033$B$3$s$K$A$O\033(B"; /* こんにちは in ISO-2022-JP-2 */ static const uint8_t expected[] = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257"; /* こんにちは */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); - size_t length; - uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, - input, strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == u8_strlen (expected)); - ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); - if (o) - { - for (i = 0; i < 16; i++) - ASSERT (offsets[i] == (i == 0 ? 0 : - i == 5 ? 3 : - i == 7 ? 6 : - i == 9 ? 9 : - i == 11 ? 12 : - i == 13 ? 15 : - (size_t)(-1))); - ASSERT (offsets[16] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (strlen (input)) : NULL); + size_t length; + uint8_t *result = u8_conv_from_encoding ("autodetect_jp", handler, + input, strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == u8_strlen (expected)); + ASSERT (u8_cmp (result, expected, u8_strlen (expected)) == 0); + if (o) + { + for (i = 0; i < 16; i++) + ASSERT (offsets[i] == (i == 0 ? 0 : + i == 5 ? 3 : + i == 7 ? 6 : + i == 9 ? 9 : + i == 11 ? 12 : + i == 13 ? 15 : + (size_t)(-1))); + ASSERT (offsets[16] == MAGIC); + free (offsets); + } + free (result); + } } # endif diff --git a/tests/uniconv/test-u8-conv-to-enc.c b/tests/uniconv/test-u8-conv-to-enc.c index 271fb0518..080896fbf 100644 --- a/tests/uniconv/test-u8-conv-to-enc.c +++ b/tests/uniconv/test-u8-conv-to-enc.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* Magic number for detecting bounds violations. */ @@ -71,33 +71,33 @@ main () static const uint8_t input[] = "\303\204rger mit b\303\266sen B\303\274bchen ohne Augenma\303\237"; static const char expected[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL); - size_t length; - char *result = u8_conv_to_encoding ("ISO-8859-1", handler, - input, u8_strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0); - if (o) - { - for (i = 0; i < 41; i++) - ASSERT (offsets[i] == (i < 1 ? i : - i == 1 ? (size_t)(-1) : - i < 13 ? i - 1 : - i == 13 ? (size_t)(-1) : - i < 20 ? i - 2 : - i == 20 ? (size_t)(-1) : - i < 40 ? i - 3 : - i == 40 ? (size_t)(-1) : - i - 4)); - ASSERT (offsets[41] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL); + size_t length; + char *result = u8_conv_to_encoding ("ISO-8859-1", handler, + input, u8_strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0); + if (o) + { + for (i = 0; i < 41; i++) + ASSERT (offsets[i] == (i < 1 ? i : + i == 1 ? (size_t)(-1) : + i < 13 ? i - 1 : + i == 13 ? (size_t)(-1) : + i < 20 ? i - 2 : + i == 20 ? (size_t)(-1) : + i < 40 ? i - 3 : + i == 40 ? (size_t)(-1) : + i - 4)); + ASSERT (offsets[41] == MAGIC); + free (offsets); + } + free (result); + } } /* Test conversion from UTF-8 to ISO-8859-1 with EILSEQ. */ @@ -106,60 +106,60 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const uint8_t input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL); - size_t length = 0xdead; - char *result = u8_conv_to_encoding ("ISO-8859-1", handler, - input, u8_strlen (input), - offsets, - NULL, &length); - switch (handler) - { - case iconveh_error: - ASSERT (result == NULL); - ASSERT (errno == EILSEQ); - ASSERT (length == 0xdead); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - static const char expected_translit[] = "Rafal Maszkowski"; - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0 - || memcmp (result, expected_translit, length) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i - 1)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (length == strlen (expected)); - ASSERT (memcmp (result, expected, length) == 0); - if (o) - { - for (i = 0; i < 17; i++) - ASSERT (offsets[i] == (i < 5 ? i : - i == 5 ? (size_t)(-1) : - i + 4)); - ASSERT (offsets[17] == MAGIC); - free (offsets); - } - free (result); - } - break; - } - } + { + size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL); + size_t length = 0xdead; + char *result = u8_conv_to_encoding ("ISO-8859-1", handler, + input, u8_strlen (input), + offsets, + NULL, &length); + switch (handler) + { + case iconveh_error: + ASSERT (result == NULL); + ASSERT (errno == EILSEQ); + ASSERT (length == 0xdead); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + static const char expected_translit[] = "Rafal Maszkowski"; + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0 + || memcmp (result, expected_translit, length) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i - 1)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (length == strlen (expected)); + ASSERT (memcmp (result, expected, length) == 0); + if (o) + { + for (i = 0; i < 17; i++) + ASSERT (offsets[i] == (i < 5 ? i : + i == 5 ? (size_t)(-1) : + i + 4)); + ASSERT (offsets[17] == MAGIC); + free (offsets); + } + free (result); + } + break; + } + } } /* Test conversion from UTF-8 to ISO-8859-1 with EINVAL. */ @@ -168,23 +168,23 @@ main () enum iconv_ilseq_handler handler = handlers[h]; static const uint8_t input[] = "\342"; for (o = 0; o < 2; o++) - { - size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL); - size_t length; - char *result = u8_conv_to_encoding ("ISO-8859-1", handler, - input, u8_strlen (input), - offsets, - NULL, &length); - ASSERT (result != NULL); - ASSERT (length == strlen ("")); - if (o) - { - ASSERT (offsets[0] == 0); - ASSERT (offsets[1] == MAGIC); - free (offsets); - } - free (result); - } + { + size_t *offsets = (o ? new_offsets (u8_strlen (input)) : NULL); + size_t length; + char *result = u8_conv_to_encoding ("ISO-8859-1", handler, + input, u8_strlen (input), + offsets, + NULL, &length); + ASSERT (result != NULL); + ASSERT (length == strlen ("")); + if (o) + { + ASSERT (offsets[0] == 0); + ASSERT (offsets[1] == MAGIC); + free (offsets); + } + free (result); + } } #endif diff --git a/tests/uniconv/test-u8-strconv-from-enc.c b/tests/uniconv/test-u8-strconv-from-enc.c index 8c32ee684..89c48d33f 100644 --- a/tests/uniconv/test-u8-strconv-from-enc.c +++ b/tests/uniconv/test-u8-strconv-from-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uniconv/test-u8-strconv-to-enc.c b/tests/uniconv/test-u8-strconv-to-enc.c index 73085b55d..f19aa4f0f 100644 --- a/tests/uniconv/test-u8-strconv-to-enc.c +++ b/tests/uniconv/test-u8-strconv-to-enc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -68,29 +68,29 @@ main () static const uint8_t input[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ char *result = u8_strconv_to_encoding (input, "ISO-8859-1", handler); switch (handler) - { - case iconveh_error: - ASSERT (result == NULL && errno == EILSEQ); - break; - case iconveh_question_mark: - { - static const char expected[] = "Rafa? Maszkowski"; - static const char expected_translit[] = "Rafal Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0 - || strcmp (result, expected_translit) == 0); - free (result); - } - break; - case iconveh_escape_sequence: - { - static const char expected[] = "Rafa\\u0142 Maszkowski"; - ASSERT (result != NULL); - ASSERT (strcmp (result, expected) == 0); - free (result); - } - break; - } + { + case iconveh_error: + ASSERT (result == NULL && errno == EILSEQ); + break; + case iconveh_question_mark: + { + static const char expected[] = "Rafa? Maszkowski"; + static const char expected_translit[] = "Rafal Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0 + || strcmp (result, expected_translit) == 0); + free (result); + } + break; + case iconveh_escape_sequence: + { + static const char expected[] = "Rafa\\u0142 Maszkowski"; + ASSERT (result != NULL); + ASSERT (strcmp (result, expected) == 0); + free (result); + } + break; + } } # if 0 diff --git a/tests/unictype/test-bidi_byname.c b/tests/unictype/test-bidi_byname.c index 5b1cfec94..c3a72d6b0 100644 --- a/tests/unictype/test-bidi_byname.c +++ b/tests/unictype/test-bidi_byname.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-bidi_name.c b/tests/unictype/test-bidi_name.c index a444ec0cb..300e98405 100644 --- a/tests/unictype/test-bidi_name.c +++ b/tests/unictype/test-bidi_name.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-bidi_of.c b/tests/unictype/test-bidi_of.c index 720e9f975..e06af1938 100644 --- a/tests/unictype/test-bidi_of.c +++ b/tests/unictype/test-bidi_of.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-bidi_test.c b/tests/unictype/test-bidi_test.c index 3404e72f5..468a4021f 100644 --- a/tests/unictype/test-bidi_test.c +++ b/tests/unictype/test-bidi_test.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-block_list.c b/tests/unictype/test-block_list.c index 140b573fc..3b37ae6e9 100644 --- a/tests/unictype/test-block_list.c +++ b/tests/unictype/test-block_list.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -49,10 +49,10 @@ main () for (i = 0; i < nblocks; i++) { - if (strcmp (blocks[i].name, "Latin") == 0) - latin_block = &blocks[i]; - if (strcmp (blocks[i].name, "Hebrew") == 0) - hebrew_block = &blocks[i]; + if (strcmp (blocks[i].name, "Latin") == 0) + latin_block = &blocks[i]; + if (strcmp (blocks[i].name, "Hebrew") == 0) + hebrew_block = &blocks[i]; } ASSERT (latin_block == NULL); ASSERT (hebrew_block != NULL); diff --git a/tests/unictype/test-block_of.c b/tests/unictype/test-block_of.c index 9460cdeb1..93206bdf7 100644 --- a/tests/unictype/test-block_of.c +++ b/tests/unictype/test-block_of.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -45,8 +45,8 @@ main () for (c = 0; c < 0x110000; c++) { - const uc_block_t *block = uc_block (c); - ASSERT (block == NULL || uc_is_block (c, block)); + const uc_block_t *block = uc_block (c); + ASSERT (block == NULL || uc_is_block (c, block)); } } @@ -59,19 +59,19 @@ main () for (i = 0; i < nblocks; i++) { - if (strcmp (blocks[i].name, "Hebrew") == 0) - { - ASSERT (uc_block (0x05DE) == &blocks[i]); - ASSERT (uc_is_block (0x05DE, &blocks[i])); - } + if (strcmp (blocks[i].name, "Hebrew") == 0) + { + ASSERT (uc_block (0x05DE) == &blocks[i]); + ASSERT (uc_is_block (0x05DE, &blocks[i])); + } } for (i = 0; i < nblocks; i++) { - unsigned int c; + unsigned int c; - for (c = blocks[i].start; c <= blocks[i].end; c++) - ASSERT (uc_block (c) == &blocks[i]); + for (c = blocks[i].start; c <= blocks[i].end; c++) + ASSERT (uc_block (c) == &blocks[i]); } } diff --git a/tests/unictype/test-block_test.c b/tests/unictype/test-block_test.c index b086cde62..d901ef1ce 100644 --- a/tests/unictype/test-block_test.c +++ b/tests/unictype/test-block_test.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_and.c b/tests/unictype/test-categ_and.c index 5531ff40b..301daafd6 100644 --- a/tests/unictype/test-categ_and.c +++ b/tests/unictype/test-categ_and.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_and_not.c b/tests/unictype/test-categ_and_not.c index 90b40f8ba..4c4990f18 100644 --- a/tests/unictype/test-categ_and_not.c +++ b/tests/unictype/test-categ_and_not.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_byname.c b/tests/unictype/test-categ_byname.c index 3bb44e9cb..9eceeea0b 100644 --- a/tests/unictype/test-categ_byname.c +++ b/tests/unictype/test-categ_byname.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_name.c b/tests/unictype/test-categ_name.c index b5c3f752b..df088c47b 100644 --- a/tests/unictype/test-categ_name.c +++ b/tests/unictype/test-categ_name.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_none.c b/tests/unictype/test-categ_none.c index f8002416b..606b10ecc 100644 --- a/tests/unictype/test-categ_none.c +++ b/tests/unictype/test-categ_none.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_of.c b/tests/unictype/test-categ_of.c index 28ee66301..dc17c5266 100644 --- a/tests/unictype/test-categ_of.c +++ b/tests/unictype/test-categ_of.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_or.c b/tests/unictype/test-categ_or.c index 6b07de5fa..5865eb04c 100644 --- a/tests/unictype/test-categ_or.c +++ b/tests/unictype/test-categ_or.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-categ_test_withtable.c b/tests/unictype/test-categ_test_withtable.c index b73513287..a1ee7d5e2 100644 --- a/tests/unictype/test-categ_test_withtable.c +++ b/tests/unictype/test-categ_test_withtable.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-combining.c b/tests/unictype/test-combining.c index 3e66a9b7c..fec2a13ad 100644 --- a/tests/unictype/test-combining.c +++ b/tests/unictype/test-combining.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-decdigit.c b/tests/unictype/test-decdigit.c index 3d916908a..04064ef9d 100644 --- a/tests/unictype/test-decdigit.c +++ b/tests/unictype/test-decdigit.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) @@ -50,7 +50,7 @@ main () for (i = 0; i < SIZEOF (mapping); i++) { for (; c < mapping[i].ch; c++) - ASSERT (uc_decimal_value (c) == -1); + ASSERT (uc_decimal_value (c) == -1); /* Here c = mapping[i].ch. */ ASSERT (uc_decimal_value (c) == mapping[i].value); c++; diff --git a/tests/unictype/test-digit.c b/tests/unictype/test-digit.c index efecaaba3..fbcf50209 100644 --- a/tests/unictype/test-digit.c +++ b/tests/unictype/test-digit.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) @@ -50,7 +50,7 @@ main () for (i = 0; i < SIZEOF (mapping); i++) { for (; c < mapping[i].ch; c++) - ASSERT (uc_digit_value (c) == -1); + ASSERT (uc_digit_value (c) == -1); /* Here c = mapping[i].ch. */ ASSERT (uc_digit_value (c) == mapping[i].value); c++; diff --git a/tests/unictype/test-mirror.c b/tests/unictype/test-mirror.c index fb4402ff1..443ee3e5e 100644 --- a/tests/unictype/test-mirror.c +++ b/tests/unictype/test-mirror.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-numeric.c b/tests/unictype/test-numeric.c index 5bca3638d..dfd90be0a 100644 --- a/tests/unictype/test-numeric.c +++ b/tests/unictype/test-numeric.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) @@ -52,14 +52,14 @@ main () for (i = 0; i < SIZEOF (mapping); i++) { for (; c < mapping[i].ch; c++) - { - value = uc_numeric_value (c); - ASSERT (value.numerator == 0 && value.denominator == 0); - } + { + value = uc_numeric_value (c); + ASSERT (value.numerator == 0 && value.denominator == 0); + } /* Here c = mapping[i].ch. */ value = uc_numeric_value (c); ASSERT (value.numerator == mapping[i].numerator - && value.denominator == mapping[i].denominator); + && value.denominator == mapping[i].denominator); c++; } for (; c < 0x110000; c++) diff --git a/tests/unictype/test-pr_byname.c b/tests/unictype/test-pr_byname.c index 770d4c8fd..056f3e889 100644 --- a/tests/unictype/test-pr_byname.c +++ b/tests/unictype/test-pr_byname.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-pr_test.c b/tests/unictype/test-pr_test.c index 388ae0042..424dc1c60 100644 --- a/tests/unictype/test-pr_test.c +++ b/tests/unictype/test-pr_test.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-predicate-part1.h b/tests/unictype/test-predicate-part1.h index e81de4712..6278d5045 100644 --- a/tests/unictype/test-predicate-part1.h +++ b/tests/unictype/test-predicate-part1.h @@ -23,16 +23,16 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed for c = 0x%04X\n", \ - __FILE__, __LINE__, c); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed for c = 0x%04X\n", \ + __FILE__, __LINE__, c); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) diff --git a/tests/unictype/test-predicate-part2.h b/tests/unictype/test-predicate-part2.h index 60b7c2467..eeeb934b4 100644 --- a/tests/unictype/test-predicate-part2.h +++ b/tests/unictype/test-predicate-part2.h @@ -26,9 +26,9 @@ main () for (i = 0; i < SIZEOF (set); i++) { for (; c < set[i].start; c++) - ASSERT (!PREDICATE (c)); + ASSERT (!PREDICATE (c)); for (; c <= set[i].end; c++) - ASSERT (PREDICATE (c)); + ASSERT (PREDICATE (c)); } for (; c < 0x110000; c++) ASSERT (!PREDICATE (c)); diff --git a/tests/unictype/test-scripts.c b/tests/unictype/test-scripts.c index 4b4b0f926..5c16cc5a0 100644 --- a/tests/unictype/test-scripts.c +++ b/tests/unictype/test-scripts.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -57,9 +57,9 @@ main () for (c = 0; c < 0x110000; c++) { - const uc_script_t *script = uc_script (c); - if (script != NULL) - ASSERT (uc_is_script (c, script)); + const uc_script_t *script = uc_script (c); + if (script != NULL) + ASSERT (uc_is_script (c, script)); } } @@ -75,9 +75,9 @@ main () found = false; for (i = 0; i < nscripts; i++) { - ASSERT (scripts[i].name != NULL); - if (strcmp (scripts[i].name, "Hebrew") == 0) - found = true; + ASSERT (scripts[i].name != NULL); + if (strcmp (scripts[i].name, "Hebrew") == 0) + found = true; } ASSERT (found); } diff --git a/tests/unictype/test-sy_c_ident.c b/tests/unictype/test-sy_c_ident.c index 00688e133..2182b26ed 100644 --- a/tests/unictype/test-sy_c_ident.c +++ b/tests/unictype/test-sy_c_ident.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unictype/test-sy_java_ident.c b/tests/unictype/test-sy_java_ident.c index 0a4eb0af1..214e3120d 100644 --- a/tests/unictype/test-sy_java_ident.c +++ b/tests/unictype/test-sy_java_ident.c @@ -23,15 +23,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/unilbrk/test-u16-possible-linebreaks.c b/tests/unilbrk/test-u16-possible-linebreaks.c index 4e0ef34b1..a374d5512 100644 --- a/tests/unilbrk/test-u16-possible-linebreaks.c +++ b/tests/unilbrk/test-u16-possible-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -46,11 +46,11 @@ main () static const uint16_t input[61] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; { @@ -59,16 +59,16 @@ main () u16_possible_linebreaks (input, SIZEOF (input), "GB18030", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 5 - || i == 11 || i == 25 - || i == 27 || i == 29 || i == 30 || i == 35 - || i == 45 || i == 51 - || i == 52 || i == 53 || i == 55 || i == 56 - || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 5 + || i == 11 || i == 25 + || i == 27 || i == 29 || i == 30 || i == 35 + || i == 45 || i == 51 + || i == 52 || i == 53 || i == 55 || i == 56 + || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } @@ -78,16 +78,16 @@ main () u16_possible_linebreaks (input, SIZEOF (input), "GB2312", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 5 - || i == 11 || i == 25 - || i == 27 || i == 29 || i == 30 || i == 35 - || i == 37 || i == 45 || i == 51 - || i == 52 || i == 53 || i == 55 || i == 56 - || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 5 + || i == 11 || i == 25 + || i == 27 || i == 29 || i == 30 || i == 35 + || i == 37 || i == 45 || i == 51 + || i == 52 || i == 53 || i == 55 || i == 56 + || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } } diff --git a/tests/unilbrk/test-u16-width-linebreaks.c b/tests/unilbrk/test-u16-width-linebreaks.c index b62d596a1..e55c46a1a 100644 --- a/tests/unilbrk/test-u16-width-linebreaks.c +++ b/tests/unilbrk/test-u16-width-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -46,11 +46,11 @@ main () static const uint16_t input[61] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; { @@ -59,11 +59,11 @@ main () u16_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 25 || i == 45 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 25 || i == 45 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } @@ -73,11 +73,11 @@ main () u16_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 11 || i == 25 || i == 45 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 11 || i == 25 || i == 45 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } } diff --git a/tests/unilbrk/test-u32-possible-linebreaks.c b/tests/unilbrk/test-u32-possible-linebreaks.c index 94e276a3e..b9696bb81 100644 --- a/tests/unilbrk/test-u32-possible-linebreaks.c +++ b/tests/unilbrk/test-u32-possible-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -46,11 +46,11 @@ main () static const uint32_t input[61] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; { @@ -59,16 +59,16 @@ main () u32_possible_linebreaks (input, SIZEOF (input), "GB18030", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 5 - || i == 11 || i == 25 - || i == 27 || i == 29 || i == 30 || i == 35 - || i == 45 || i == 51 - || i == 52 || i == 53 || i == 55 || i == 56 - || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 5 + || i == 11 || i == 25 + || i == 27 || i == 29 || i == 30 || i == 35 + || i == 45 || i == 51 + || i == 52 || i == 53 || i == 55 || i == 56 + || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } @@ -78,16 +78,16 @@ main () u32_possible_linebreaks (input, SIZEOF (input), "GB2312", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 5 - || i == 11 || i == 25 - || i == 27 || i == 29 || i == 30 || i == 35 - || i == 37 || i == 45 || i == 51 - || i == 52 || i == 53 || i == 55 || i == 56 - || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 5 + || i == 11 || i == 25 + || i == 27 || i == 29 || i == 30 || i == 35 + || i == 37 || i == 45 || i == 51 + || i == 52 || i == 53 || i == 55 || i == 56 + || i == 58 || i == 59 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } } diff --git a/tests/unilbrk/test-u32-width-linebreaks.c b/tests/unilbrk/test-u32-width-linebreaks.c index f684dee77..5a103cca3 100644 --- a/tests/unilbrk/test-u32-width-linebreaks.c +++ b/tests/unilbrk/test-u32-width-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -46,11 +46,11 @@ main () static const uint32_t input[61] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; { @@ -59,11 +59,11 @@ main () u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 25 || i == 45 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 25 || i == 45 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } @@ -73,11 +73,11 @@ main () u32_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p); for (i = 0; i < 61; i++) - { - ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : - i == 11 || i == 25 || i == 45 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 60 ? UC_BREAK_MANDATORY : + i == 11 || i == 25 || i == 45 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } } diff --git a/tests/unilbrk/test-u8-possible-linebreaks.c b/tests/unilbrk/test-u8-possible-linebreaks.c index c3a091d65..c8450f782 100644 --- a/tests/unilbrk/test-u8-possible-linebreaks.c +++ b/tests/unilbrk/test-u8-possible-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -53,16 +53,16 @@ main () u8_possible_linebreaks (input, SIZEOF (input), "GB18030", p); for (i = 0; i < 91; i++) - { - ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : - i == 7 - || i == 13 || i == 39 - || i == 41 || i == 43 || i == 44 || i == 50 - || i == 61 || i == 67 - || i == 70 || i == 73 || i == 77 || i == 80 - || i == 84 || i == 87 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : + i == 7 + || i == 13 || i == 39 + || i == 41 || i == 43 || i == 44 || i == 50 + || i == 61 || i == 67 + || i == 70 || i == 73 || i == 77 || i == 80 + || i == 84 || i == 87 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } @@ -72,16 +72,16 @@ main () u8_possible_linebreaks (input, SIZEOF (input), "GB2312", p); for (i = 0; i < 91; i++) - { - ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : - i == 7 - || i == 13 || i == 39 - || i == 41 || i == 43 || i == 44 || i == 50 - || i == 52 || i == 61 || i == 67 - || i == 70 || i == 73 || i == 77 || i == 80 - || i == 84 || i == 87 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : + i == 7 + || i == 13 || i == 39 + || i == 41 || i == 43 || i == 44 || i == 50 + || i == 52 || i == 61 || i == 67 + || i == 70 || i == 73 || i == 77 || i == 80 + || i == 84 || i == 87 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } } diff --git a/tests/unilbrk/test-u8-width-linebreaks.c b/tests/unilbrk/test-u8-width-linebreaks.c index 6c176f152..3502d8c70 100644 --- a/tests/unilbrk/test-u8-width-linebreaks.c +++ b/tests/unilbrk/test-u8-width-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -53,11 +53,11 @@ main () u8_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB18030", p); for (i = 0; i < 91; i++) - { - ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : - i == 39 || i == 61 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : + i == 39 || i == 61 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } @@ -67,11 +67,11 @@ main () u8_width_linebreaks (input, SIZEOF (input), 25, 0, 0, NULL, "GB2312", p); for (i = 0; i < 91; i++) - { - ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : - i == 13 || i == 39 || i == 61 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); - } + { + ASSERT (p[i] == (i == 90 ? UC_BREAK_MANDATORY : + i == 13 || i == 39 || i == 61 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); + } free (p); } } diff --git a/tests/unilbrk/test-ulc-possible-linebreaks.c b/tests/unilbrk/test-ulc-possible-linebreaks.c index fdd73bee4..2179a34d8 100644 --- a/tests/unilbrk/test-ulc-possible-linebreaks.c +++ b/tests/unilbrk/test-ulc-possible-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -53,10 +53,10 @@ main () ulc_possible_linebreaks (input, SIZEOF (input), "ISO-8859-1", p); for (i = 0; i < 36; i++) { - ASSERT (p[i] == (i == 35 ? UC_BREAK_MANDATORY : - i == 5 || i == 11 || i == 13 || i == 15 || i == 16 - || i == 21 || i == 31 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); + ASSERT (p[i] == (i == 35 ? UC_BREAK_MANDATORY : + i == 5 || i == 11 || i == 13 || i == 15 || i == 16 + || i == 21 || i == 31 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); } free (p); } diff --git a/tests/unilbrk/test-ulc-width-linebreaks.c b/tests/unilbrk/test-ulc-width-linebreaks.c index c0b230195..466197881 100644 --- a/tests/unilbrk/test-ulc-width-linebreaks.c +++ b/tests/unilbrk/test-ulc-width-linebreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -53,9 +53,9 @@ main () ulc_width_linebreaks (input, SIZEOF (input), 12, 0, 0, NULL, "ISO-8859-1", p); for (i = 0; i < 36; i++) { - ASSERT (p[i] == (i == 35 ? UC_BREAK_MANDATORY : - i == 11 || i == 21 || i == 31 ? UC_BREAK_POSSIBLE : - UC_BREAK_PROHIBITED)); + ASSERT (p[i] == (i == 35 ? UC_BREAK_MANDATORY : + i == 11 || i == 21 || i == 31 ? UC_BREAK_POSSIBLE : + UC_BREAK_PROHIBITED)); } free (p); } diff --git a/tests/uniname/test-uninames.c b/tests/uniname/test-uninames.c index 1408434bc..75a923d2e 100644 --- a/tests/uniname/test-uninames.c +++ b/tests/uniname/test-uninames.c @@ -44,10 +44,10 @@ getfield (FILE *stream, char *buffer, int delim) { /* Put c into the buffer. */ if (++count >= FIELDLEN - 1) - { - fprintf (stderr, "field too long\n"); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "field too long\n"); + exit (EXIT_FAILURE); + } *buffer++ = c; } @@ -88,21 +88,21 @@ fill_names (const char *unicodedata_filename) n = getfield (stream, field0, ';'); n += getfield (stream, field1, ';'); if (n == 0) - break; + break; if (n != 2) - { - fprintf (stderr, "short line in '%s':%d\n", - unicodedata_filename, lineno); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "short line in '%s':%d\n", + unicodedata_filename, lineno); + exit (EXIT_FAILURE); + } for (; (c = getc (stream)), (c != EOF && c != '\n'); ) - ; + ; i = strtoul (field0, NULL, 16); if (i >= 0x110000) - { - fprintf (stderr, "index too large\n"); - exit (EXIT_FAILURE); - } + { + fprintf (stderr, "index too large\n"); + exit (EXIT_FAILURE); + } unicode_names[i] = xstrdup (field1); } if (ferror (stream) || fclose (stream)) @@ -125,28 +125,28 @@ test_name_lookup () char *result = unicode_character_name (i, buf); if (unicode_names[i] != NULL) - { - if (result == NULL) - { - fprintf (stderr, "\\u%04X name lookup failed!\n", i); - error = 1; - } - else if (strcmp (result, unicode_names[i]) != 0) - { - fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", - i, result); - error = 1; - } - } + { + if (result == NULL) + { + fprintf (stderr, "\\u%04X name lookup failed!\n", i); + error = 1; + } + else if (strcmp (result, unicode_names[i]) != 0) + { + fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", + i, result); + error = 1; + } + } else - { - if (result != NULL) - { - fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", - i, result); - error = 1; - } - } + { + if (result != NULL) + { + fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", + i, result); + error = 1; + } + } } for (i = 0x110000; i < 0x1000000; i++) @@ -154,11 +154,11 @@ test_name_lookup () char *result = unicode_character_name (i, buf); if (result != NULL) - { - fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", - i, result); - error = 1; - } + { + fprintf (stderr, "\\u%04X name lookup returned wrong name: %s\n", + i, result); + error = 1; + } } return error; @@ -175,18 +175,18 @@ test_inverse_lookup () for (i = 0; i < 0x110000; i++) if (unicode_names[i] != NULL) { - unsigned int result = unicode_name_character (unicode_names[i]); - if (result != i) - { - if (result == UNINAME_INVALID) - fprintf (stderr, "inverse name lookup of \"%s\" failed\n", - unicode_names[i]); - else - fprintf (stderr, - "inverse name lookup of \"%s\" returned 0x%04X\n", - unicode_names[i], result); - error = 1; - } + unsigned int result = unicode_name_character (unicode_names[i]); + if (result != i) + { + if (result == UNINAME_INVALID) + fprintf (stderr, "inverse name lookup of \"%s\" failed\n", + unicode_names[i]); + else + fprintf (stderr, + "inverse name lookup of \"%s\" returned 0x%04X\n", + unicode_names[i], result); + error = 1; + } } /* Second, generate random but likely names and verify they are not @@ -201,13 +201,13 @@ test_inverse_lookup () unsigned int result; do i1 = ((rand () % 0x11) << 16) - + ((rand () & 0xff) << 8) - + (rand () & 0xff); + + ((rand () & 0xff) << 8) + + (rand () & 0xff); while (unicode_names[i1] == NULL); do i2 = ((rand () % 0x11) << 16) - + ((rand () & 0xff) << 8) - + (rand () & 0xff); + + ((rand () & 0xff) << 8) + + (rand () & 0xff); while (unicode_names[i2] == NULL); s1 = unicode_names[i1]; @@ -217,25 +217,25 @@ test_inverse_lookup () /* Concatenate a starting piece of s1 with an ending piece of s2. */ for (j1 = 1; j1 <= l1; j1++) - if (j1 == l1 || s1[j1] == ' ') - for (j2 = 0; j2 < l2; j2++) - if (j2 == 0 || s2[j2-1] == ' ') - { - memcpy (buf, s1, j1); - buf[j1] = ' '; - memcpy (buf + j1 + 1, s2 + j2, l2 - j2 + 1); - - result = unicode_name_character (buf); - if (result != UNINAME_INVALID - && !(unicode_names[result] != NULL - && strcmp (unicode_names[result], buf) == 0)) - { - fprintf (stderr, - "inverse name lookup of \"%s\" returned 0x%04X\n", - unicode_names[i], result); - error = 1; - } - } + if (j1 == l1 || s1[j1] == ' ') + for (j2 = 0; j2 < l2; j2++) + if (j2 == 0 || s2[j2-1] == ' ') + { + memcpy (buf, s1, j1); + buf[j1] = ' '; + memcpy (buf + j1 + 1, s2 + j2, l2 - j2 + 1); + + result = unicode_name_character (buf); + if (result != UNINAME_INVALID + && !(unicode_names[result] != NULL + && strcmp (unicode_names[result], buf) == 0)) + { + fprintf (stderr, + "inverse name lookup of \"%s\" returned 0x%04X\n", + unicode_names[i], result); + error = 1; + } + } } /* Third, some extreme case that used to loop. */ diff --git a/tests/uninorm/test-canonical-decomposition.c b/tests/uninorm/test-canonical-decomposition.c index 040011b55..5d3db60bf 100644 --- a/tests/uninorm/test-canonical-decomposition.c +++ b/tests/uninorm/test-canonical-decomposition.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uninorm/test-compat-decomposition.c b/tests/uninorm/test-compat-decomposition.c index 49a2b09f8..766cd40c0 100644 --- a/tests/uninorm/test-compat-decomposition.c +++ b/tests/uninorm/test-compat-decomposition.c @@ -26,15 +26,15 @@ #include "uninorm.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uninorm/test-composition.c b/tests/uninorm/test-composition.c index dbadbbac8..551905024 100644 --- a/tests/uninorm/test-composition.c +++ b/tests/uninorm/test-composition.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uninorm/test-decomposing-form.c b/tests/uninorm/test-decomposing-form.c index 3802c3fe1..c9444b734 100644 --- a/tests/uninorm/test-decomposing-form.c +++ b/tests/uninorm/test-decomposing-form.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uninorm/test-decomposition.c b/tests/uninorm/test-decomposition.c index 684dee452..c7fa6c23c 100644 --- a/tests/uninorm/test-decomposition.c +++ b/tests/uninorm/test-decomposition.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uninorm/test-u16-nfc.c b/tests/uninorm/test-u16-nfc.c index 1bf9a94d7..73523e0f7 100644 --- a/tests/uninorm/test-u16-nfc.c +++ b/tests/uninorm/test-u16-nfc.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_normalize (UNINORM_NFC, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -241,20 +241,20 @@ test_u16_nfc (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t decomposed[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), input, SIZEOF (input)) == 0); @@ -272,65 +272,65 @@ test_u16_nfc (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); - if (input != NULL) - { - uint16_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint16_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x00C0; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2 - 1; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - { - ASSERT (check (input, m, expected, m - 1) == 0); - ASSERT (check (expected, m - 1, expected, m - 1) == 0); - } - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); + if (input != NULL) + { + uint16_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint16_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x00C0; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2 - 1; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + { + ASSERT (check (input, m, expected, m - 1) == 0); + ASSERT (check (expected, m - 1, expected, m - 1) == 0); + } + + free (input); + } } } } diff --git a/tests/uninorm/test-u16-nfd.c b/tests/uninorm/test-u16-nfd.c index 34789b8df..8d35bac3f 100644 --- a/tests/uninorm/test-u16-nfd.c +++ b/tests/uninorm/test-u16-nfd.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_normalize (UNINORM_NFD, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -229,20 +229,20 @@ test_u16_nfd (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t expected[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -259,62 +259,62 @@ test_u16_nfd (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); - if (input != NULL) - { - uint16_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint16_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x0041; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - ASSERT (check (input, m, expected, m) == 0); - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); + if (input != NULL) + { + uint16_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint16_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x0041; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + ASSERT (check (input, m, expected, m) == 0); + + free (input); + } } } } diff --git a/tests/uninorm/test-u16-nfkc.c b/tests/uninorm/test-u16-nfkc.c index 4ac8f7edf..362bc5b35 100644 --- a/tests/uninorm/test-u16-nfkc.c +++ b/tests/uninorm/test-u16-nfkc.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_normalize (UNINORM_NFKC, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -257,7 +257,7 @@ test_u16_nfkc (void) static const uint16_t input[] = { 0xFDFA }; static const uint16_t decomposed[] = { 0x0635, 0x0644, 0x0649, 0x0020, 0x0627, 0x0644, 0x0644, 0x0647, 0x0020, - 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 + 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 }; ASSERT (check (input, SIZEOF (input), decomposed, SIZEOF (decomposed)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), decomposed, SIZEOF (decomposed)) == 0); @@ -280,28 +280,28 @@ test_u16_nfkc (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t decomposed[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; static const uint16_t expected[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), expected, SIZEOF (expected)) == 0); @@ -320,65 +320,65 @@ test_u16_nfkc (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); - if (input != NULL) - { - uint16_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint16_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x00C0; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2 - 1; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - { - ASSERT (check (input, m, expected, m - 1) == 0); - ASSERT (check (expected, m - 1, expected, m - 1) == 0); - } - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); + if (input != NULL) + { + uint16_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint16_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x00C0; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2 - 1; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + { + ASSERT (check (input, m, expected, m - 1) == 0); + ASSERT (check (expected, m - 1, expected, m - 1) == 0); + } + + free (input); + } } } } diff --git a/tests/uninorm/test-u16-nfkd.c b/tests/uninorm/test-u16-nfkd.c index 6dfa39f31..8e38f08ef 100644 --- a/tests/uninorm/test-u16-nfkd.c +++ b/tests/uninorm/test-u16-nfkd.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint16_t *input, size_t input_length, preallocated = (uint16_t *) malloc (length * sizeof (uint16_t)); result = u16_normalize (UNINORM_NFKD, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u16_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -229,7 +229,7 @@ test_u16_nfkd (void) static const uint16_t input[] = { 0xFDFA }; static const uint16_t expected[] = { 0x0635, 0x0644, 0x0649, 0x0020, 0x0627, 0x0644, 0x0644, 0x0647, 0x0020, - 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 + 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -249,20 +249,20 @@ test_u16_nfkd (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint16_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint16_t expected[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -279,62 +279,62 @@ test_u16_nfkd (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); - if (input != NULL) - { - uint16_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint16_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x0041; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - ASSERT (check (input, m, expected, m) == 0); - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint16_t *input = (uint16_t *) malloc (2 * m * sizeof (uint16_t)); + if (input != NULL) + { + uint16_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint16_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x0041; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + ASSERT (check (input, m, expected, m) == 0); + + free (input); + } } } } diff --git a/tests/uninorm/test-u16-normcmp.c b/tests/uninorm/test-u16-normcmp.c index 3cf947a34..6fa42c39b 100644 --- a/tests/uninorm/test-u16-normcmp.c +++ b/tests/uninorm/test-u16-normcmp.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u16-normcmp.h" diff --git a/tests/uninorm/test-u16-normcmp.h b/tests/uninorm/test-u16-normcmp.h index ea7def8fd..088ef6051 100644 --- a/tests/uninorm/test-u16-normcmp.h +++ b/tests/uninorm/test-u16-normcmp.h @@ -18,7 +18,7 @@ static void test_ascii (int (*my_normcmp) (const uint16_t *, size_t, const uint16_t *, size_t, uninorm_t, int *), - uninorm_t nf) + uninorm_t nf) { /* Empty string. */ { diff --git a/tests/uninorm/test-u16-normcoll.c b/tests/uninorm/test-u16-normcoll.c index d83799dd3..550e31de0 100644 --- a/tests/uninorm/test-u16-normcoll.c +++ b/tests/uninorm/test-u16-normcoll.c @@ -26,15 +26,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u16-normcmp.h" diff --git a/tests/uninorm/test-u32-nfc-big.c b/tests/uninorm/test-u32-nfc-big.c index 2a1b611fa..330987237 100644 --- a/tests/uninorm/test-u32-nfc-big.c +++ b/tests/uninorm/test-u32-nfc-big.c @@ -45,8 +45,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFC, c1, c1_length, NULL, &length); if (!(result != NULL - && length == c2_length - && u32_cmp (result, c2, c2_length) == 0)) + && length == c2_length + && u32_cmp (result, c2, c2_length) == 0)) return 1; free (result); } @@ -56,8 +56,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFC, c2, c2_length, NULL, &length); if (!(result != NULL - && length == c2_length - && u32_cmp (result, c2, c2_length) == 0)) + && length == c2_length + && u32_cmp (result, c2, c2_length) == 0)) return 2; free (result); } @@ -67,8 +67,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFC, c3, c3_length, NULL, &length); if (!(result != NULL - && length == c2_length - && u32_cmp (result, c2, c2_length) == 0)) + && length == c2_length + && u32_cmp (result, c2, c2_length) == 0)) return 3; free (result); } @@ -78,8 +78,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFC, c4, c4_length, NULL, &length); if (!(result != NULL - && length == c4_length - && u32_cmp (result, c4, c4_length) == 0)) + && length == c4_length + && u32_cmp (result, c4, c4_length) == 0)) return 4; free (result); } @@ -89,8 +89,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFC, c5, c5_length, NULL, &length); if (!(result != NULL - && length == c4_length - && u32_cmp (result, c4, c4_length) == 0)) + && length == c4_length + && u32_cmp (result, c4, c4_length) == 0)) return 5; free (result); } diff --git a/tests/uninorm/test-u32-nfc.c b/tests/uninorm/test-u32-nfc.c index 0d8311cc4..eda22023b 100644 --- a/tests/uninorm/test-u32-nfc.c +++ b/tests/uninorm/test-u32-nfc.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_normalize (UNINORM_NFC, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -241,20 +241,20 @@ test_u32_nfc (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t decomposed[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), input, SIZEOF (input)) == 0); @@ -272,65 +272,65 @@ test_u32_nfc (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); - if (input != NULL) - { - uint32_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint32_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x00C0; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2 - 1; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - { - ASSERT (check (input, m, expected, m - 1) == 0); - ASSERT (check (expected, m - 1, expected, m - 1) == 0); - } - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); + if (input != NULL) + { + uint32_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint32_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x00C0; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2 - 1; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + { + ASSERT (check (input, m, expected, m - 1) == 0); + ASSERT (check (expected, m - 1, expected, m - 1) == 0); + } + + free (input); + } } } } diff --git a/tests/uninorm/test-u32-nfd-big.c b/tests/uninorm/test-u32-nfd-big.c index 9bfd0d895..ece1e3a41 100644 --- a/tests/uninorm/test-u32-nfd-big.c +++ b/tests/uninorm/test-u32-nfd-big.c @@ -45,8 +45,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFD, c1, c1_length, NULL, &length); if (!(result != NULL - && length == c3_length - && u32_cmp (result, c3, c3_length) == 0)) + && length == c3_length + && u32_cmp (result, c3, c3_length) == 0)) return 1; free (result); } @@ -56,8 +56,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFD, c2, c2_length, NULL, &length); if (!(result != NULL - && length == c3_length - && u32_cmp (result, c3, c3_length) == 0)) + && length == c3_length + && u32_cmp (result, c3, c3_length) == 0)) return 2; free (result); } @@ -67,8 +67,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFD, c3, c3_length, NULL, &length); if (!(result != NULL - && length == c3_length - && u32_cmp (result, c3, c3_length) == 0)) + && length == c3_length + && u32_cmp (result, c3, c3_length) == 0)) return 3; free (result); } @@ -78,8 +78,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFD, c4, c4_length, NULL, &length); if (!(result != NULL - && length == c5_length - && u32_cmp (result, c5, c5_length) == 0)) + && length == c5_length + && u32_cmp (result, c5, c5_length) == 0)) return 4; free (result); } @@ -89,8 +89,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFD, c5, c5_length, NULL, &length); if (!(result != NULL - && length == c5_length - && u32_cmp (result, c5, c5_length) == 0)) + && length == c5_length + && u32_cmp (result, c5, c5_length) == 0)) return 5; free (result); } diff --git a/tests/uninorm/test-u32-nfd.c b/tests/uninorm/test-u32-nfd.c index f7b2d8dfb..21776ece2 100644 --- a/tests/uninorm/test-u32-nfd.c +++ b/tests/uninorm/test-u32-nfd.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_normalize (UNINORM_NFD, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -229,20 +229,20 @@ test_u32_nfd (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t expected[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -259,62 +259,62 @@ test_u32_nfd (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); - if (input != NULL) - { - uint32_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint32_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x0041; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - ASSERT (check (input, m, expected, m) == 0); - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); + if (input != NULL) + { + uint32_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint32_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x0041; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + ASSERT (check (input, m, expected, m) == 0); + + free (input); + } } } } diff --git a/tests/uninorm/test-u32-nfkc-big.c b/tests/uninorm/test-u32-nfkc-big.c index 340fe65bb..d97ae3b8c 100644 --- a/tests/uninorm/test-u32-nfkc-big.c +++ b/tests/uninorm/test-u32-nfkc-big.c @@ -42,8 +42,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKC, c1, c1_length, NULL, &length); if (!(result != NULL - && length == c4_length - && u32_cmp (result, c4, c4_length) == 0)) + && length == c4_length + && u32_cmp (result, c4, c4_length) == 0)) return 1; free (result); } @@ -53,8 +53,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKC, c2, c2_length, NULL, &length); if (!(result != NULL - && length == c4_length - && u32_cmp (result, c4, c4_length) == 0)) + && length == c4_length + && u32_cmp (result, c4, c4_length) == 0)) return 2; free (result); } @@ -64,8 +64,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKC, c3, c3_length, NULL, &length); if (!(result != NULL - && length == c4_length - && u32_cmp (result, c4, c4_length) == 0)) + && length == c4_length + && u32_cmp (result, c4, c4_length) == 0)) return 3; free (result); } @@ -75,8 +75,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKC, c4, c4_length, NULL, &length); if (!(result != NULL - && length == c4_length - && u32_cmp (result, c4, c4_length) == 0)) + && length == c4_length + && u32_cmp (result, c4, c4_length) == 0)) return 4; free (result); } @@ -86,8 +86,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKC, c5, c5_length, NULL, &length); if (!(result != NULL - && length == c4_length - && u32_cmp (result, c4, c4_length) == 0)) + && length == c4_length + && u32_cmp (result, c4, c4_length) == 0)) return 5; free (result); } diff --git a/tests/uninorm/test-u32-nfkc.c b/tests/uninorm/test-u32-nfkc.c index 75f7e8256..6aa68fa9c 100644 --- a/tests/uninorm/test-u32-nfkc.c +++ b/tests/uninorm/test-u32-nfkc.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_normalize (UNINORM_NFKC, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -257,7 +257,7 @@ test_u32_nfkc (void) static const uint32_t input[] = { 0xFDFA }; static const uint32_t decomposed[] = { 0x0635, 0x0644, 0x0649, 0x0020, 0x0627, 0x0644, 0x0644, 0x0647, 0x0020, - 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 + 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 }; ASSERT (check (input, SIZEOF (input), decomposed, SIZEOF (decomposed)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), decomposed, SIZEOF (decomposed)) == 0); @@ -280,28 +280,28 @@ test_u32_nfkc (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t decomposed[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; static const uint32_t expected[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), expected, SIZEOF (expected)) == 0); @@ -320,65 +320,65 @@ test_u32_nfkc (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); - if (input != NULL) - { - uint32_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint32_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x00C0; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2 - 1; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - { - ASSERT (check (input, m, expected, m - 1) == 0); - ASSERT (check (expected, m - 1, expected, m - 1) == 0); - } - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); + if (input != NULL) + { + uint32_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint32_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x00C0; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2 - 1; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + { + ASSERT (check (input, m, expected, m - 1) == 0); + ASSERT (check (expected, m - 1, expected, m - 1) == 0); + } + + free (input); + } } } } diff --git a/tests/uninorm/test-u32-nfkd-big.c b/tests/uninorm/test-u32-nfkd-big.c index e7c1b4f3f..0da9be8b5 100644 --- a/tests/uninorm/test-u32-nfkd-big.c +++ b/tests/uninorm/test-u32-nfkd-big.c @@ -42,8 +42,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKD, c1, c1_length, NULL, &length); if (!(result != NULL - && length == c5_length - && u32_cmp (result, c5, c5_length) == 0)) + && length == c5_length + && u32_cmp (result, c5, c5_length) == 0)) return 1; free (result); } @@ -53,8 +53,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKD, c2, c2_length, NULL, &length); if (!(result != NULL - && length == c5_length - && u32_cmp (result, c5, c5_length) == 0)) + && length == c5_length + && u32_cmp (result, c5, c5_length) == 0)) return 2; free (result); } @@ -64,8 +64,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKD, c3, c3_length, NULL, &length); if (!(result != NULL - && length == c5_length - && u32_cmp (result, c5, c5_length) == 0)) + && length == c5_length + && u32_cmp (result, c5, c5_length) == 0)) return 3; free (result); } @@ -75,8 +75,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKD, c4, c4_length, NULL, &length); if (!(result != NULL - && length == c5_length - && u32_cmp (result, c5, c5_length) == 0)) + && length == c5_length + && u32_cmp (result, c5, c5_length) == 0)) return 4; free (result); } @@ -86,8 +86,8 @@ check (const uint32_t *c1, size_t c1_length, result = u32_normalize (UNINORM_NFKD, c5, c5_length, NULL, &length); if (!(result != NULL - && length == c5_length - && u32_cmp (result, c5, c5_length) == 0)) + && length == c5_length + && u32_cmp (result, c5, c5_length) == 0)) return 5; free (result); } diff --git a/tests/uninorm/test-u32-nfkd.c b/tests/uninorm/test-u32-nfkd.c index d3de7f763..b932ae24b 100644 --- a/tests/uninorm/test-u32-nfkd.c +++ b/tests/uninorm/test-u32-nfkd.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint32_t *input, size_t input_length, preallocated = (uint32_t *) malloc (length * sizeof (uint32_t)); result = u32_normalize (UNINORM_NFKD, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u32_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -229,7 +229,7 @@ test_u32_nfkd (void) static const uint32_t input[] = { 0xFDFA }; static const uint32_t expected[] = { 0x0635, 0x0644, 0x0649, 0x0020, 0x0627, 0x0644, 0x0644, 0x0647, 0x0020, - 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 + 0x0639, 0x0644, 0x064A, 0x0647, 0x0020, 0x0648, 0x0633, 0x0644, 0x0645 }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -249,20 +249,20 @@ test_u32_nfkd (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t expected[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x0032, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -279,62 +279,62 @@ test_u32_nfkd (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); - if (input != NULL) - { - uint32_t *expected = input + m; - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint32_t *p; - size_t i; - - input[0] = 0x0041; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - break; - - case 1: - for (i = 0; i < m2; i++) - *p++ = 0x0300; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0x0319; - *p++ = 0x0300; - } - for (; i < m1; i++) - *p++ = 0x0319; - break; - - default: - abort (); - } - - expected[0] = 0x0041; - p = expected + 1; - for (i = 0; i < m1; i++) - *p++ = 0x0319; - for (i = 0; i < m2; i++) - *p++ = 0x0300; - - for (; repeat > 0; repeat--) - ASSERT (check (input, m, expected, m) == 0); - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint32_t *input = (uint32_t *) malloc (2 * m * sizeof (uint32_t)); + if (input != NULL) + { + uint32_t *expected = input + m; + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint32_t *p; + size_t i; + + input[0] = 0x0041; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + break; + + case 1: + for (i = 0; i < m2; i++) + *p++ = 0x0300; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0x0319; + *p++ = 0x0300; + } + for (; i < m1; i++) + *p++ = 0x0319; + break; + + default: + abort (); + } + + expected[0] = 0x0041; + p = expected + 1; + for (i = 0; i < m1; i++) + *p++ = 0x0319; + for (i = 0; i < m2; i++) + *p++ = 0x0300; + + for (; repeat > 0; repeat--) + ASSERT (check (input, m, expected, m) == 0); + + free (input); + } } } } diff --git a/tests/uninorm/test-u32-normalize-big.c b/tests/uninorm/test-u32-normalize-big.c index 96781ab08..5cf60a6e4 100644 --- a/tests/uninorm/test-u32-normalize-big.c +++ b/tests/uninorm/test-u32-normalize-big.c @@ -30,28 +30,28 @@ #include "unistr.h" #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #define ASSERT_WITH_LINE(expr, file, line) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed for %s:%u\n", \ - __FILE__, __LINE__, file, line); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed for %s:%u\n", \ + __FILE__, __LINE__, file, line); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -64,7 +64,7 @@ cmp_ucs4_t (const void *a, const void *b) void read_normalization_test_file (const char *filename, - struct normalization_test_file *file) + struct normalization_test_file *file) { FILE *stream; unsigned int lineno; @@ -106,103 +106,103 @@ read_normalization_test_file (const char *filename, /* Read a line. */ ptr = buf; do - { - c = getc (stream); - if (c == EOF || c == '\n') - break; - *ptr++ = c; - } + { + c = getc (stream); + if (c == EOF || c == '\n') + break; + *ptr++ = c; + } while (ptr < buf + 1000); *ptr = '\0'; if (c == EOF) - break; + break; /* Ignore empty lines and comment lines. */ if (buf[0] == '\0' || buf[0] == '#') - continue; + continue; /* Handle lines that introduce a new part. */ if (buf[0] == '@') - { - /* Switch to the next part. */ - if (part_index >= 0) - { - lines = - (struct normalization_test_line *) - xnrealloc (lines, lines_length, sizeof (struct normalization_test_line)); - file->parts[part_index].lines = lines; - file->parts[part_index].lines_length = lines_length; - } - part_index++; - lines = NULL; - lines_length = 0; - lines_allocated = 0; - continue; - } + { + /* Switch to the next part. */ + if (part_index >= 0) + { + lines = + (struct normalization_test_line *) + xnrealloc (lines, lines_length, sizeof (struct normalization_test_line)); + file->parts[part_index].lines = lines; + file->parts[part_index].lines_length = lines_length; + } + part_index++; + lines = NULL; + lines_length = 0; + lines_allocated = 0; + continue; + } /* It's a line containing 5 sequences of Unicode characters. - Parse it and append it to the current part. */ + Parse it and append it to the current part. */ if (!(part_index >= 0 && part_index < 4)) - { - fprintf (stderr, "unexpected structure of '%s'\n", filename); - exit (1); - } + { + fprintf (stderr, "unexpected structure of '%s'\n", filename); + exit (1); + } ptr = buf; line.lineno = lineno; for (sequence_index = 0; sequence_index < 5; sequence_index++) - line.sequences[sequence_index] = NULL; + line.sequences[sequence_index] = NULL; for (sequence_index = 0; sequence_index < 5; sequence_index++) - { - uint32_t *sequence = XNMALLOC (1, uint32_t); - size_t sequence_length = 0; - - for (;;) - { - char *endptr; - unsigned int uc; - - uc = strtoul (ptr, &endptr, 16); - if (endptr == ptr) - break; - ptr = endptr; - - /* Append uc to the sequence. */ - sequence = - (uint32_t *) - xnrealloc (sequence, sequence_length + 2, sizeof (uint32_t)); - sequence[sequence_length] = uc; - sequence_length++; - - if (*ptr == ' ') - ptr++; - } - if (sequence_length == 0) - { - fprintf (stderr, "empty character sequence in '%s'\n", filename); - exit (1); - } - sequence[sequence_length] = 0; /* terminator */ - - line.sequences[sequence_index] = sequence; - - if (*ptr != ';') - { - fprintf (stderr, "error parsing '%s'\n", filename); - exit (1); - } - ptr++; - } + { + uint32_t *sequence = XNMALLOC (1, uint32_t); + size_t sequence_length = 0; + + for (;;) + { + char *endptr; + unsigned int uc; + + uc = strtoul (ptr, &endptr, 16); + if (endptr == ptr) + break; + ptr = endptr; + + /* Append uc to the sequence. */ + sequence = + (uint32_t *) + xnrealloc (sequence, sequence_length + 2, sizeof (uint32_t)); + sequence[sequence_length] = uc; + sequence_length++; + + if (*ptr == ' ') + ptr++; + } + if (sequence_length == 0) + { + fprintf (stderr, "empty character sequence in '%s'\n", filename); + exit (1); + } + sequence[sequence_length] = 0; /* terminator */ + + line.sequences[sequence_index] = sequence; + + if (*ptr != ';') + { + fprintf (stderr, "error parsing '%s'\n", filename); + exit (1); + } + ptr++; + } /* Append the line to the current part. */ if (lines_length == lines_allocated) - { - lines_allocated = 2 * lines_allocated; - if (lines_allocated < 7) - lines_allocated = 7; - lines = - (struct normalization_test_line *) - xnrealloc (lines, lines_allocated, sizeof (struct normalization_test_line)); - } + { + lines_allocated = 2 * lines_allocated; + if (lines_allocated < 7) + lines_allocated = 7; + lines = + (struct normalization_test_line *) + xnrealloc (lines, lines_allocated, sizeof (struct normalization_test_line)); + } lines[lines_length] = line; lines_length++; } @@ -210,8 +210,8 @@ read_normalization_test_file (const char *filename, if (part_index >= 0) { lines = - (struct normalization_test_line *) - xnrealloc (lines, lines_length, sizeof (struct normalization_test_line)); + (struct normalization_test_line *) + xnrealloc (lines, lines_length, sizeof (struct normalization_test_line)); file->parts[part_index].lines = lines; file->parts[part_index].lines_length = lines_length; } @@ -224,11 +224,11 @@ read_normalization_test_file (const char *filename, for (line_index = 0; line_index < p->lines_length; line_index++) { - const uint32_t *sequence = p->lines[line_index].sequences[0]; - /* In part 1, every sequences[0] consists of a single character. */ - if (!(sequence[0] != 0 && sequence[1] == 0)) - abort (); - c1_array[line_index] = sequence[0]; + const uint32_t *sequence = p->lines[line_index].sequences[0]; + /* In part 1, every sequences[0] consists of a single character. */ + if (!(sequence[0] != 0 && sequence[1] == 0)) + abort (); + c1_array[line_index] = sequence[0]; } /* Sort this array. */ @@ -251,11 +251,11 @@ read_normalization_test_file (const char *filename, void test_specific (const struct normalization_test_file *file, - int (*check) (const uint32_t *c1, size_t c1_length, - const uint32_t *c2, size_t c2_length, - const uint32_t *c3, size_t c3_length, - const uint32_t *c4, size_t c4_length, - const uint32_t *c5, size_t c5_length)) + int (*check) (const uint32_t *c1, size_t c1_length, + const uint32_t *c2, size_t c2_length, + const uint32_t *c3, size_t c3_length, + const uint32_t *c4, size_t c4_length, + const uint32_t *c5, size_t c5_length)) { size_t part_index; @@ -265,17 +265,17 @@ test_specific (const struct normalization_test_file *file, size_t line_index; for (line_index = 0; line_index < p->lines_length; line_index++) - { - const struct normalization_test_line *l = &p->lines[line_index]; - - ASSERT_WITH_LINE (check (l->sequences[0], u32_strlen (l->sequences[0]), - l->sequences[1], u32_strlen (l->sequences[1]), - l->sequences[2], u32_strlen (l->sequences[2]), - l->sequences[3], u32_strlen (l->sequences[3]), - l->sequences[4], u32_strlen (l->sequences[4])) - == 0, - file->filename, l->lineno); - } + { + const struct normalization_test_line *l = &p->lines[line_index]; + + ASSERT_WITH_LINE (check (l->sequences[0], u32_strlen (l->sequences[0]), + l->sequences[1], u32_strlen (l->sequences[1]), + l->sequences[2], u32_strlen (l->sequences[2]), + l->sequences[3], u32_strlen (l->sequences[3]), + l->sequences[4], u32_strlen (l->sequences[4])) + == 0, + file->filename, l->lineno); + } } } @@ -291,24 +291,24 @@ test_other (const struct normalization_test_file *file, uninorm_t nf) for (uc = 0; uc < 0x110000; uc++) { if (uc >= 0xD800 && uc < 0xE000) - { - /* A surrogate, not a character. Skip uc. */ - } + { + /* A surrogate, not a character. Skip uc. */ + } else if (uc == *p) - { - /* Skip uc. */ - p++; - } + { + /* Skip uc. */ + p++; + } else - { - uint32_t input[1]; - size_t length; - uint32_t *result; - - input[0] = uc; - result = u32_normalize (nf, input, 1, NULL, &length); - ASSERT (result != NULL && length == 1 && result[0] == uc); - } + { + uint32_t input[1]; + size_t length; + uint32_t *result; + + input[0] = uc; + result = u32_normalize (nf, input, 1, NULL, &length); + ASSERT (result != NULL && length == 1 && result[0] == uc); + } } } diff --git a/tests/uninorm/test-u32-normalize-big.h b/tests/uninorm/test-u32-normalize-big.h index f154daa91..66f66419d 100644 --- a/tests/uninorm/test-u32-normalize-big.h +++ b/tests/uninorm/test-u32-normalize-big.h @@ -54,16 +54,16 @@ struct normalization_test_file /* Read the NormalizationTest.txt file and return its contents. */ extern void read_normalization_test_file (const char *filename, - struct normalization_test_file *file); + struct normalization_test_file *file); /* Perform the first compliance test. */ extern void test_specific (const struct normalization_test_file *file, - int (*check) (const uint32_t *c1, size_t c1_length, - const uint32_t *c2, size_t c2_length, - const uint32_t *c3, size_t c3_length, - const uint32_t *c4, size_t c4_length, - const uint32_t *c5, size_t c5_length)); + int (*check) (const uint32_t *c1, size_t c1_length, + const uint32_t *c2, size_t c2_length, + const uint32_t *c3, size_t c3_length, + const uint32_t *c4, size_t c4_length, + const uint32_t *c5, size_t c5_length)); /* Perform the second compliance test. */ extern void diff --git a/tests/uninorm/test-u32-normcmp.c b/tests/uninorm/test-u32-normcmp.c index 846300a81..3edeffd61 100644 --- a/tests/uninorm/test-u32-normcmp.c +++ b/tests/uninorm/test-u32-normcmp.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u32-normcmp.h" diff --git a/tests/uninorm/test-u32-normcmp.h b/tests/uninorm/test-u32-normcmp.h index 06d5fad81..5eb1b1ec1 100644 --- a/tests/uninorm/test-u32-normcmp.h +++ b/tests/uninorm/test-u32-normcmp.h @@ -18,7 +18,7 @@ static void test_ascii (int (*my_normcmp) (const uint32_t *, size_t, const uint32_t *, size_t, uninorm_t, int *), - uninorm_t nf) + uninorm_t nf) { /* Empty string. */ { diff --git a/tests/uninorm/test-u32-normcoll.c b/tests/uninorm/test-u32-normcoll.c index 916d433fc..0019770b5 100644 --- a/tests/uninorm/test-u32-normcoll.c +++ b/tests/uninorm/test-u32-normcoll.c @@ -26,15 +26,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u32-normcmp.h" diff --git a/tests/uninorm/test-u8-nfc.c b/tests/uninorm/test-u8-nfc.c index 52baa68bc..3eb71a47d 100644 --- a/tests/uninorm/test-u8-nfc.c +++ b/tests/uninorm/test-u8-nfc.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_normalize (UNINORM_NFC, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -242,25 +242,25 @@ test_u8_nfc (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, - 0xEA, 0xB8, 0x80, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, + 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t decomposed[] = { 'G', 'r', 0x75, 0xCC, 0x88, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, - 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, + 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), input, SIZEOF (input)) == 0); @@ -278,89 +278,89 @@ test_u8_nfc (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); - if (input != NULL) - { - uint8_t *expected = input + (2 * m - 1); - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint8_t *p; - size_t i; - - input[0] = 0x41; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - break; - - case 1: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - *p++ = 0xCC; - *p++ = 0x80; - } - for (; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - default: - abort (); - } - - expected[0] = 0xC3; - expected[1] = 0x80; - p = expected + 2; - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2 - 1; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - - for (; repeat > 0; repeat--) - { - ASSERT (check (input, 2 * m - 1, expected, 2 * m - 2) == 0); - ASSERT (check (expected, 2 * m - 2, expected, 2 * m - 2) == 0); - } - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); + if (input != NULL) + { + uint8_t *expected = input + (2 * m - 1); + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint8_t *p; + size_t i; + + input[0] = 0x41; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + break; + + case 1: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + *p++ = 0xCC; + *p++ = 0x80; + } + for (; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + default: + abort (); + } + + expected[0] = 0xC3; + expected[1] = 0x80; + p = expected + 2; + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2 - 1; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + + for (; repeat > 0; repeat--) + { + ASSERT (check (input, 2 * m - 1, expected, 2 * m - 2) == 0); + ASSERT (check (expected, 2 * m - 2, expected, 2 * m - 2) == 0); + } + + free (input); + } } } } diff --git a/tests/uninorm/test-u8-nfd.c b/tests/uninorm/test-u8-nfd.c index d1d840acb..93bf297bc 100644 --- a/tests/uninorm/test-u8-nfd.c +++ b/tests/uninorm/test-u8-nfd.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_normalize (UNINORM_NFD, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -230,25 +230,25 @@ test_u8_nfd (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, - 0xEA, 0xB8, 0x80, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, + 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t expected[] = { 'G', 'r', 0x75, 0xCC, 0x88, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, - 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, + 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -265,85 +265,85 @@ test_u8_nfd (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); - if (input != NULL) - { - uint8_t *expected = input + (2 * m - 1); - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint8_t *p; - size_t i; - - input[0] = 0x41; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - break; - - case 1: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - *p++ = 0xCC; - *p++ = 0x80; - } - for (; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - default: - abort (); - } - - expected[0] = 0x41; - p = expected + 1; - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - - for (; repeat > 0; repeat--) - ASSERT (check (input, 2 * m - 1, expected, 2 * m - 1) == 0); - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); + if (input != NULL) + { + uint8_t *expected = input + (2 * m - 1); + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint8_t *p; + size_t i; + + input[0] = 0x41; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + break; + + case 1: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + *p++ = 0xCC; + *p++ = 0x80; + } + for (; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + default: + abort (); + } + + expected[0] = 0x41; + p = expected + 1; + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + + for (; repeat > 0; repeat--) + ASSERT (check (input, 2 * m - 1, expected, 2 * m - 1) == 0); + + free (input); + } } } } diff --git a/tests/uninorm/test-u8-nfkc.c b/tests/uninorm/test-u8-nfkc.c index 0ea463630..fcc50a34c 100644 --- a/tests/uninorm/test-u8-nfkc.c +++ b/tests/uninorm/test-u8-nfkc.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_normalize (UNINORM_NFKC, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -257,8 +257,8 @@ test_u8_nfkc (void) static const uint8_t input[] = { 0xEF, 0xB7, 0xBA }; static const uint8_t decomposed[] = { 0xD8, 0xB5, 0xD9, 0x84, 0xD9, 0x89, 0x20, 0xD8, 0xA7, 0xD9, 0x84, 0xD9, - 0x84, 0xD9, 0x87, 0x20, 0xD8, 0xB9, 0xD9, 0x84, 0xD9, 0x8A, 0xD9, 0x87, - 0x20, 0xD9, 0x88, 0xD8, 0xB3, 0xD9, 0x84, 0xD9, 0x85 + 0x84, 0xD9, 0x87, 0x20, 0xD8, 0xB9, 0xD9, 0x84, 0xD9, 0x8A, 0xD9, 0x87, + 0x20, 0xD9, 0x88, 0xD8, 0xB3, 0xD9, 0x84, 0xD9, 0x85 }; ASSERT (check (input, SIZEOF (input), decomposed, SIZEOF (decomposed)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), decomposed, SIZEOF (decomposed)) == 0); @@ -282,36 +282,36 @@ test_u8_nfkc (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, - 0xEA, 0xB8, 0x80, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, + 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t decomposed[] = { 'G', 'r', 0x75, 0xCC, 0x88, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, - 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, + 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' }; static const uint8_t expected[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, - 0xEA, 0xB8, 0x80, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, + 0xEA, 0xB8, 0x80, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), expected, SIZEOF (expected)) == 0); @@ -330,89 +330,89 @@ test_u8_nfkc (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); - if (input != NULL) - { - uint8_t *expected = input + (2 * m - 1); - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint8_t *p; - size_t i; - - input[0] = 0x41; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - break; - - case 1: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - *p++ = 0xCC; - *p++ = 0x80; - } - for (; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - default: - abort (); - } - - expected[0] = 0xC3; - expected[1] = 0x80; - p = expected + 2; - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2 - 1; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - - for (; repeat > 0; repeat--) - { - ASSERT (check (input, 2 * m - 1, expected, 2 * m - 2) == 0); - ASSERT (check (expected, 2 * m - 2, expected, 2 * m - 2) == 0); - } - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); + if (input != NULL) + { + uint8_t *expected = input + (2 * m - 1); + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint8_t *p; + size_t i; + + input[0] = 0x41; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + break; + + case 1: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + *p++ = 0xCC; + *p++ = 0x80; + } + for (; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + default: + abort (); + } + + expected[0] = 0xC3; + expected[1] = 0x80; + p = expected + 2; + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2 - 1; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + + for (; repeat > 0; repeat--) + { + ASSERT (check (input, 2 * m - 1, expected, 2 * m - 2) == 0); + ASSERT (check (expected, 2 * m - 2, expected, 2 * m - 2) == 0); + } + + free (input); + } } } } diff --git a/tests/uninorm/test-u8-nfkd.c b/tests/uninorm/test-u8-nfkd.c index 2d883a057..f1246d80c 100644 --- a/tests/uninorm/test-u8-nfkd.c +++ b/tests/uninorm/test-u8-nfkd.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static int @@ -68,13 +68,13 @@ check (const uint8_t *input, size_t input_length, preallocated = (uint8_t *) malloc (length * sizeof (uint8_t)); result = u8_normalize (UNINORM_NFKD, input, input_length, preallocated, &length); if (!(result != NULL)) - return 4; + return 4; if (!(result != preallocated)) - return 5; + return 5; if (!(length == expected_length)) - return 6; + return 6; if (!(u8_cmp (result, expected, expected_length) == 0)) - return 7; + return 7; free (result); free (preallocated); } @@ -229,8 +229,8 @@ test_u8_nfkd (void) static const uint8_t input[] = { 0xEF, 0xB7, 0xBA }; static const uint8_t expected[] = { 0xD8, 0xB5, 0xD9, 0x84, 0xD9, 0x89, 0x20, 0xD8, 0xA7, 0xD9, 0x84, 0xD9, - 0x84, 0xD9, 0x87, 0x20, 0xD8, 0xB9, 0xD9, 0x84, 0xD9, 0x8A, 0xD9, 0x87, - 0x20, 0xD9, 0x88, 0xD8, 0xB3, 0xD9, 0x84, 0xD9, 0x85 + 0x84, 0xD9, 0x87, 0x20, 0xD8, 0xB9, 0xD9, 0x84, 0xD9, 0x8A, 0xD9, 0x87, + 0x20, 0xD9, 0x88, 0xD8, 0xB3, 0xD9, 0x84, 0xD9, 0x85 }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -251,25 +251,25 @@ test_u8_nfkd (void) { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint8_t input[] = { 'G', 'r', 0xC3, 0xBC, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xED, 0x95, 0x9C, - 0xEA, 0xB8, 0x80, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB9, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0xC2, 0xB2, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xED, 0x95, 0x9C, + 0xEA, 0xB8, 0x80, '\n' }; static const uint8_t expected[] = { 'G', 'r', 0x75, 0xCC, 0x88, 0xC3, 0x9F, ' ', 'G', 'o', 't', 't', '.', - ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, - 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, - 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, - 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', - '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, - 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', - 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, - 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' + ' ', 0xD0, 0x97, 0xD0, 0xB4, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xB2, 0xD1, + 0x81, 0xD1, 0x82, 0xD0, 0xB2, 0xD1, 0x83, 0xD0, 0xB8, 0xCC, 0x86, + 0xD1, 0x82, 0xD0, 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', 0xC2, 0xB1, + 's', 'q', 'r', 't', '(', 'b', 0x32, '-', '4', 'a', 'c', ')', ')', + '/', '(', '2', 'a', ')', ' ', ' ', 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, + 0xE8, 0xAA, 0x9E, ',', 0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, ',', + 0xE1, 0x84, 0x92, 0xE1, 0x85, 0xA1, 0xE1, 0x86, 0xAB, + 0xE1, 0x84, 0x80, 0xE1, 0x85, 0xB3, 0xE1, 0x86, 0xAF, '\n' }; ASSERT (check (input, SIZEOF (input), expected, SIZEOF (expected)) == 0); } @@ -286,85 +286,85 @@ test_u8_nfkd (void) int pass; for (pass = 0; pass < 3; pass++) { - size_t repeat = 1; - size_t m = 100000; - uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); - if (input != NULL) - { - uint8_t *expected = input + (2 * m - 1); - size_t m1 = m / 2; - size_t m2 = (m - 1) / 2; - /* NB: m1 + m2 == m - 1. */ - uint8_t *p; - size_t i; - - input[0] = 0x41; - p = input + 1; - switch (pass) - { - case 0: - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - break; - - case 1: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - case 2: - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - *p++ = 0xCC; - *p++ = 0x80; - } - for (; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - break; - - default: - abort (); - } - - expected[0] = 0x41; - p = expected + 1; - for (i = 0; i < m1; i++) - { - *p++ = 0xCC; - *p++ = 0x99; - } - for (i = 0; i < m2; i++) - { - *p++ = 0xCC; - *p++ = 0x80; - } - - for (; repeat > 0; repeat--) - ASSERT (check (input, 2 * m - 1, expected, 2 * m - 1) == 0); - - free (input); - } + size_t repeat = 1; + size_t m = 100000; + uint8_t *input = (uint8_t *) malloc (2 * (2 * m - 1) * sizeof (uint8_t)); + if (input != NULL) + { + uint8_t *expected = input + (2 * m - 1); + size_t m1 = m / 2; + size_t m2 = (m - 1) / 2; + /* NB: m1 + m2 == m - 1. */ + uint8_t *p; + size_t i; + + input[0] = 0x41; + p = input + 1; + switch (pass) + { + case 0: + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + break; + + case 1: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + case 2: + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + *p++ = 0xCC; + *p++ = 0x80; + } + for (; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + break; + + default: + abort (); + } + + expected[0] = 0x41; + p = expected + 1; + for (i = 0; i < m1; i++) + { + *p++ = 0xCC; + *p++ = 0x99; + } + for (i = 0; i < m2; i++) + { + *p++ = 0xCC; + *p++ = 0x80; + } + + for (; repeat > 0; repeat--) + ASSERT (check (input, 2 * m - 1, expected, 2 * m - 1) == 0); + + free (input); + } } } } diff --git a/tests/uninorm/test-u8-normcmp.c b/tests/uninorm/test-u8-normcmp.c index ec4794727..643dd3e07 100644 --- a/tests/uninorm/test-u8-normcmp.c +++ b/tests/uninorm/test-u8-normcmp.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u8-normcmp.h" diff --git a/tests/uninorm/test-u8-normcmp.h b/tests/uninorm/test-u8-normcmp.h index 78c887d2b..3ee583241 100644 --- a/tests/uninorm/test-u8-normcmp.h +++ b/tests/uninorm/test-u8-normcmp.h @@ -18,7 +18,7 @@ static void test_ascii (int (*my_normcmp) (const uint8_t *, size_t, const uint8_t *, size_t, uninorm_t, int *), - uninorm_t nf) + uninorm_t nf) { /* Empty string. */ { diff --git a/tests/uninorm/test-u8-normcoll.c b/tests/uninorm/test-u8-normcoll.c index edf917200..4f907308f 100644 --- a/tests/uninorm/test-u8-normcoll.c +++ b/tests/uninorm/test-u8-normcoll.c @@ -26,15 +26,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u8-normcmp.h" diff --git a/tests/uninorm/test-uninorm-filter-nfc.c b/tests/uninorm/test-uninorm-filter-nfc.c index 32b77efac..1dd040301 100644 --- a/tests/uninorm/test-uninorm-filter-nfc.c +++ b/tests/uninorm/test-uninorm-filter-nfc.c @@ -27,15 +27,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* A stream of Unicode characters that simply accumulates the contents. */ @@ -99,20 +99,20 @@ main () { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ static const uint32_t input[] = { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; static const uint32_t decomposed[] = { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; ASSERT (check (input, SIZEOF (input), input, SIZEOF (input)) == 0); ASSERT (check (decomposed, SIZEOF (decomposed), input, SIZEOF (input)) == 0); diff --git a/tests/unistdio/test-u16-asnprintf1.c b/tests/unistdio/test-u16-asnprintf1.c index 53fedf348..f2d2f706b 100644 --- a/tests/unistdio/test-u16-asnprintf1.c +++ b/tests/unistdio/test-u16-asnprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u16-asnprintf1.h" diff --git a/tests/unistdio/test-u16-asnprintf1.h b/tests/unistdio/test-u16-asnprintf1.h index 34d4f8217..f796dfa11 100644 --- a/tests/unistdio/test-u16-asnprintf1.h +++ b/tests/unistdio/test-u16-asnprintf1.h @@ -29,7 +29,7 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . size_t length = size; uint16_t *result = my_asnprintf (NULL, &length, "%d", 12345); static const uint16_t expected[] = - { '1', '2', '3', '4', '5', 0 }; + { '1', '2', '3', '4', '5', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == 5); @@ -39,9 +39,9 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . for (size = 0; size <= 8; size++) { static const uint16_t initializer[] = - { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F', 0 }; + { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F', 0 }; static const uint16_t expected[] = - { '1', '2', '3', '4', '5', 0 }; + { '1', '2', '3', '4', '5', 0 }; size_t length; uint16_t *result; @@ -52,9 +52,9 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == 5); if (size < 6) - ASSERT (result != buf); + ASSERT (result != buf); ASSERT (u16_cmp (buf + size, initializer + size, 8 - size) == 0); if (result != buf) - free (result); + free (result); } } diff --git a/tests/unistdio/test-u16-printf1.h b/tests/unistdio/test-u16-printf1.h index 199ece905..b9f924487 100644 --- a/tests/unistdio/test-u16-printf1.h +++ b/tests/unistdio/test-u16-printf1.h @@ -67,36 +67,36 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) static const uint8_t unicode_string[] = "Hello"; { uint16_t *result = - my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint16_t *result = - my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint16_t *result = - my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint16_t *result = - my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); @@ -107,36 +107,36 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { uint16_t *result = - my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint16_t *result = - my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint16_t *result = - my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint16_t *result = - my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); @@ -147,36 +147,36 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { uint16_t *result = - my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint16_t *result = - my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint16_t *result = - my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint16_t *result = - my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); @@ -190,8 +190,8 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55); static const uint16_t expected[] = { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', - ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', '3', '3', - 0 + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -203,8 +203,8 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55); static const uint16_t expected[] = { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', - 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -216,8 +216,8 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); static const uint16_t expected[] = { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', - ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', '3', '3', 0 + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -229,8 +229,8 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55); static const uint16_t expected[] = { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', - 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -253,9 +253,9 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -272,9 +272,9 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -283,29 +283,29 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); static const uint16_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint16_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint16_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint16_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -314,45 +314,45 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.50a %d", 1.75, 33, 44, 55); static const uint16_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint16_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint16_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint16_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -361,25 +361,25 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55); static const uint16_t expected1[] = { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1', - ' ', '3', '3', 0 + ' ', '3', '3', 0 }; static const uint16_t expected2[] = { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0', - ' ', '3', '3', 0 + ' ', '3', '3', 0 }; static const uint16_t expected3[] = { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1', - ' ', '3', '3', 0 + ' ', '3', '3', 0 }; static const uint16_t expected4[] = { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', - '3', '3', 0 + '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -396,9 +396,9 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -407,29 +407,29 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); static const uint16_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint16_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint16_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint16_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -438,45 +438,45 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55); static const uint16_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint16_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint16_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint16_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0 - || u16_strcmp (result, expected3) == 0 - || u16_strcmp (result, expected4) == 0); + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); free (result); } @@ -591,15 +591,15 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%e %d", 12.75, 33, 44, 55); static const uint16_t expected1[] = { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', - '0', '1', ' ', '3', '3', 0 + '0', '1', ' ', '3', '3', 0 }; static const uint16_t expected2[] = { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', - '0', '0', '1', ' ', '3', '3', 0 + '0', '0', '1', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0); + || u16_strcmp (result, expected2) == 0); free (result); } @@ -608,15 +608,15 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%15e %d", 1.75, 33, 44, 55); static const uint16_t expected1[] = { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', - '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 }; static const uint16_t expected2[] = { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', - 'e', '+', '0', '0', '0', ' ', '3', '3', 0 + 'e', '+', '0', '0', '0', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0); + || u16_strcmp (result, expected2) == 0); free (result); } @@ -629,7 +629,7 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0); + || u16_strcmp (result, expected2) == 0); free (result); } @@ -638,7 +638,7 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%Le %d", 12.75L, 33, 44, 55); static const uint16_t expected[] = { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', - '0', '1', ' ', '3', '3', 0 + '0', '1', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -650,7 +650,7 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55); static const uint16_t expected[] = { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', - '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); @@ -698,7 +698,7 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected1) == 0 - || u16_strcmp (result, expected2) == 0); + || u16_strcmp (result, expected2) == 0); free (result); } @@ -774,47 +774,47 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ { uint16_t *result = - my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint16_t *result = - my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint16_t *result = - my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint16_t *result = - my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); @@ -824,52 +824,52 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) { static const uint16_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { uint16_t *result = - my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint16_t *result = - my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint16_t *result = - my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint16_t *result = - my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); @@ -879,52 +879,52 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) { static const uint32_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { uint16_t *result = - my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint16_t *result = - my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint16_t *result = - my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint16_t *result = - my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); free (result); diff --git a/tests/unistdio/test-u16-vasnprintf1.c b/tests/unistdio/test-u16-vasnprintf1.c index b236e3fee..7907168c0 100644 --- a/tests/unistdio/test-u16-vasnprintf1.c +++ b/tests/unistdio/test-u16-vasnprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u16-asnprintf1.h" diff --git a/tests/unistdio/test-u16-vasnprintf2.c b/tests/unistdio/test-u16-vasnprintf2.c index 6f7b7cf6f..8f1d48cab 100644 --- a/tests/unistdio/test-u16-vasnprintf2.c +++ b/tests/unistdio/test-u16-vasnprintf2.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -52,9 +52,9 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); @@ -63,11 +63,11 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { /* Width. */ size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); @@ -76,11 +76,11 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { /* FLAG_LEFT. */ size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); @@ -89,11 +89,11 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { /* FLAG_ZERO: no effect. */ size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); diff --git a/tests/unistdio/test-u16-vasnprintf3.c b/tests/unistdio/test-u16-vasnprintf3.c index 140218190..b758f7394 100644 --- a/tests/unistdio/test-u16-vasnprintf3.c +++ b/tests/unistdio/test-u16-vasnprintf3.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -52,9 +52,9 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); @@ -63,11 +63,11 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { /* Width. */ size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); @@ -76,11 +76,11 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { /* FLAG_LEFT. */ size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); @@ -89,11 +89,11 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . { /* FLAG_ZERO: no effect. */ size_t length; uint16_t *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); static const uint16_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u16_strcmp (result, expected) == 0); ASSERT (length == u16_strlen (result)); diff --git a/tests/unistdio/test-u16-vasprintf1.c b/tests/unistdio/test-u16-vasprintf1.c index 8b9612689..b534dfe04 100644 --- a/tests/unistdio/test-u16-vasprintf1.c +++ b/tests/unistdio/test-u16-vasprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u16-printf1.h" diff --git a/tests/unistdio/test-u16-vsnprintf1.c b/tests/unistdio/test-u16-vsnprintf1.c index 886e95b33..37420f751 100644 --- a/tests/unistdio/test-u16-vsnprintf1.c +++ b/tests/unistdio/test-u16-vsnprintf1.c @@ -34,15 +34,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u16-printf1.h" diff --git a/tests/unistdio/test-u16-vsprintf1.c b/tests/unistdio/test-u16-vsprintf1.c index e6b6eab7e..179c4a36e 100644 --- a/tests/unistdio/test-u16-vsprintf1.c +++ b/tests/unistdio/test-u16-vsprintf1.c @@ -34,15 +34,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u16-printf1.h" diff --git a/tests/unistdio/test-u32-asnprintf1.c b/tests/unistdio/test-u32-asnprintf1.c index 252e919f1..a470cbf5b 100644 --- a/tests/unistdio/test-u32-asnprintf1.c +++ b/tests/unistdio/test-u32-asnprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u32-asnprintf1.h" diff --git a/tests/unistdio/test-u32-asnprintf1.h b/tests/unistdio/test-u32-asnprintf1.h index dfaed98dc..13092a82f 100644 --- a/tests/unistdio/test-u32-asnprintf1.h +++ b/tests/unistdio/test-u32-asnprintf1.h @@ -29,7 +29,7 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . size_t length = size; uint32_t *result = my_asnprintf (NULL, &length, "%d", 12345); static const uint32_t expected[] = - { '1', '2', '3', '4', '5', 0 }; + { '1', '2', '3', '4', '5', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == 5); @@ -39,9 +39,9 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . for (size = 0; size <= 8; size++) { static const uint32_t initializer[] = - { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F', 0 }; + { 'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F', 0 }; static const uint32_t expected[] = - { '1', '2', '3', '4', '5', 0 }; + { '1', '2', '3', '4', '5', 0 }; size_t length; uint32_t *result; @@ -52,9 +52,9 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == 5); if (size < 6) - ASSERT (result != buf); + ASSERT (result != buf); ASSERT (u32_cmp (buf + size, initializer + size, 8 - size) == 0); if (result != buf) - free (result); + free (result); } } diff --git a/tests/unistdio/test-u32-printf1.h b/tests/unistdio/test-u32-printf1.h index 240232fd9..7d7007a6b 100644 --- a/tests/unistdio/test-u32-printf1.h +++ b/tests/unistdio/test-u32-printf1.h @@ -67,36 +67,36 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) static const uint8_t unicode_string[] = "Hello"; { uint32_t *result = - my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint32_t *result = - my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint32_t *result = - my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint32_t *result = - my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); @@ -107,36 +107,36 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { uint32_t *result = - my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint32_t *result = - my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint32_t *result = - my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint32_t *result = - my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); @@ -147,36 +147,36 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { uint32_t *result = - my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint32_t *result = - my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint32_t *result = - my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint32_t *result = - my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); @@ -190,8 +190,8 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %s %d", "Ronald Reagan", 33, 44, 55); static const uint32_t expected[] = { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', - ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', '3', '3', - 0 + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -203,8 +203,8 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %20s %d", "Ronald Reagan", 33, 44, 55); static const uint32_t expected[] = { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', - 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -216,8 +216,8 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); static const uint32_t expected[] = { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', - ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', '3', '3', 0 + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -229,8 +229,8 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("Mr. %020s %d", "Ronald Reagan", 33, 44, 55); static const uint32_t expected[] = { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', - 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -253,9 +253,9 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -272,9 +272,9 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -283,29 +283,29 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); static const uint32_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint32_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint32_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint32_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -314,45 +314,45 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.50a %d", 1.75, 33, 44, 55); static const uint32_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint32_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint32_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint32_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -361,25 +361,25 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55); static const uint32_t expected1[] = { '0', 'x', '1', '.', '9', '2', '2', 'p', '+', '1', - ' ', '3', '3', 0 + ' ', '3', '3', 0 }; static const uint32_t expected2[] = { '0', 'x', '3', '.', '2', '4', '4', 'p', '+', '0', - ' ', '3', '3', 0 + ' ', '3', '3', 0 }; static const uint32_t expected3[] = { '0', 'x', '6', '.', '4', '8', '8', 'p', '-', '1', - ' ', '3', '3', 0 + ' ', '3', '3', 0 }; static const uint32_t expected4[] = { '0', 'x', 'c', '.', '9', '1', 'p', '-', '2', ' ', - '3', '3', 0 + '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -396,9 +396,9 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -407,29 +407,29 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); static const uint32_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint32_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint32_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint32_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -438,45 +438,45 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55); static const uint32_t expected1[] = { '0', 'x', '1', '.', 'c', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '+', '0', ' ', '3', '3', + 0 }; static const uint32_t expected2[] = { '0', 'x', '3', '.', '8', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '1', ' ', '3', '3', + 0 }; static const uint32_t expected3[] = { '0', 'x', '7', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '2', ' ', '3', '3', + 0 }; static const uint32_t expected4[] = { '0', 'x', 'e', '.', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', - 0 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', '0', '0', '0', 'p', '-', '3', ' ', '3', '3', + 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0 - || u32_strcmp (result, expected3) == 0 - || u32_strcmp (result, expected4) == 0); + || u32_strcmp (result, expected2) == 0 + || u32_strcmp (result, expected3) == 0 + || u32_strcmp (result, expected4) == 0); free (result); } @@ -591,15 +591,15 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%e %d", 12.75, 33, 44, 55); static const uint32_t expected1[] = { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', - '0', '1', ' ', '3', '3', 0 + '0', '1', ' ', '3', '3', 0 }; static const uint32_t expected2[] = { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', - '0', '0', '1', ' ', '3', '3', 0 + '0', '0', '1', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0); + || u32_strcmp (result, expected2) == 0); free (result); } @@ -608,15 +608,15 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%15e %d", 1.75, 33, 44, 55); static const uint32_t expected1[] = { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', - '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 }; static const uint32_t expected2[] = { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', - 'e', '+', '0', '0', '0', ' ', '3', '3', 0 + 'e', '+', '0', '0', '0', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0); + || u32_strcmp (result, expected2) == 0); free (result); } @@ -629,7 +629,7 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0); + || u32_strcmp (result, expected2) == 0); free (result); } @@ -638,7 +638,7 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%Le %d", 12.75L, 33, 44, 55); static const uint32_t expected[] = { '1', '.', '2', '7', '5', '0', '0', '0', 'e', '+', - '0', '1', ' ', '3', '3', 0 + '0', '1', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -650,7 +650,7 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%15Le %d", 1.75L, 33, 44, 55); static const uint32_t expected[] = { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', - '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); @@ -698,7 +698,7 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) { '1', 'e', '+', '0', '0', '3', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected1) == 0 - || u32_strcmp (result, expected2) == 0); + || u32_strcmp (result, expected2) == 0); free (result); } @@ -774,47 +774,47 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ { uint32_t *result = - my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint32_t *result = - my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint32_t *result = - my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint32_t *result = - my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); @@ -824,52 +824,52 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) { static const uint16_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { uint32_t *result = - my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint32_t *result = - my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint32_t *result = - my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint32_t *result = - my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); @@ -879,52 +879,52 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...)) { static const uint32_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { uint32_t *result = - my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* Width. */ uint32_t *result = - my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_LEFT. */ uint32_t *result = - my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', - 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); } { /* FLAG_ZERO: no effect. */ uint32_t *result = - my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', - 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); free (result); diff --git a/tests/unistdio/test-u32-vasnprintf1.c b/tests/unistdio/test-u32-vasnprintf1.c index 959bdab3a..d068c2713 100644 --- a/tests/unistdio/test-u32-vasnprintf1.c +++ b/tests/unistdio/test-u32-vasnprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u32-asnprintf1.h" diff --git a/tests/unistdio/test-u32-vasnprintf2.c b/tests/unistdio/test-u32-vasnprintf2.c index 9d8ab007a..ec5b46dad 100644 --- a/tests/unistdio/test-u32-vasnprintf2.c +++ b/tests/unistdio/test-u32-vasnprintf2.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -52,9 +52,9 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); @@ -63,11 +63,11 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { /* Width. */ size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); @@ -76,11 +76,11 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { /* FLAG_LEFT. */ size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); @@ -89,11 +89,11 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { /* FLAG_ZERO: no effect. */ size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); diff --git a/tests/unistdio/test-u32-vasnprintf3.c b/tests/unistdio/test-u32-vasnprintf3.c index 73f7c6c7f..78608ffa9 100644 --- a/tests/unistdio/test-u32-vasnprintf3.c +++ b/tests/unistdio/test-u32-vasnprintf3.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -52,9 +52,9 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); @@ -63,11 +63,11 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { /* Width. */ size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); @@ -76,11 +76,11 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { /* FLAG_LEFT. */ size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', - ' ', '3', '3', 0 - }; + { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); @@ -89,11 +89,11 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, . { /* FLAG_ZERO: no effect. */ size_t length; uint32_t *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); static const uint32_t expected[] = - { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', - ' ', '3', '3', 0 - }; + { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r', + ' ', '3', '3', 0 + }; ASSERT (result != NULL); ASSERT (u32_strcmp (result, expected) == 0); ASSERT (length == u32_strlen (result)); diff --git a/tests/unistdio/test-u32-vasprintf1.c b/tests/unistdio/test-u32-vasprintf1.c index 39e68d25e..901424c30 100644 --- a/tests/unistdio/test-u32-vasprintf1.c +++ b/tests/unistdio/test-u32-vasprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u32-printf1.h" diff --git a/tests/unistdio/test-u32-vsnprintf1.c b/tests/unistdio/test-u32-vsnprintf1.c index d77270811..af52a7b34 100644 --- a/tests/unistdio/test-u32-vsnprintf1.c +++ b/tests/unistdio/test-u32-vsnprintf1.c @@ -34,15 +34,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u32-printf1.h" diff --git a/tests/unistdio/test-u32-vsprintf1.c b/tests/unistdio/test-u32-vsprintf1.c index 8398b274b..6f23d83bf 100644 --- a/tests/unistdio/test-u32-vsprintf1.c +++ b/tests/unistdio/test-u32-vsprintf1.c @@ -34,15 +34,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u32-printf1.h" diff --git a/tests/unistdio/test-u8-asnprintf1.c b/tests/unistdio/test-u8-asnprintf1.c index 852d76b4c..820e5e1af 100644 --- a/tests/unistdio/test-u8-asnprintf1.c +++ b/tests/unistdio/test-u8-asnprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u8-asnprintf1.h" diff --git a/tests/unistdio/test-u8-asnprintf1.h b/tests/unistdio/test-u8-asnprintf1.h index 063f145f4..620a003b9 100644 --- a/tests/unistdio/test-u8-asnprintf1.h +++ b/tests/unistdio/test-u8-asnprintf1.h @@ -49,9 +49,9 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... ASSERT (u8_strcmp (result, expected) == 0); ASSERT (length == 5); if (size < 6) - ASSERT (result != buf); + ASSERT (result != buf); ASSERT (u8_cmp (buf + size, initializer + size, 8 - size) == 0); if (result != buf) - free (result); + free (result); } } diff --git a/tests/unistdio/test-u8-printf1.h b/tests/unistdio/test-u8-printf1.h index 4ac6573f0..ed49ffc6e 100644 --- a/tests/unistdio/test-u8-printf1.h +++ b/tests/unistdio/test-u8-printf1.h @@ -63,7 +63,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t unicode_string[] = "Hello"; { uint8_t *result = - my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -71,7 +71,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* Width. */ uint8_t *result = - my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -79,7 +79,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_LEFT. */ uint8_t *result = - my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -87,7 +87,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_ZERO: no effect. */ uint8_t *result = - my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -99,7 +99,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { uint8_t *result = - my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -107,7 +107,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* Width. */ uint8_t *result = - my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -115,7 +115,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_LEFT. */ uint8_t *result = - my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -123,7 +123,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_ZERO: no effect. */ uint8_t *result = - my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -135,7 +135,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { uint8_t *result = - my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -143,7 +143,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* Width. */ uint8_t *result = - my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -151,7 +151,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_LEFT. */ uint8_t *result = - my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -159,7 +159,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_ZERO: no effect. */ uint8_t *result = - my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Hello 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -217,9 +217,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = "0xc.91p-2 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -232,9 +232,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = " 0xep-3 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -247,9 +247,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = "0xe.0000000000p-3 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -262,9 +262,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = "0xe.00000000000000000000000000000000000000000000000000p-3 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -277,9 +277,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = "0xc.91p-2 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -292,9 +292,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = " 0xep-3 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -307,9 +307,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = "0xe.0000000000p-3 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -322,9 +322,9 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected4[] = "0xe.00000000000000000000000000000000000000000000000000p-3 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0 - || u8_strcmp (result, expected3) == 0 - || u8_strcmp (result, expected4) == 0); + || u8_strcmp (result, expected2) == 0 + || u8_strcmp (result, expected3) == 0 + || u8_strcmp (result, expected4) == 0); free (result); } @@ -431,7 +431,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected2[] = "1.275000e+001 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0); + || u8_strcmp (result, expected2) == 0); free (result); } @@ -442,7 +442,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected2[] = " 1.750000e+000 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0); + || u8_strcmp (result, expected2) == 0); free (result); } @@ -453,7 +453,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected2[] = "1e+003 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0); + || u8_strcmp (result, expected2) == 0); free (result); } @@ -511,7 +511,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t expected2[] = "1e+003 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected1) == 0 - || u8_strcmp (result, expected2) == 0); + || u8_strcmp (result, expected2) == 0); free (result); } @@ -582,7 +582,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */ { uint8_t *result = - my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -590,7 +590,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* Width. */ uint8_t *result = - my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -598,7 +598,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_LEFT. */ uint8_t *result = - my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -606,7 +606,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_ZERO: no effect. */ uint8_t *result = - my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020U %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -617,12 +617,12 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) { static const uint16_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { uint8_t *result = - my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -630,7 +630,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* Width. */ uint8_t *result = - my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -638,7 +638,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_LEFT. */ uint8_t *result = - my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -646,7 +646,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_ZERO: no effect. */ uint8_t *result = - my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020lU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -657,12 +657,12 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) { static const uint32_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { uint8_t *result = - my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -670,7 +670,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* Width. */ uint8_t *result = - my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%20llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -678,7 +678,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_LEFT. */ uint8_t *result = - my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -686,7 +686,7 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...)) } { /* FLAG_ZERO: no effect. */ uint8_t *result = - my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%020llU %d", unicode_string, 33, 44, 55); static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); diff --git a/tests/unistdio/test-u8-vasnprintf1.c b/tests/unistdio/test-u8-vasnprintf1.c index 3329df403..9e597b8f3 100644 --- a/tests/unistdio/test-u8-vasnprintf1.c +++ b/tests/unistdio/test-u8-vasnprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u8-asnprintf1.h" diff --git a/tests/unistdio/test-u8-vasnprintf2.c b/tests/unistdio/test-u8-vasnprintf2.c index 4283be69e..df59f40e3 100644 --- a/tests/unistdio/test-u8-vasnprintf2.c +++ b/tests/unistdio/test-u8-vasnprintf2.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -52,7 +52,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = "\303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -62,7 +62,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { /* Width. */ size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = " \303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -72,7 +72,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { /* FLAG_LEFT. */ size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = "\303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -82,7 +82,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { /* FLAG_ZERO: no effect. */ size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = " \303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); diff --git a/tests/unistdio/test-u8-vasnprintf3.c b/tests/unistdio/test-u8-vasnprintf3.c index fc645bca1..d35d64787 100644 --- a/tests/unistdio/test-u8-vasnprintf3.c +++ b/tests/unistdio/test-u8-vasnprintf3.c @@ -31,15 +31,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -52,7 +52,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = "\303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -62,7 +62,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { /* Width. */ size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = " \303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -72,7 +72,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { /* FLAG_LEFT. */ size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = "\303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); @@ -82,7 +82,7 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ... { /* FLAG_ZERO: no effect. */ size_t length; uint8_t *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); static const uint8_t expected[] = " \303\204rger 33"; ASSERT (result != NULL); ASSERT (u8_strcmp (result, expected) == 0); diff --git a/tests/unistdio/test-u8-vasprintf1.c b/tests/unistdio/test-u8-vasprintf1.c index 8a2caae89..dc9afb438 100644 --- a/tests/unistdio/test-u8-vasprintf1.c +++ b/tests/unistdio/test-u8-vasprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u8-printf1.h" diff --git a/tests/unistdio/test-u8-vsnprintf1.c b/tests/unistdio/test-u8-vsnprintf1.c index 6dd7439d4..c494c6d61 100644 --- a/tests/unistdio/test-u8-vsnprintf1.c +++ b/tests/unistdio/test-u8-vsnprintf1.c @@ -34,15 +34,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u8-printf1.h" diff --git a/tests/unistdio/test-u8-vsprintf1.c b/tests/unistdio/test-u8-vsprintf1.c index 9559df0c9..a607a7f9c 100644 --- a/tests/unistdio/test-u8-vsprintf1.c +++ b/tests/unistdio/test-u8-vsprintf1.c @@ -34,15 +34,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-u8-printf1.h" diff --git a/tests/unistdio/test-ulc-asnprintf1.c b/tests/unistdio/test-ulc-asnprintf1.c index 591ae262d..8ad1906b1 100644 --- a/tests/unistdio/test-ulc-asnprintf1.c +++ b/tests/unistdio/test-ulc-asnprintf1.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-ulc-asnprintf1.h" diff --git a/tests/unistdio/test-ulc-asnprintf1.h b/tests/unistdio/test-ulc-asnprintf1.h index 285a4062e..77d592726 100644 --- a/tests/unistdio/test-ulc-asnprintf1.h +++ b/tests/unistdio/test-ulc-asnprintf1.h @@ -46,9 +46,9 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) ASSERT (strcmp (result, "12345") == 0); ASSERT (length == 5); if (size < 6) - ASSERT (result != buf); + ASSERT (result != buf); ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0); if (result != buf) - free (result); + free (result); } } diff --git a/tests/unistdio/test-ulc-printf1.h b/tests/unistdio/test-ulc-printf1.h index 77516d61c..9d4a12008 100644 --- a/tests/unistdio/test-ulc-printf1.h +++ b/tests/unistdio/test-ulc-printf1.h @@ -59,28 +59,28 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) static const uint8_t unicode_string[] = "Hello"; { char *result = - my_xasprintf ("%U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Hello 33") == 0); free (result); } { /* Width. */ char *result = - my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Hello 33") == 0); free (result); } { /* FLAG_LEFT. */ char *result = - my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Hello 33") == 0); free (result); } { /* FLAG_ZERO: no effect. */ char *result = - my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Hello 33") == 0); free (result); @@ -91,28 +91,28 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { char *result = - my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Hello 33") == 0); free (result); } { /* Width. */ char *result = - my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Hello 33") == 0); free (result); } { /* FLAG_LEFT. */ char *result = - my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Hello 33") == 0); free (result); } { /* FLAG_ZERO: no effect. */ char *result = - my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Hello 33") == 0); free (result); @@ -123,28 +123,28 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 }; { char *result = - my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Hello 33") == 0); free (result); } { /* Width. */ char *result = - my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Hello 33") == 0); free (result); } { /* FLAG_LEFT. */ char *result = - my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Hello 33") == 0); free (result); } { /* FLAG_ZERO: no effect. */ char *result = - my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); + my_xasprintf ("%010llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Hello 33") == 0); free (result); @@ -193,9 +193,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%a %d", 3.1416015625, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); free (result); } @@ -204,9 +204,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); free (result); } @@ -215,9 +215,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); free (result); } @@ -226,9 +226,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.50a %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); free (result); } @@ -237,9 +237,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%La %d", 3.1416015625L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); free (result); } @@ -248,9 +248,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 0x1.cp+0 33") == 0 - || strcmp (result, " 0x3.8p-1 33") == 0 - || strcmp (result, " 0x7p-2 33") == 0 - || strcmp (result, " 0xep-3 33") == 0); + || strcmp (result, " 0x3.8p-1 33") == 0 + || strcmp (result, " 0x7p-2 33") == 0 + || strcmp (result, " 0xep-3 33") == 0); free (result); } @@ -259,9 +259,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c000000000p+0 33") == 0 - || strcmp (result, "0x3.8000000000p-1 33") == 0 - || strcmp (result, "0x7.0000000000p-2 33") == 0 - || strcmp (result, "0xe.0000000000p-3 33") == 0); + || strcmp (result, "0x3.8000000000p-1 33") == 0 + || strcmp (result, "0x7.0000000000p-2 33") == 0 + || strcmp (result, "0xe.0000000000p-3 33") == 0); free (result); } @@ -270,9 +270,9 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.50La %d", 1.75L, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "0x1.c0000000000000000000000000000000000000000000000000p+0 33") == 0 - || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 - || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 - || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); + || strcmp (result, "0x3.80000000000000000000000000000000000000000000000000p-1 33") == 0 + || strcmp (result, "0x7.00000000000000000000000000000000000000000000000000p-2 33") == 0 + || strcmp (result, "0xe.00000000000000000000000000000000000000000000000000p-3 33") == 0); free (result); } @@ -367,7 +367,7 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%e %d", 12.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1.275000e+01 33") == 0 - || strcmp (result, "1.275000e+001 33") == 0); + || strcmp (result, "1.275000e+001 33") == 0); free (result); } @@ -376,7 +376,7 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%15e %d", 1.75, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " 1.750000e+00 33") == 0 - || strcmp (result, " 1.750000e+000 33") == 0); + || strcmp (result, " 1.750000e+000 33") == 0); free (result); } @@ -385,7 +385,7 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); free (result); } @@ -436,7 +436,7 @@ test_xfunction (char * (*my_xasprintf) (const char *, ...)) my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "1e+03 33") == 0 - || strcmp (result, "1e+003 33") == 0); + || strcmp (result, "1e+003 33") == 0); free (result); } diff --git a/tests/unistdio/test-ulc-vasnprintf1.c b/tests/unistdio/test-ulc-vasnprintf1.c index e2f8be6d7..a9af5637b 100644 --- a/tests/unistdio/test-ulc-vasnprintf1.c +++ b/tests/unistdio/test-ulc-vasnprintf1.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-ulc-asnprintf1.h" diff --git a/tests/unistdio/test-ulc-vasnprintf2.c b/tests/unistdio/test-ulc-vasnprintf2.c index 90229751f..d1c035ede 100644 --- a/tests/unistdio/test-ulc-vasnprintf2.c +++ b/tests/unistdio/test-ulc-vasnprintf2.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -50,40 +50,40 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { size_t length; char *result = - my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 - || strcmp (result, "Rafal Maszkowski 33") == 0); + || strcmp (result, "Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 - || strcmp (result, " Rafal Maszkowski 33") == 0); + || strcmp (result, " Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 - || strcmp (result, "Rafal Maszkowski 33") == 0); + || strcmp (result, "Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 - || strcmp (result, " Rafal Maszkowski 33") == 0); + || strcmp (result, " Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -92,46 +92,46 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { static const uint16_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { size_t length; char *result = - my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 - || strcmp (result, "Rafal Maszkowski 33") == 0); + || strcmp (result, "Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 - || strcmp (result, " Rafal Maszkowski 33") == 0); + || strcmp (result, " Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 - || strcmp (result, "Rafal Maszkowski 33") == 0); + || strcmp (result, "Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 - || strcmp (result, " Rafal Maszkowski 33") == 0); + || strcmp (result, " Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -140,46 +140,46 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { static const uint32_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { size_t length; char *result = - my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 - || strcmp (result, "Rafal Maszkowski 33") == 0); + || strcmp (result, "Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 - || strcmp (result, " Rafal Maszkowski 33") == 0); + || strcmp (result, " Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0 - || strcmp (result, "Rafal Maszkowski 33") == 0); + || strcmp (result, "Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0 - || strcmp (result, " Rafal Maszkowski 33") == 0); + || strcmp (result, " Rafal Maszkowski 33") == 0); ASSERT (length == strlen (result)); free (result); } @@ -192,7 +192,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { size_t length; char *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "\304rger 33") == 0); ASSERT (length == strlen (result)); @@ -201,7 +201,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " \304rger 33") == 0); ASSERT (length == strlen (result)); @@ -210,7 +210,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "\304rger 33") == 0); ASSERT (length == strlen (result)); @@ -219,7 +219,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " \304rger 33") == 0); ASSERT (length == strlen (result)); diff --git a/tests/unistdio/test-ulc-vasnprintf3.c b/tests/unistdio/test-ulc-vasnprintf3.c index 1fbd925d7..b1268c9c6 100644 --- a/tests/unistdio/test-ulc-vasnprintf3.c +++ b/tests/unistdio/test-ulc-vasnprintf3.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) static void @@ -50,7 +50,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { size_t length; char *result = - my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -59,7 +59,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -68,7 +68,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -77,7 +77,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -88,13 +88,13 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { static const uint16_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { size_t length; char *result = - my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -103,7 +103,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -112,7 +112,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -121,7 +121,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -132,13 +132,13 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { static const uint32_t unicode_string[] = /* Rafał Maszkowski */ { - 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', - 's', 'k', 'i', 0 + 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w', + 's', 'k', 'i', 0 }; { size_t length; char *result = - my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -147,7 +147,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -156,7 +156,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -165,7 +165,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " Rafa\305\202 Maszkowski 33") == 0); ASSERT (length == strlen (result)); @@ -180,7 +180,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { size_t length; char *result = - my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "\303\204rger 33") == 0); ASSERT (length == strlen (result)); @@ -189,7 +189,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* Width. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " \303\204rger 33") == 0); ASSERT (length == strlen (result)); @@ -198,7 +198,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_LEFT. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, "\303\204rger 33") == 0); ASSERT (length == strlen (result)); @@ -207,7 +207,7 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) { /* FLAG_ZERO: no effect. */ size_t length; char *result = - my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); + my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55); ASSERT (result != NULL); ASSERT (strcmp (result, " \303\204rger 33") == 0); ASSERT (length == strlen (result)); diff --git a/tests/unistdio/test-ulc-vasprintf1.c b/tests/unistdio/test-ulc-vasprintf1.c index d8ed67c2d..cd1875869 100644 --- a/tests/unistdio/test-ulc-vasprintf1.c +++ b/tests/unistdio/test-ulc-vasprintf1.c @@ -29,15 +29,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-ulc-printf1.h" diff --git a/tests/unistdio/test-ulc-vsnprintf1.c b/tests/unistdio/test-ulc-vsnprintf1.c index 7701c21e4..0a2b43fe9 100644 --- a/tests/unistdio/test-ulc-vsnprintf1.c +++ b/tests/unistdio/test-ulc-vsnprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-ulc-printf1.h" diff --git a/tests/unistdio/test-ulc-vsprintf1.c b/tests/unistdio/test-ulc-vsprintf1.c index 76b85b29f..2b1586b91 100644 --- a/tests/unistdio/test-ulc-vsprintf1.c +++ b/tests/unistdio/test-ulc-vsprintf1.c @@ -32,15 +32,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) #include "test-ulc-printf1.h" diff --git a/tests/uniwbrk/test-u16-wordbreaks.c b/tests/uniwbrk/test-u16-wordbreaks.c index b5eb26cd4..e3a66c7e6 100644 --- a/tests/uniwbrk/test-u16-wordbreaks.c +++ b/tests/uniwbrk/test-u16-wordbreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -46,11 +46,11 @@ main () static const uint16_t input[61] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; char *p = (char *) malloc (SIZEOF (input)); size_t i; @@ -59,14 +59,14 @@ main () for (i = 0; i < 61; i++) { - ASSERT (p[i] == ((i >= 4 && i <= 5) - || (i >= 9 && i <= 11) - || (i >= 23 && i <= 31) - || (i >= 35 && i <= 39) - || (i >= 42 && i <= 46) - || (i >= 48 && i <= 58) - || i == 60 - ? 1 : 0)); + ASSERT (p[i] == ((i >= 4 && i <= 5) + || (i >= 9 && i <= 11) + || (i >= 23 && i <= 31) + || (i >= 35 && i <= 39) + || (i >= 42 && i <= 46) + || (i >= 48 && i <= 58) + || i == 60 + ? 1 : 0)); } free (p); } @@ -76,12 +76,12 @@ main () static const uint16_t input[67] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; char *p = (char *) malloc (SIZEOF (input)); size_t i; @@ -90,14 +90,14 @@ main () for (i = 0; i < 67; i++) { - ASSERT (p[i] == ((i >= 5 && i <= 6) - || (i >= 10 && i <= 12) - || (i >= 25 && i <= 33) - || (i >= 37 && i <= 41) - || (i >= 44 && i <= 48) - || (i >= 50 && i <= 60) - || i == 66 - ? 1 : 0)); + ASSERT (p[i] == ((i >= 5 && i <= 6) + || (i >= 10 && i <= 12) + || (i >= 25 && i <= 33) + || (i >= 37 && i <= 41) + || (i >= 44 && i <= 48) + || (i >= 50 && i <= 60) + || i == 66 + ? 1 : 0)); } free (p); } diff --git a/tests/uniwbrk/test-u32-wordbreaks.c b/tests/uniwbrk/test-u32-wordbreaks.c index c6feb84f7..1dbdea50e 100644 --- a/tests/uniwbrk/test-u32-wordbreaks.c +++ b/tests/uniwbrk/test-u32-wordbreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -46,11 +46,11 @@ main () static const uint32_t input[61] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x00FC, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0439, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0439, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', 0xD55C, 0xAE00, '\n' }; char *p = (char *) malloc (SIZEOF (input)); size_t i; @@ -59,14 +59,14 @@ main () for (i = 0; i < 61; i++) { - ASSERT (p[i] == ((i >= 4 && i <= 5) - || (i >= 9 && i <= 11) - || (i >= 23 && i <= 31) - || (i >= 35 && i <= 39) - || (i >= 42 && i <= 46) - || (i >= 48 && i <= 58) - || i == 60 - ? 1 : 0)); + ASSERT (p[i] == ((i >= 4 && i <= 5) + || (i >= 9 && i <= 11) + || (i >= 23 && i <= 31) + || (i >= 35 && i <= 39) + || (i >= 42 && i <= 46) + || (i >= 48 && i <= 58) + || i == 60 + ? 1 : 0)); } free (p); } @@ -76,12 +76,12 @@ main () static const uint32_t input[67] = /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" */ { 'G', 'r', 0x0075, 0x0308, 0x00DF, ' ', 'G', 'o', 't', 't', '.', ' ', - 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, - 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', - 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, - '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', - 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', - 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' + 0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441, 0x0442, 0x0432, 0x0443, + 0x0438, 0x0306, 0x0442, 0x0435, '!', ' ', + 'x', '=', '(', '-', 'b', 0x00B1, 's', 'q', 'r', 't', '(', 'b', 0x00B2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + 0x65E5, 0x672C, 0x8A9E, ',', 0x4E2D, 0x6587, ',', + 0x1112, 0x1161, 0x11AB, 0x1100, 0x1173, 0x11AF, '\n' }; char *p = (char *) malloc (SIZEOF (input)); size_t i; @@ -90,14 +90,14 @@ main () for (i = 0; i < 67; i++) { - ASSERT (p[i] == ((i >= 5 && i <= 6) - || (i >= 10 && i <= 12) - || (i >= 25 && i <= 33) - || (i >= 37 && i <= 41) - || (i >= 44 && i <= 48) - || (i >= 50 && i <= 60) - || i == 66 - ? 1 : 0)); + ASSERT (p[i] == ((i >= 5 && i <= 6) + || (i >= 10 && i <= 12) + || (i >= 25 && i <= 33) + || (i >= 37 && i <= 41) + || (i >= 44 && i <= 48) + || (i >= 50 && i <= 60) + || i == 66 + ? 1 : 0)); } free (p); } diff --git a/tests/uniwbrk/test-u8-wordbreaks.c b/tests/uniwbrk/test-u8-wordbreaks.c index c2633025b..e7d15d1fa 100644 --- a/tests/uniwbrk/test-u8-wordbreaks.c +++ b/tests/uniwbrk/test-u8-wordbreaks.c @@ -25,15 +25,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -53,16 +53,16 @@ main () for (i = 0; i < 91; i++) { - ASSERT (p[i] == ((i >= 6 && i <= 7) - || (i >= 11 && i <= 13) - || (i >= 37 && i <= 44) - || i == 46 || (i >= 50 && i <= 52) - || (i >= 54 && i <= 55) - || (i >= 58 && i <= 62) || (i >= 64 && i <= 67) - || i == 70 || i == 73 || i == 76 - || i == 77 || i == 80 || i == 83 - || i == 84 || i == 90 - ? 1 : 0)); + ASSERT (p[i] == ((i >= 6 && i <= 7) + || (i >= 11 && i <= 13) + || (i >= 37 && i <= 44) + || i == 46 || (i >= 50 && i <= 52) + || (i >= 54 && i <= 55) + || (i >= 58 && i <= 62) || (i >= 64 && i <= 67) + || i == 70 || i == 73 || i == 76 + || i == 77 || i == 80 || i == 83 + || i == 84 || i == 90 + ? 1 : 0)); } free (p); } @@ -79,16 +79,16 @@ main () for (i = 0; i < 106; i++) { - ASSERT (p[i] == ((i >= 7 && i <= 8) - || (i >= 12 && i <= 14) - || (i >= 40 && i <= 47) - || i == 49 || (i >= 53 && i <= 55) - || (i >= 57 && i <= 58) - || (i >= 61 && i <= 65) || (i >= 67 && i <= 70) - || i == 73 || i == 76 || i == 79 - || i == 80 || i == 83 || i == 86 - || i == 87 || i == 105 - ? 1 : 0)); + ASSERT (p[i] == ((i >= 7 && i <= 8) + || (i >= 12 && i <= 14) + || (i >= 40 && i <= 47) + || i == 49 || (i >= 53 && i <= 55) + || (i >= 57 && i <= 58) + || (i >= 61 && i <= 65) || (i >= 67 && i <= 70) + || i == 73 || i == 76 || i == 79 + || i == 80 || i == 83 || i == 86 + || i == 87 || i == 105 + ? 1 : 0)); } free (p); } diff --git a/tests/uniwbrk/test-ulc-wordbreaks.c b/tests/uniwbrk/test-ulc-wordbreaks.c index 80284ab2d..172743239 100644 --- a/tests/uniwbrk/test-ulc-wordbreaks.c +++ b/tests/uniwbrk/test-ulc-wordbreaks.c @@ -26,15 +26,15 @@ #define SIZEOF(array) (sizeof (array) / sizeof (array[0])) #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -59,12 +59,12 @@ main () for (i = 0; i < 36; i++) { - ASSERT (p[i] == ((i >= 4 && i <= 5) - || (i >= 9 && i <= 17) - || (i >= 21 && i <= 25) - || (i >= 28 && i <= 32) - || (i >= 34 && i <= 35) - ? 1 : 0)); + ASSERT (p[i] == ((i >= 4 && i <= 5) + || (i >= 9 && i <= 17) + || (i >= 21 && i <= 25) + || (i >= 28 && i <= 32) + || (i >= 34 && i <= 35) + ? 1 : 0)); } free (p); } diff --git a/tests/uniwidth/test-u16-strwidth.c b/tests/uniwidth/test-u16-strwidth.c index 7365426f6..9794c3ff9 100644 --- a/tests/uniwidth/test-u16-strwidth.c +++ b/tests/uniwidth/test-u16-strwidth.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -53,8 +53,8 @@ main () { static const uint16_t input[] = /* "Данило Шеган" */ { - 0x0414, 0x0430, 0x043D, 0x0438, 0x043B, 0x043E, ' ', - 0x0428, 0x0435, 0x0433, 0x0430, 0x043D, 0 + 0x0414, 0x0430, 0x043D, 0x0438, 0x043B, 0x043E, ' ', + 0x0428, 0x0435, 0x0433, 0x0430, 0x043D, 0 }; ASSERT (u16_strwidth (input, "UTF-8") == 12); ASSERT (u16_strwidth (input, "EUC-JP") == 23); diff --git a/tests/uniwidth/test-u16-width.c b/tests/uniwidth/test-u16-width.c index b3e2b5929..440a4fbdb 100644 --- a/tests/uniwidth/test-u16-width.c +++ b/tests/uniwidth/test-u16-width.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uniwidth/test-u32-strwidth.c b/tests/uniwidth/test-u32-strwidth.c index 3976daa90..77ca68e8f 100644 --- a/tests/uniwidth/test-u32-strwidth.c +++ b/tests/uniwidth/test-u32-strwidth.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -53,8 +53,8 @@ main () { static const uint32_t input[] = /* "Данило Шеган" */ { - 0x0414, 0x0430, 0x043D, 0x0438, 0x043B, 0x043E, ' ', - 0x0428, 0x0435, 0x0433, 0x0430, 0x043D, 0 + 0x0414, 0x0430, 0x043D, 0x0438, 0x043B, 0x043E, ' ', + 0x0428, 0x0435, 0x0433, 0x0430, 0x043D, 0 }; ASSERT (u32_strwidth (input, "UTF-8") == 12); ASSERT (u32_strwidth (input, "EUC-JP") == 23); diff --git a/tests/uniwidth/test-u32-width.c b/tests/uniwidth/test-u32-width.c index 05fd856d9..a55c6a8f5 100644 --- a/tests/uniwidth/test-u32-width.c +++ b/tests/uniwidth/test-u32-width.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uniwidth/test-u8-strwidth.c b/tests/uniwidth/test-u8-strwidth.c index 3fbb39e5d..b6254418c 100644 --- a/tests/uniwidth/test-u8-strwidth.c +++ b/tests/uniwidth/test-u8-strwidth.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uniwidth/test-u8-width.c b/tests/uniwidth/test-u8-width.c index b25328977..b421e4568 100644 --- a/tests/uniwidth/test-u8-width.c +++ b/tests/uniwidth/test-u8-width.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uniwidth/test-uc_width.c b/tests/uniwidth/test-uc_width.c index d7335cfd4..8303c08ef 100644 --- a/tests/uniwidth/test-uc_width.c +++ b/tests/uniwidth/test-uc_width.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int diff --git a/tests/uniwidth/test-uc_width2.c b/tests/uniwidth/test-uc_width2.c index 2bf143c22..78f71e0eb 100644 --- a/tests/uniwidth/test-uc_width2.c +++ b/tests/uniwidth/test-uc_width2.c @@ -24,15 +24,15 @@ #include #define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ + do \ + { \ + if (!(expr)) \ + { \ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) /* One of 0, '0', '1', 'A', '2'. */ @@ -47,10 +47,10 @@ finish_interval (void) if (current_width != 0) { if (current_start == current_end) - printf ("%04X\t\t%c\n", (unsigned) current_start, current_width); + printf ("%04X\t\t%c\n", (unsigned) current_start, current_width); else - printf ("%04X..%04X\t%c\n", (unsigned) current_start, - (unsigned) current_end, current_width); + printf ("%04X..%04X\t%c\n", (unsigned) current_start, + (unsigned) current_end, current_width); current_width = 0; } } @@ -78,18 +78,18 @@ main () int w1 = uc_width (uc, "UTF-8"); int w2 = uc_width (uc, "GBK"); char width = - (w1 == 0 && w2 == 0 ? '0' : - w1 == 1 && w2 == 1 ? '1' : - w1 == 1 && w2 == 2 ? 'A' : - w1 == 2 && w2 == 2 ? '2' : - 0); + (w1 == 0 && w2 == 0 ? '0' : + w1 == 1 && w2 == 1 ? '1' : + w1 == 1 && w2 == 2 ? 'A' : + w1 == 2 && w2 == 2 ? '2' : + 0); if (width == 0) - { - /* uc must be a control character. */ - ASSERT (w1 < 0 && w2 < 0); - } + { + /* uc must be a control character. */ + ASSERT (w1 < 0 && w2 < 0); + } else - add_to_interval (uc, width); + add_to_interval (uc, width); } finish_interval (); diff --git a/tests/zerosize-ptr.h b/tests/zerosize-ptr.h index a38a2cf49..399d01933 100644 --- a/tests/zerosize-ptr.h +++ b/tests/zerosize-ptr.h @@ -57,11 +57,11 @@ zerosize_ptr (void) { int pagesize = getpagesize (); char *two_pages = - (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, - flags, fd, 0); + (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, + flags, fd, 0); if (two_pages != (char *)(-1) - && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) - return two_pages + pagesize; + && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) + return two_pages + pagesize; } #endif return NULL; -- 2.11.0